X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.5.0/lucene/src/test/org/apache/lucene/index/TestByteSlices.java diff --git a/lucene-java-3.5.0/lucene/src/test/org/apache/lucene/index/TestByteSlices.java b/lucene-java-3.5.0/lucene/src/test/org/apache/lucene/index/TestByteSlices.java new file mode 100644 index 0000000..07c6e78 --- /dev/null +++ b/lucene-java-3.5.0/lucene/src/test/org/apache/lucene/index/TestByteSlices.java @@ -0,0 +1,118 @@ +package org.apache.lucene.index; + +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.ArrayList; +import java.util.List; + +import org.apache.lucene.util.LuceneTestCase; + +public class TestByteSlices extends LuceneTestCase { + + private static class ByteBlockAllocator extends ByteBlockPool.Allocator { + ArrayList freeByteBlocks = new ArrayList(); + + /* Allocate another byte[] from the shared pool */ + @Override + synchronized byte[] getByteBlock() { + final int size = freeByteBlocks.size(); + final byte[] b; + if (0 == size) + b = new byte[DocumentsWriter.BYTE_BLOCK_SIZE]; + else + b = freeByteBlocks.remove(size-1); + return b; + } + + /* Return a byte[] to the pool */ + @Override + synchronized void recycleByteBlocks(byte[][] blocks, int start, int end) { + for(int i=start;i blocks) { + final int size = blocks.size(); + for(int i=0;i