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);
}
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));
}
}
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;
}
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));
}
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);
}
Aggregations