@Override public IndexSample sampleResult() { List<IndexSample> samples = new ArrayList<>(); for ( IndexPopulator partPopulator : this ) { samples.add( partPopulator.sampleResult() ); } return combineSamples( samples ); }
@Override public IndexSample sampleResult() { List<IndexSample> samples = new ArrayList<>(); for ( IndexPopulator partPopulator : this ) { samples.add( partPopulator.sampleResult() ); } return combineSamples( samples ); }
private static IndexPopulator createIndexPopulator() { IndexPopulator populator = mock( IndexPopulator.class ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); return populator; }
@Before public void setUp() { when( populator.sampleResult() ).thenReturn( new IndexSample() ); when( storeView.indexSample( anyLong(), any( DoubleLongRegister.class ) ) ) .thenAnswer( invocation -> invocation.getArgument( 1 ) ); }
@Test public void canceledPopulationNotAbleToFlip() throws FlipFailedKernelException { IndexPopulator populator = createIndexPopulator(); IndexPopulation indexPopulation = addPopulator( populator, 1 ); indexPopulation.cancel(); indexPopulation.flip( false ); verify( indexPopulation.populator, never() ).sampleResult(); }
@Test public void shouldVerifyConstraintsBeforeFlippingIfToldTo() throws IndexEntryConflictException { // given IndexProxyFactory indexProxyFactory = mock( IndexProxyFactory.class ); FailedIndexProxyFactory failedIndexProxyFactory = mock( FailedIndexProxyFactory.class ); FlippableIndexProxy flipper = new FlippableIndexProxy(); flipper.setFlipTarget( indexProxyFactory ); IndexPopulator indexPopulator = createIndexPopulator(); addPopulator( indexPopulator, 1, flipper, failedIndexProxyFactory ); when( indexPopulator.sampleResult() ).thenReturn( new IndexSample() ); // when multipleIndexPopulator.indexAllEntities(); multipleIndexPopulator.flipAfterPopulation( true ); // then verify( indexPopulator ).verifyDeferredConstraints( any( NodePropertyAccessor.class ) ); verify( indexPopulator ).close( true ); }
IndexSample sample = populator.sampleResult(); storeView.replaceIndexCounts( indexId, sample.uniqueValues(), sample.sampleSize(), sample.indexSize() ); populator.close( true );
.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ) .thenReturn( populator ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); IndexAccessor mockedAccessor = mock( IndexAccessor.class ); when( mockedAccessor.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( SwallowingIndexUpdater.INSTANCE );
@Test public void testIndexFlip() { IndexProxyFactory indexProxyFactory = mock( IndexProxyFactory.class ); FailedIndexProxyFactory failedIndexProxyFactory = mock( FailedIndexProxyFactory.class ); FlippableIndexProxy flipper = new FlippableIndexProxy(); flipper.setFlipTarget( indexProxyFactory ); IndexPopulator indexPopulator1 = createIndexPopulator(); IndexPopulator indexPopulator2 = createIndexPopulator(); addPopulator( indexPopulator1, 1, flipper, failedIndexProxyFactory ); addPopulator( indexPopulator2, 2, flipper, failedIndexProxyFactory ); when( indexPopulator1.sampleResult() ).thenThrow( getSampleError() ); multipleIndexPopulator.indexAllEntities(); multipleIndexPopulator.flipAfterPopulation( false ); verify( indexPopulator1 ).close( false ); verify( failedIndexProxyFactory, times( 1 ) ).create( any( RuntimeException.class ) ); verify( indexPopulator2 ).close( true ); verify( indexPopulator2 ).sampleResult(); verify( indexStoreView ).replaceIndexCounts( anyLong(), anyLong(), anyLong(), anyLong() ); verify( schemaState ).clear(); }
@Test public void shouldRunIndexPopulationJobAtShutdown() throws Throwable { // GIVEN IndexPopulator populator = mock( IndexPopulator.class ); IndexProvider provider = mock( IndexProvider.class ); IndexAccessor accessor = mock( IndexAccessor.class ); when( provider.getProviderDescriptor() ).thenReturn( DESCRIPTOR ); when( provider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( populator ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); when( provider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( accessor ); when( provider.bless( any( IndexDescriptor.class ) ) ).thenCallRealMethod(); BatchInserter inserter = newBatchInserterWithIndexProvider( singleInstanceIndexProviderFactory( KEY, provider ), provider.getProviderDescriptor() ); inserter.createDeferredSchemaIndex( label( "Hacker" ) ).on( "handle" ).create(); long nodeId = inserter.createNode( map( "handle", "Jakewins" ), label( "Hacker" ) ); // WHEN inserter.shutdown(); // THEN verify( provider ).init(); verify( provider ).start(); verify( provider ).getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); verify( populator ).add( argThat( matchesCollection( add( nodeId, internalIndex.schema(), Values.of( "Jakewins" ) ) ) ) ); verify( populator ).verifyDeferredConstraints( any( NodePropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); verify( provider ).shutdown(); }
@Test public void shouldRunConstraintPopulationJobAtShutdown() throws Throwable { // GIVEN IndexPopulator populator = mock( IndexPopulator.class ); IndexProvider provider = mock( IndexProvider.class ); IndexAccessor accessor = mock( IndexAccessor.class ); when( provider.getProviderDescriptor() ).thenReturn( DESCRIPTOR ); when( provider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( populator ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); when( provider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( accessor ); when( provider.bless( any( IndexDescriptor.class ) ) ).thenCallRealMethod(); BatchInserter inserter = newBatchInserterWithIndexProvider( singleInstanceIndexProviderFactory( KEY, provider ), provider.getProviderDescriptor() ); inserter.createDeferredConstraint( label( "Hacker" ) ).assertPropertyIsUnique( "handle" ).create(); long nodeId = inserter.createNode( map( "handle", "Jakewins" ), label( "Hacker" ) ); // WHEN inserter.shutdown(); // THEN verify( provider ).init(); verify( provider ).start(); verify( provider ).getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); verify( populator ).add( argThat( matchesCollection( add( nodeId, internalUniqueIndex.schema(), Values.of( "Jakewins" ) ) ) ) ); verify( populator ).verifyDeferredConstraints( any( NodePropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); verify( provider ).shutdown(); }
@Test public void shouldRepopulatePreexistingIndexed() throws Throwable { // GIVEN long jakewins = dbWithIndexAndSingleIndexedNode(); IndexPopulator populator = mock( IndexPopulator.class ); IndexProvider provider = mock( IndexProvider.class ); IndexAccessor accessor = mock( IndexAccessor.class ); when( provider.getProviderDescriptor() ).thenReturn( DESCRIPTOR ); when( provider.getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( populator ); when( populator.sampleResult() ).thenReturn( new IndexSample() ); when( provider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( accessor ); BatchInserter inserter = newBatchInserterWithIndexProvider( singleInstanceIndexProviderFactory( KEY, provider ), provider.getProviderDescriptor() ); long boggle = inserter.createNode( map( "handle", "b0ggl3" ), label( "Hacker" ) ); // WHEN inserter.shutdown(); // THEN verify( provider ).init(); verify( provider ).start(); verify( provider ).getPopulator( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ); verify( populator ).create(); verify( populator ).add( argThat( matchesCollection( add( jakewins, internalIndex.schema(), Values.of( "Jakewins" ) ), add( boggle, internalIndex.schema(), Values.of( "b0ggl3" ) ) ) ) ); verify( populator ).verifyDeferredConstraints( any( NodePropertyAccessor.class ) ); verify( populator ).close( true ); verify( provider ).stop(); verify( provider ).shutdown(); }
@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 ); }
order.verify( populator ).newPopulatingUpdater( storeView ); order.verify( updater ).close(); order.verify( populator ).sampleResult(); order.verify( populator ).close( true ); verifyNoMoreInteractions( updater );
@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 ); }
@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 ); }
@Override public IndexSample sampleResult() { List<IndexSample> samples = new ArrayList<>(); for ( IndexPopulator partPopulator : this ) { samples.add( partPopulator.sampleResult() ); } return combineSamples( samples ); }
@Override public IndexSample sampleResult() { List<IndexSample> samples = new ArrayList<>(); for ( IndexPopulator partPopulator : this ) { samples.add( partPopulator.sampleResult() ); } return combineSamples( samples ); }
IndexSample sample = populator.sampleResult(); storeView.replaceIndexCounts( indexId, sample.uniqueValues(), sample.sampleSize(), sample.indexSize() ); populator.close( true );