use of org.neo4j.kernel.api.index.InternalIndexState in project neo4j by neo4j.
the class AwaitIndexProcedureTest method shouldBlockUntilTheIndexIsOnline.
@Test
public void shouldBlockUntilTheIndexIsOnline() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, InterruptedException {
when(operations.labelGetForName(anyString())).thenReturn(0);
when(operations.propertyKeyGetForName(anyString())).thenReturn(0);
when(operations.indexGetForLabelAndPropertyKey(anyObject())).thenReturn(anyIndex);
AtomicReference<InternalIndexState> state = new AtomicReference<>(POPULATING);
when(operations.indexGetState(any(NewIndexDescriptor.class))).then(new Answer<InternalIndexState>() {
@Override
public InternalIndexState answer(InvocationOnMock invocationOnMock) throws Throwable {
return state.get();
}
});
AtomicBoolean done = new AtomicBoolean(false);
new Thread(() -> {
try {
procedure.awaitIndex(":Person(name)", timeout, timeoutUnits);
} catch (ProcedureException e) {
throw new RuntimeException(e);
}
done.set(true);
}).start();
assertThat(done.get(), is(false));
state.set(ONLINE);
assertEventually("Procedure did not return after index was online", done::get, is(true), 10, TimeUnit.SECONDS);
}
Aggregations