use of org.apache.lucene.store.RAMDirectory in project jackrabbit by apache.
the class IndexMigrationTest method testMigration.
public void testMigration() throws Exception {
List<Document> docs = new ArrayList<Document>();
docs.add(createDocument("ab", "a"));
docs.add(createDocument("a", "b"));
docs.add(createDocument("abcd", "c"));
docs.add(createDocument("abc", "d"));
DirectoryManager dirMgr = new RAMDirectoryManager();
PersistentIndex idx = new PersistentIndex("index", new StandardAnalyzer(Version.LUCENE_36), Similarity.getDefault(), new DocNumberCache(100), new IndexingQueue(new IndexingQueueStore(new RAMDirectory())), dirMgr, 0);
idx.addDocuments(docs.toArray(new Document[docs.size()]));
idx.commit();
IndexMigration.migrate(idx, dirMgr, SEP_CHAR);
}
use of org.apache.lucene.store.RAMDirectory in project jackrabbit-oak by apache.
the class IndexPlannerTest method createSampleDirectory.
private static Directory createSampleDirectory(long numOfDocs) throws IOException {
Directory dir = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(VERSION, LuceneIndexConstants.ANALYZER);
IndexWriter writer = new IndexWriter(dir, config);
for (int i = 0; i < numOfDocs; i++) {
Document doc = new Document();
doc.add(new StringField("foo", "bar" + i, Field.Store.NO));
writer.addDocument(doc);
}
writer.close();
return dir;
}
use of org.apache.lucene.store.RAMDirectory in project jackrabbit-oak by apache.
the class IndexCopierTest method copyOnWriteBasics.
@Test
public void copyOnWriteBasics() throws Exception {
Directory baseDir = new CloseSafeDir();
IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
IndexCopier copier = new RAMIndexCopier(baseDir, sameThreadExecutor(), getWorkDir());
Directory remote = new RAMDirectory();
byte[] t1 = writeFile(remote, "t1");
//State of remote directory should set before wrapping as later
//additions would not be picked up given COW assume remote directory
//to be read only
Directory local = copier.wrapForWrite(defn, remote, false, INDEX_DATA_CHILD_NAME);
assertEquals(newHashSet("t1"), newHashSet(local.listAll()));
assertEquals(t1.length, local.fileLength("t1"));
byte[] t2 = writeFile(local, "t2");
assertEquals(newHashSet("t1", "t2"), newHashSet(local.listAll()));
assertEquals(t2.length, local.fileLength("t2"));
assertTrue(local.fileExists("t1"));
assertTrue(local.fileExists("t2"));
assertTrue("t2 should be copied to remote", remote.fileExists("t2"));
readAndAssert(local, "t1", t1);
readAndAssert(local, "t2", t2);
local.deleteFile("t1");
assertEquals(newHashSet("t2"), newHashSet(local.listAll()));
local.deleteFile("t2");
assertEquals(newHashSet(), newHashSet(local.listAll()));
try {
local.fileLength("nonExistentFile");
fail();
} catch (FileNotFoundException ignore) {
}
try {
local.openInput("nonExistentFile", IOContext.DEFAULT);
fail();
} catch (FileNotFoundException ignore) {
}
local.close();
assertFalse(baseDir.fileExists("t2"));
}
use of org.apache.lucene.store.RAMDirectory in project jackrabbit-oak by apache.
the class IndexCopierTest method deletesOnClose.
@Test
public void deletesOnClose() throws Exception {
//Use a close safe dir. In actual case the FSDir would
//be opened on same file system hence it can retain memory
//but RAMDirectory does not retain memory hence we simulate
//that by not closing the RAMDir and reuse it
Directory baseDir = new CloseSafeDir();
IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
IndexCopier c1 = new RAMIndexCopier(baseDir, sameThreadExecutor(), getWorkDir());
Directory r1 = new RAMDirectory();
byte[] t1 = writeFile(r1, "t1");
byte[] t2 = writeFile(r1, "t2");
Directory w1 = c1.wrapForRead("/foo", defn, r1, INDEX_DATA_CHILD_NAME);
readAndAssert(w1, "t1", t1);
readAndAssert(w1, "t2", t2);
// t1 and t2 should now be present in local (base dir which back local)
assertTrue(baseDir.fileExists("t1"));
assertTrue(baseDir.fileExists("t2"));
Directory r2 = new RAMDirectory();
copy(r1, r2);
r2.deleteFile("t1");
Directory w2 = c1.wrapForRead("/foo", defn, r2, INDEX_DATA_CHILD_NAME);
//Close would trigger removal of file which are not present in remote
w2.close();
assertFalse("t1 should have been deleted", baseDir.fileExists("t1"));
assertTrue(baseDir.fileExists("t2"));
}
use of org.apache.lucene.store.RAMDirectory in project jackrabbit-oak by apache.
the class IndexCopierTest method deletedOnlyFilesForOlderVersion.
@Test
public void deletedOnlyFilesForOlderVersion() throws Exception {
Directory baseDir = new CloseSafeDir();
IndexDefinition defn = new IndexDefinition(root, builder.getNodeState(), "/foo");
IndexCopier copier = new RAMIndexCopier(baseDir, sameThreadExecutor(), getWorkDir());
//1. Open a local and read t1 from remote
Directory remote1 = new RAMDirectory();
byte[] t1 = writeFile(remote1, "t1");
Directory local1 = copier.wrapForRead("/foo", defn, remote1, INDEX_DATA_CHILD_NAME);
readAndAssert(local1, "t1", t1);
//While local1 is open , open another local2 and read t2
Directory remote2 = new RAMDirectory();
byte[] t2 = writeFile(remote2, "t2");
Directory local2 = copier.wrapForRead("/foo", defn, remote2, INDEX_DATA_CHILD_NAME);
readAndAssert(local2, "t2", t2);
//Close local1
local1.close();
//t2 should still be readable
readAndAssert(local2, "t2", t2);
}
Aggregations