private void onUpdate( IndexEntryUpdate<?> update ) { populator.includeSample( update ); if ( batch( update ) ) { flush( this ); } }
@Override public void includeSample( IndexEntryUpdate<?> update ) { instanceSelector.select( slotSelector.selectSlot( update.values(), GROUP_OF ) ).includeSample( update ); }
private void verifySampleToCorrectPopulator( Value[] values, IndexPopulator populator ) { for ( Value value : values ) { // when IndexEntryUpdate<LabelSchemaDescriptor> update = add( value ); fusionIndexPopulator.includeSample( update ); // then verify( populator ).includeSample( update ); reset( populator ); } }
@Override public void process( IndexEntryUpdate<?> update ) { Pair<IndexPopulation,IndexUpdater> pair = populationsWithUpdaters.get( update.indexKey().schema() ); if ( pair != null ) { IndexPopulation population = pair.first(); IndexUpdater updater = pair.other(); try { population.populator.includeSample( update ); updater.process( update ); } catch ( Throwable t ) { try { updater.close(); } catch ( Throwable ce ) { log.error( format( "Failed to close index updater: [%s]", updater ), ce ); } populationsWithUpdaters.remove( update.indexKey().schema() ); multipleIndexPopulator.fail( population, t ); } } }
@Test public void shouldPopulateIndexWithOneNode() throws Exception { // GIVEN String value = "Taylor"; long nodeId = createNode( map( name, value ), FIRST ); IndexPopulator populator = spy( indexPopulator( false ) ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( 0, 0 ); IndexPopulationJob job = newIndexPopulationJob( populator, new FlippableIndexProxy(), EntityType.NODE, IndexDescriptorFactory.forSchema( descriptor ) ); // WHEN job.run(); // THEN IndexEntryUpdate<?> update = IndexEntryUpdate.add( nodeId, descriptor, Values.of( value ) ); verify( populator ).create(); verify( populator ).includeSample( update ); verify( populator, times( 2 ) ).add( any( Collection.class) ); verify( populator ).sampleResult(); verify( populator ).close( true ); }
@Test public void shouldPopulateIndexWithOneRelationship() throws Exception { // GIVEN String value = "Taylor"; long nodeId = createNode( map( name, value ), FIRST ); long relationship = createRelationship( map( name, age ), likes, nodeId, nodeId ); IndexDescriptor descriptor = IndexDescriptorFactory.forSchema( SchemaDescriptorFactory.forRelType( 0, 0 ) ); IndexPopulator populator = spy( indexPopulator( descriptor ) ); IndexPopulationJob job = newIndexPopulationJob( populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor ); // WHEN job.run(); // THEN IndexEntryUpdate<?> update = IndexEntryUpdate.add( relationship, descriptor, Values.of( age ) ); verify( populator ).create(); verify( populator ).includeSample( update ); verify( populator, times( 2 ) ).add( any( Collection.class ) ); verify( populator ).sampleResult(); verify( populator ).close( true ); }
@Test public void shouldPopulateIndexWithASmallDataset() throws Exception { // GIVEN String value = "Mattias"; long node1 = createNode( map( name, value ), FIRST ); createNode( map( name, value ), SECOND ); createNode( map( age, 31 ), FIRST ); long node4 = createNode( map( age, 35, name, value ), FIRST ); IndexPopulator populator = spy( indexPopulator( false ) ); LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel( 0, 0 ); IndexPopulationJob job = newIndexPopulationJob( populator, new FlippableIndexProxy(), EntityType.NODE, IndexDescriptorFactory.forSchema( descriptor ) ); // WHEN job.run(); // THEN IndexEntryUpdate<?> update1 = add( node1, descriptor, Values.of( value ) ); IndexEntryUpdate<?> update2 = add( node4, descriptor, Values.of( value ) ); verify( populator ).create(); verify( populator ).includeSample( update1 ); verify( populator ).includeSample( update2 ); verify( populator, times( 2 ) ).add( anyCollection() ); verify( populator ).sampleResult(); verify( populator ).close( true ); }
InOrder order = inOrder( populator, accessor, updater); order.verify( populator ).create(); order.verify( populator ).includeSample( add( 1, "value1" ) ); order.verify( populator, times( 3 ) ).add( any( Collection.class ) ); order.verify( populator ).newPopulatingUpdater( storeView );
@Test public void shouldPopulateRelatonshipIndexWithASmallDataset() throws Exception { // GIVEN String value = "Philip J.Fry"; long node1 = createNode( map( name, value ), FIRST ); long node2 = createNode( map( name, value ), SECOND ); long node3 = createNode( map( age, 31 ), FIRST ); long node4 = createNode( map( age, 35, name, value ), FIRST ); long rel1 = createRelationship( map( name, value ), likes, node1, node3 ); createRelationship( map( name, value ), knows, node3, node1 ); createRelationship( map( age, 31 ), likes, node2, node1 ); long rel4 = createRelationship( map( age, 35, name, value ), likes, node4, node4 ); IndexDescriptor descriptor = IndexDescriptorFactory.forSchema( SchemaDescriptorFactory.forRelType( 0, 0 ) ); IndexPopulator populator = spy( indexPopulator( descriptor ) ); IndexPopulationJob job = newIndexPopulationJob( populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor ); // WHEN job.run(); // THEN IndexEntryUpdate<?> update1 = add( rel1, descriptor, Values.of( value ) ); IndexEntryUpdate<?> update2 = add( rel4, descriptor, Values.of( value ) ); verify( populator ).create(); verify( populator ).includeSample( update1 ); verify( populator ).includeSample( update2 ); verify( populator, times( 2 ) ).add( anyCollection() ); verify( populator ).sampleResult(); verify( populator ).close( true ); }
private void onUpdate( IndexEntryUpdate<?> update ) { populator.includeSample( update ); if ( batch( update ) ) { flush( this ); } }
@Override public void includeSample( IndexEntryUpdate<?> update ) { instanceSelector.select( slotSelector.selectSlot( update.values(), GROUP_OF ) ).includeSample( update ); }
@Override public void process( IndexEntryUpdate<?> update ) { Pair<IndexPopulation,IndexUpdater> pair = populationsWithUpdaters.get( update.indexKey().schema() ); if ( pair != null ) { IndexPopulation population = pair.first(); IndexUpdater updater = pair.other(); try { population.populator.includeSample( update ); updater.process( update ); } catch ( Throwable t ) { try { updater.close(); } catch ( Throwable ce ) { log.error( format( "Failed to close index updater: [%s]", updater ), ce ); } populationsWithUpdaters.remove( update.indexKey().schema() ); multipleIndexPopulator.fail( population, t ); } } }