private EditorHook hook = new EditorHook(new IndexUpdateProvider(provider));
@Test
public void testAsyncPropertyLookup() throws Exception {
NodeStore store = new MemoryNodeStore();
NodeBuilder builder = store.getRoot().builder();
//add a property index on 'foo'
NodeBuilder def = createIndexDefinition(
builder.child(INDEX_DEFINITIONS_NAME), "foo", true, false,
of("foo"), null);
def.setProperty(REINDEX_ASYNC_PROPERTY_NAME, true);
// add some content
builder.child("a").setProperty("foo", "abc");
builder.child("b").setProperty("foo", Arrays.asList("abc", "def"),
STRINGS);
NodeState head = store.merge(builder, hook, EMPTY);
// query the index, check it doesn't get indexed by the normal PI
FilterImpl f = createFilter(head, NT_BASE);
PropertyIndexLookup lookup = new PropertyIndexLookup(head);
try {
assertEquals(of(), find(lookup, "foo", "abc", f));
fail();
} catch (IllegalArgumentException e) {
// expected: no index for "foo"
}
// run async first time, there are some changes
AsyncIndexUpdate async = new AsyncIndexUpdate(ASYNC_REINDEX_VALUE,
store, provider, true);
async.run();
assertEquals(ASYNC_REINDEX_VALUE,
store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME)
.getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
// run async second time, there are no changes, should switch to sync
async.run();
assertEquals(null, store.getRoot().getChildNode(INDEX_DEFINITIONS_NAME)
.getChildNode("foo").getString(ASYNC_PROPERTY_NAME));
// add content, it should be indexed synchronously
builder = store.getRoot().builder();
builder.child("c").setProperty("foo", "def");
head = store.merge(builder, hook, EMPTY);
f = createFilter(head, NT_BASE);
lookup = new PropertyIndexLookup(head);
assertEquals(ImmutableSet.of("b", "c"), find(lookup, "foo", "def", f));
}