Search in sources :

Example 1 with InternalIndexState

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);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)1 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1