@Test public void shouldPopulateWithAllValues() throws Exception { // GIVEN withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> p.add( updates( valueSet1 ) ) ); // THEN assertHasAllValues( valueSet1 ); }
@Test public void shouldUpdateWithAllValuesDuringPopulation() throws Exception { // GIVEN withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> { try ( IndexUpdater updater = p.newPopulatingUpdater( this::valueSet1Lookup ) ) { for ( NodeAndValue entry : valueSet1 ) { updater.process( add( entry.nodeId, descriptor.schema(), entry.value ) ); } } } ); // THEN assertHasAllValues( valueSet1 ); }
@Test public void shouldPopulateAndUpdate() throws Exception { // GIVEN withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> p.add( updates( valueSet1 ) ) ); try ( IndexAccessor accessor = indexProvider.getOnlineAccessor( descriptor, indexSamplingConfig ) ) { // WHEN try ( IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ) ) { List<IndexEntryUpdate<?>> updates = updates( valueSet2 ); for ( IndexEntryUpdate<?> update : updates ) { updater.process( update ); } } // THEN try ( IndexReader reader = new QueryResultComparingIndexReader( accessor.newReader() ) ) { int propertyKeyId = descriptor.schema().getPropertyId(); for ( NodeAndValue entry : Iterables.concat( valueSet1, valueSet2 ) ) { NodeValueIterator nodes = new NodeValueIterator(); reader.query( nodes, IndexOrder.NONE, false , IndexQuery.exact( propertyKeyId, entry.value ) ); assertEquals( entry.nodeId, nodes.next() ); assertFalse( nodes.hasNext() ); } } } }
@Test public void shouldStorePopulationFailedForRetrievalFromProviderLater() throws Exception { // GIVEN String failure = "The contrived failure"; IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() ); // WHEN (this will attempt to call close) withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> p.markAsFailed( failure ), false ); // THEN assertThat( indexProvider.getPopulationFailure( descriptor ), containsString( failure ) ); }
@Test public void shouldReportInitialStateAsFailedIfPopulationFailed() throws Exception { // GIVEN IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() ); withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> { String failure = "The contrived failure"; // WHEN p.markAsFailed( failure ); p.close( false ); // THEN assertEquals( FAILED, indexProvider.getInitialState( descriptor ) ); }, false ); }
@Test public void shouldApplyUpdatesIdempotently() throws Exception { // GIVEN IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig( Config.defaults() ); final Value propertyValue = Values.of( "value1" ); withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> { long nodeId = 1; // update using populator... IndexEntryUpdate<SchemaDescriptor> update = add( nodeId, descriptor.schema(), propertyValue ); p.add( singletonList( update ) ); // ...is the same as update using updater try ( IndexUpdater updater = p.newPopulatingUpdater( ( node, propertyId ) -> propertyValue ) ) { updater.process( update ); } } ); // THEN try ( IndexAccessor accessor = indexProvider.getOnlineAccessor( descriptor, indexSamplingConfig ) ) { try ( IndexReader reader = new QueryResultComparingIndexReader( accessor.newReader() ) ) { int propertyKeyId = descriptor.schema().getPropertyId(); LongIterator nodes = reader.query( IndexQuery.exact( propertyKeyId, propertyValue ) ); assertEquals( asSet( 1L ), PrimitiveLongCollections.toSet( nodes ) ); } } }