assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.POPULATING ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) );
@Test public void shouldKeepFailedIndexesAsFailedAfterRestart() throws Exception { // Given IndexPopulator indexPopulator = mock( IndexPopulator.class ); when( mockedIndexProvider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( indexPopulator ); IndexAccessor indexAccessor = mock( IndexAccessor.class ); when( mockedIndexProvider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( indexAccessor ); startDb(); createIndex( myLabel ); rotateLogsAndCheckPoint(); // And Given killDb(); when( mockedIndexProvider.getInitialState( any( StoreIndexDescriptor.class ) ) ) .thenReturn( InternalIndexState.FAILED ); // When startDb(); // Then assertThat( getIndexes( db, myLabel ), inTx( db, hasSize( 1 ) ) ); assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.FAILED ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); }
assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.POPULATING ) ) ); verify( mockedIndexProvider, times( 2 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) );
assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.ONLINE ) ) ); verify( mockedIndexProvider, times( 1 ) ) .getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) );
@Test public void shouldHandleRestartIndexThatHasNotComeOnlineYet() { // Given startDb(); createIndex(); // And Given stopDb(); provider.setInitialIndexState( POPULATING ); // When startDb(); assertThat( getIndexes( db, myLabel ), inTx( db, not( haveState( db, Schema.IndexState.FAILED ) ) ) ); assertEquals( 2, provider.populatorCallCount.get() ); }
@Test public void shouldHandleRestartOfOnlineIndex() { // Given startDb(); createIndex(); provider.awaitFullyPopulated(); // And Given stopDb(); provider.setInitialIndexState( ONLINE ); // When startDb(); // Then assertThat( getIndexes( db, myLabel ), inTx( db, haveState( db, Schema.IndexState.ONLINE ) ) ); assertEquals( 1, provider.populatorCallCount.get() ); assertEquals( 2, provider.writerCallCount.get() ); }
@Test public void shouldIndexArraysPostPopulation() { long[] arrayPropertyValue = {42, 23, 87}; Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } createIndex( db, label, propertyKey ); restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new long[]{42, 23}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }
@Test public void shouldIndexArrays() { long[] arrayPropertyValue = {42, 23, 87}; createIndex( db, label, propertyKey ); Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) )); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new long[]{42, 23}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }
@Test public void shouldIndexStringArrays() { String[] arrayPropertyValue = {"A, B", "C"}; createIndex( db, label, propertyKey ); Node node1; try ( Transaction tx = db.beginTx() ) { node1 = createNode( label, propertyKey, arrayPropertyValue ); tx.success(); } restart(); assertThat( getIndexes( db, label ), inTx( db, haveState( db, IndexState.ONLINE ) ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, arrayPropertyValue, db ), containsOnly( node1 ) ); assertThat( findNodesByLabelAndProperty( label, propertyKey, new String[]{"A", "B, C"}, db ), isEmpty() ); assertThat( findNodesByLabelAndProperty( label, propertyKey, Arrays.toString( arrayPropertyValue ), db ), isEmpty() ); }