Search in sources :

Example 11 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.

the class FSDirectoryFactoryTest method reuseExistingDir.

@Test
public void reuseExistingDir() throws Exception {
    IndexDefinition defn = IndexDefinition.newBuilder(root, idx.getNodeState(), "/fooIndex").build();
    FSDirectoryFactory factory = new FSDirectoryFactory(temporaryFolder.getRoot());
    Directory dir = factory.newInstance(defn, idx, ":data", false);
    File fsDir1 = ((FSDirectory) dir).getDirectory();
    dir.close();
    Directory dir2 = factory.newInstance(defn, idx, ":data", false);
    File fsDir2 = ((FSDirectory) dir2).getDirectory();
    dir2.close();
    assertEquals(fsDir1, fsDir2);
    assertEquals(1, temporaryFolder.getRoot().list(DirectoryFileFilter.DIRECTORY).length);
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) FSDirectory(org.apache.lucene.store.FSDirectory) File(java.io.File) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) Test(org.junit.Test)

Example 12 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.

the class FSDirectoryFactoryTest method multiIndexWithSimilarPaths.

@Test
public void multiIndexWithSimilarPaths() throws Exception {
    IndexDefinition defn1 = IndexDefinition.newBuilder(root, idx.getNodeState(), "/content/a/en_us/oak:index/fooIndex").build();
    IndexDefinition defn2 = IndexDefinition.newBuilder(root, idx.getNodeState(), "/content/b/en_us/oak:index/fooIndex").build();
    FSDirectoryFactory factory = new FSDirectoryFactory(temporaryFolder.getRoot());
    factory.newInstance(defn1, idx, ":data", false).close();
    factory.newInstance(defn2, idx, ":data", false).close();
    IndexRootDirectory idxDir = new IndexRootDirectory(temporaryFolder.getRoot());
    List<LocalIndexDir> indexes = idxDir.getAllLocalIndexes();
    assertEquals(2, indexes.size());
    List<String> idxPaths = indexes.stream().map(LocalIndexDir::getJcrPath).collect(Collectors.toList());
    assertThat(idxPaths, hasItems("/content/a/en_us/oak:index/fooIndex", "/content/b/en_us/oak:index/fooIndex"));
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) Test(org.junit.Test)

Example 13 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.

the class IndexConsistencyCheckerTest method validIndexTest.

@Test
public void validIndexTest() throws Exception {
    IndexDefinition defn = IndexDefinition.newBuilder(rootState, idx.getNodeState(), "/fooIndex").build();
    Directory dir = new OakDirectory(idx, ":data", defn, false);
    createIndex(dir, 10);
    dir = new OakDirectory(idx, ":data2" + MultiplexersLucene.INDEX_DIR_SUFFIX, defn, false);
    createIndex(dir, 10);
    NodeBuilder builder = rootState.builder();
    builder.setChildNode("fooIndex", idx.getNodeState());
    NodeState indexState = builder.getNodeState();
    IndexConsistencyChecker checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
    Result result = checker.check(Level.BLOBS_ONLY);
    assertTrue(result.clean);
    checker = new IndexConsistencyChecker(indexState, "/fooIndex", temporaryFolder.getRoot());
    result = checker.check(Level.FULL);
    assertTrue(result.clean);
    assertEquals(2, result.dirStatus.size());
    dumpResult(result);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) OakDirectory(org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory) Directory(org.apache.lucene.store.Directory) Result(org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Result) Test(org.junit.Test)

Example 14 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.

the class CopyOnWriteDirectoryTest method copyOnWrite.

// OAK-5238
@Test
public void copyOnWrite() throws Exception {
    IndexDefinition def = new IndexDefinition(ns.getRoot(), ns.getRoot(), "/foo");
    NodeBuilder builder = ns.getRoot().builder();
    Directory dir = new DefaultDirectoryFactory(copier, null).newInstance(def, builder.child("foo"), INDEX_DATA_CHILD_NAME, false);
    addFiles(dir);
    writeTree(builder);
    dir.close();
    ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 15 with IndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition in project jackrabbit-oak by apache.

the class FSDirectoryFactoryTest method singleIndex.

@Test
public void singleIndex() throws Exception {
    IndexDefinition defn = IndexDefinition.newBuilder(root, idx.getNodeState(), "/fooIndex").build();
    FSDirectoryFactory factory = new FSDirectoryFactory(temporaryFolder.getRoot());
    Directory dir = factory.newInstance(defn, idx, ":data", false);
    dir.close();
    IndexRootDirectory idxDir = new IndexRootDirectory(temporaryFolder.getRoot());
    List<LocalIndexDir> indexes = idxDir.getAllLocalIndexes();
    assertEquals(1, indexes.size());
    assertEquals("/fooIndex", indexes.get(0).getJcrPath());
    assertTrue(new File(indexes.get(0).dir, "data").exists());
}
Also used : IndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition) File(java.io.File) Directory(org.apache.lucene.store.Directory) FSDirectory(org.apache.lucene.store.FSDirectory) Test(org.junit.Test)

Aggregations

IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)28 Test (org.junit.Test)24 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)7 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)7 Document (org.apache.lucene.document.Document)7 Directory (org.apache.lucene.store.Directory)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)5 File (java.io.File)4 OakDirectory (org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectory)4 Result (org.apache.jackrabbit.oak.plugins.index.lucene.directory.IndexConsistencyChecker.Result)3 LuceneIndexReader (org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader)3 DefaultDirectoryFactory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory)2 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)2 LuceneIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory)2 StringField (org.apache.lucene.document.StringField)2 FSDirectory (org.apache.lucene.store.FSDirectory)2 Closer (com.google.common.io.Closer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Blob (org.apache.jackrabbit.oak.api.Blob)1