Search in sources :

Example 1 with IndexUpdateCallback

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

the class LuceneIndexEditorProviderTest method readOnlyBuilderUsedForSync.

@Test
public void readOnlyBuilderUsedForSync() throws Exception {
    LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null, null, null, null, Mounts.defaultMountInfoProvider());
    editorProvider.setIndexingQueue(mock(DocumentQueue.class));
    IndexUpdateCallback callback = new TestCallback("/oak:index/fooIndex", newCommitInfo(), false, false);
    NodeBuilder defnBuilder = createIndexDefinition("fooIndex").builder();
    Editor editor = editorProvider.getIndexEditor(TYPE_LUCENE, defnBuilder, root, callback);
    LuceneIndexEditor luceneEditor = (LuceneIndexEditor) editor;
    NodeBuilder builderFromContext = (NodeBuilder) FieldUtils.readField(luceneEditor.getContext(), "definitionBuilder", true);
    try {
        builderFromContext.setProperty("foo", "bar");
        fail("Should have been read only builder");
    } catch (UnsupportedOperationException ignore) {
    }
}
Also used : IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) DocumentQueue(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

Example 2 with IndexUpdateCallback

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

the class LuceneIndexEditorProviderTest method reuseOldIndexDefinition.

@Test
public void reuseOldIndexDefinition() throws Exception {
    IndexTracker tracker = mock(IndexTracker.class);
    LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null, tracker, null, null, Mounts.defaultMountInfoProvider());
    editorProvider.setIndexingQueue(mock(DocumentQueue.class));
    //Set up a different IndexDefinition which needs to be returned
    //from tracker with a marker property
    NodeBuilder testBuilder = createIndexDefinition("fooIndex").builder();
    testBuilder.setProperty("foo", "bar");
    IndexDefinition defn = new IndexDefinition(root, testBuilder.getNodeState(), "/foo");
    when(tracker.getIndexDefinition("/oak:index/fooIndex")).thenReturn(defn);
    IndexUpdateCallback callback = new TestCallback("/oak:index/fooIndex", newCommitInfo(), false, false);
    NodeBuilder defnBuilder = createIndexDefinition("fooIndex").builder();
    Editor editor = editorProvider.getIndexEditor(TYPE_LUCENE, defnBuilder, root, callback);
    LuceneIndexEditor luceneEditor = (LuceneIndexEditor) editor;
    LuceneIndexEditorContext context = luceneEditor.getContext();
    //Definition should reflect the marker property
    assertEquals("bar", context.getDefinition().getDefinitionNodeState().getString("foo"));
}
Also used : LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) DocumentQueue(org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

Example 3 with IndexUpdateCallback

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

the class LuceneIndexEditorProviderTest method editorNullInCaseOfReindex.

@Test
public void editorNullInCaseOfReindex() throws Exception {
    LuceneIndexEditorProvider editorProvider = new LuceneIndexEditorProvider(null, null, null, null, Mounts.defaultMountInfoProvider());
    IndexUpdateCallback callback = new TestCallback("/oak:index/fooIndex", newCommitInfo(), true, false);
    NodeBuilder defnBuilder = createIndexDefinition("fooIndex").builder();
    Editor editor = editorProvider.getIndexEditor(TYPE_LUCENE, defnBuilder, root, callback);
    assertNull(editor);
}
Also used : IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Editor(org.apache.jackrabbit.oak.spi.commit.Editor) Test(org.junit.Test)

Example 4 with IndexUpdateCallback

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

the class SolrIndexEditorTest method testIndexedProperties.

@Test
public void testIndexedProperties() throws Exception {
    SolrServer solrServer = TestUtils.createSolrServer();
    OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
    IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
    SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
    NodeState before = mock(NodeState.class);
    NodeState after = mock(NodeState.class);
    Iterable properties = new Iterable<PropertyState>() {

        @Override
        public Iterator<PropertyState> iterator() {
            return Arrays.asList(PropertyStates.createProperty("foo1", "bar")).iterator();
        }
    };
    when(after.getProperties()).thenReturn(properties);
    solrIndexEditor.leave(before, after);
    QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
    assertEquals(1, queryResponse.getResults().getNumFound());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Example 5 with IndexUpdateCallback

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

the class SolrIndexEditorTest method testIgnoredPropertiesNotIndexed.

@Test
public void testIgnoredPropertiesNotIndexed() throws Exception {
    NodeBuilder builder = mock(NodeBuilder.class);
    SolrServer solrServer = TestUtils.createSolrServer();
    OakSolrConfiguration configuration = new DefaultSolrConfiguration() {

        @Nonnull
        @Override
        public Collection<String> getIgnoredProperties() {
            return Arrays.asList("foo2");
        }

        @Nonnull
        @Override
        public CommitPolicy getCommitPolicy() {
            return CommitPolicy.HARD;
        }
    };
    IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
    SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
    NodeState before = mock(NodeState.class);
    NodeState after = mock(NodeState.class);
    Iterable properties = new Iterable<PropertyState>() {

        @Override
        public Iterator<PropertyState> iterator() {
            return Arrays.asList(PropertyStates.createProperty("foo2", "bar")).iterator();
        }
    };
    when(after.getProperties()).thenReturn(properties);
    solrIndexEditor.leave(before, after);
    QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
    assertEquals(0, queryResponse.getResults().getNumFound());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexUpdateCallback(org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback) DefaultSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Test(org.junit.Test)

Aggregations

IndexUpdateCallback (org.apache.jackrabbit.oak.plugins.index.IndexUpdateCallback)5 Test (org.junit.Test)5 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)4 Editor (org.apache.jackrabbit.oak.spi.commit.Editor)3 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 DocumentQueue (org.apache.jackrabbit.oak.plugins.index.lucene.hybrid.DocumentQueue)2 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)2 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServer (org.apache.solr.client.solrj.SolrServer)2 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)2 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)1