Search in sources :

Example 71 with IndexInput

use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.

the class OakDirectoryTest method testCloseOnClonedIndexInputs.

@Test
public void testCloseOnClonedIndexInputs() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int dataSize = 1024;
    List<? super Blob> blobs = new ArrayList<Blob>(dataSize);
    for (int i = 0; i < dataSize; i++) {
        blobs.add(new ArrayBasedBlob(new byte[0]));
    }
    file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES));
    IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT);
    IndexInput clone1 = input.clone();
    IndexInput clone2 = input.clone();
    input.close();
    assertClosed(input);
    assertClosed(clone1);
    assertClosed(clone2);
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 72 with IndexInput

use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.

the class OakDirectoryTest method dirNameInExceptionMessage.

@Test
public void dirNameInExceptionMessage() throws Exception {
    String indexPath = "/foo/bar";
    Directory dir = createDir(builder, false, indexPath);
    try {
        dir.openInput("foo.txt", IOContext.DEFAULT);
        fail();
    } catch (IOException e) {
        assertThat(e.getMessage(), containsString(indexPath));
    }
    int fileSize = createFile(dir, "test.txt");
    IndexInput in = dir.openInput("test.txt", IOContext.DEFAULT);
    try {
        in.seek(fileSize + 1);
        fail();
    } catch (IOException e) {
        assertThat(e.getMessage(), containsString(indexPath));
    }
    IndexInput in2 = dir.openInput("test.txt", IOContext.DEFAULT);
    try {
        byte[] data = new byte[fileSize + 1];
        in2.readBytes(data, 0, fileSize + 1);
        fail();
    } catch (IOException e) {
        assertThat(e.getMessage(), containsString(indexPath));
    }
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 73 with IndexInput

use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.

the class OakDirectoryTest method assertWrites.

byte[] assertWrites(Directory dir, int blobSize) throws IOException {
    byte[] data = randomBytes(fileSize);
    IndexOutput o = dir.createOutput("test", IOContext.DEFAULT);
    o.writeBytes(data, data.length);
    o.close();
    assertTrue(dir.fileExists("test"));
    assertEquals(fileSize, dir.fileLength("test"));
    IndexInput i = dir.openInput("test", IOContext.DEFAULT);
    assertEquals(fileSize, i.length());
    byte[] result = new byte[fileSize];
    i.readBytes(result, 0, result.length);
    assertTrue(Arrays.equals(data, result));
    NodeBuilder testNode = builder.child(INDEX_DATA_CHILD_NAME).child("test");
    assertEquals(blobSize, testNode.getProperty(PROP_BLOB_SIZE).getValue(Type.LONG).longValue());
    List<Blob> blobs = newArrayList(testNode.getProperty(JCR_DATA).getValue(BINARIES));
    assertEquals(blobSize + UNIQUE_KEY_SIZE, blobs.get(0).length());
    return data;
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Blob(org.apache.jackrabbit.oak.api.Blob) IndexInput(org.apache.lucene.store.IndexInput) IndexOutput(org.apache.lucene.store.IndexOutput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder)

Example 74 with IndexInput

use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.

the class OakDirectoryTest method testCompatibility.

@Test
public void testCompatibility() throws Exception {
    builder.setProperty(LuceneIndexConstants.BLOB_SIZE, OakDirectory.DEFAULT_BLOB_SIZE);
    Directory dir = createDir(builder, false, "/foo");
    byte[] data = assertWrites(dir, OakDirectory.DEFAULT_BLOB_SIZE);
    NodeBuilder testNode = builder.child(INDEX_DATA_CHILD_NAME).child("test");
    //Remove the size property to simulate old behaviour
    testNode.removeProperty(PROP_BLOB_SIZE);
    //Read should still work even if the size property is removed
    IndexInput i = dir.openInput("test", IOContext.DEFAULT);
    assertEquals(fileSize, i.length());
    byte[] result = new byte[fileSize];
    i.readBytes(result, 0, result.length);
    assertTrue(Arrays.equals(data, result));
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 75 with IndexInput

use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.

the class OakDirectoryTest method testCloseOnOriginalIndexInput.

@Test
public void testCloseOnOriginalIndexInput() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int dataSize = 1024;
    List<? super Blob> blobs = new ArrayList<Blob>(dataSize);
    for (int i = 0; i < dataSize; i++) {
        blobs.add(new ArrayBasedBlob(new byte[0]));
    }
    file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES));
    IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT);
    input.close();
    assertClosed(input);
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Aggregations

IndexInput (org.apache.lucene.store.IndexInput)150 IndexOutput (org.apache.lucene.store.IndexOutput)69 Directory (org.apache.lucene.store.Directory)62 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)41 IOException (java.io.IOException)21 RAMDirectory (org.apache.lucene.store.RAMDirectory)21 FilterDirectory (org.apache.lucene.store.FilterDirectory)19 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)17 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)14 ArrayList (java.util.ArrayList)13 BytesRef (org.apache.lucene.util.BytesRef)13 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)13 CorruptingIndexOutput (org.apache.lucene.store.CorruptingIndexOutput)10 IOContext (org.apache.lucene.store.IOContext)10 NRTCachingDirectory (org.apache.lucene.store.NRTCachingDirectory)10 IntersectVisitor (org.apache.lucene.index.PointValues.IntersectVisitor)9 Relation (org.apache.lucene.index.PointValues.Relation)9 Test (org.junit.Test)8 FileNotFoundException (java.io.FileNotFoundException)7 BaseDirectoryWrapper (org.apache.lucene.store.BaseDirectoryWrapper)7