1 package org.apache.lucene.util;
3 import java.io.IOException;
4 import java.util.ArrayList;
7 import org.apache.lucene.store.IndexInput;
8 import org.apache.lucene.store.IndexOutput;
9 import org.apache.lucene.store.RAMDirectory;
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed with this
14 * work for additional information regarding copyright ownership. The ASF
15 * licenses this file to You under the Apache License, Version 2.0 (the
16 * "License"); you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
19 * http://www.apache.org/licenses/LICENSE-2.0
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
24 * License for the specific language governing permissions and limitations under
27 public class TestByteBlockPool extends LuceneTestCase {
29 public void testCopyRefAndWrite() throws IOException {
30 List<String> list = new ArrayList<String>();
31 int maxLength = atLeast(500);
32 ByteBlockPool pool = new ByteBlockPool(new ByteBlockPool.DirectAllocator());
34 final int numValues = atLeast(100);
35 BytesRef ref = new BytesRef();
36 for (int i = 0; i < numValues; i++) {
37 final String value = _TestUtil.randomRealisticUnicodeString(random,
43 RAMDirectory dir = new RAMDirectory();
44 IndexOutput stream = dir.createOutput("foo.txt");
45 pool.writePool(stream);
48 IndexInput input = dir.openInput("foo.txt");
49 assertEquals(pool.byteOffset + pool.byteUpto, stream.length());
50 BytesRef expected = new BytesRef();
51 BytesRef actual = new BytesRef();
52 for (String string : list) {
53 expected.copy(string);
54 actual.grow(expected.length);
55 actual.length = expected.length;
56 input.readBytes(actual.bytes, 0, actual.length);
57 assertEquals(expected, actual);
62 } catch (IOException e) {
63 // expected - read past EOF