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