private IndexEntryUpdate<?> remove( long nodeId, Object removedValue ) { return IndexQueryHelper.remove( nodeId, index.schema(), removedValue ); }
private IndexEntryUpdate<?> remove( long nodeId, Object... values ) { return IndexQueryHelper.remove( nodeId, SCHEMA_INDEX_DESCRIPTOR.schema(), values ); }
private IndexEntryUpdate<?> remove( long nodeId, Object value ) { return IndexQueryHelper.remove( nodeId, index.schema(), value ); }
private IndexEntryUpdate<?> remove( long nodeId, Object oldValue ) { return IndexQueryHelper.remove( nodeId, index.schema(), oldValue ); }
@Test void removalsDeliveredToIndexWriter() throws Exception { LuceneIndexWriter writer = mock( LuceneIndexWriter.class ); UniqueLuceneIndexPopulatingUpdater updater = newUpdater( writer ); updater.process( remove( 1, descriptor, "foo" ) ); updater.process( remove( 2, descriptor, "bar" ) ); updater.process( remove( 3, descriptor, "baz" ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 1 ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 2 ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 3 ) ); }
@Test void removalsDeliveredToIndexWriter() throws Exception { LuceneIndexWriter writer = mock( LuceneIndexWriter.class ); NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater( writer ); updater.process( remove( 1, SCHEMA_DESCRIPTOR, "foo" ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 1 ) ); updater.process( remove( 2, SCHEMA_DESCRIPTOR, "bar" ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 2 ) ); updater.process( remove( 3, SCHEMA_DESCRIPTOR, "baz" ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 3 ) ); updater.process( remove( 4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "baz" ) ); verify( writer ).deleteDocuments( newTermForChangeOrRemove( 4 ) ); }
@Test void removedNodePropertyIncludedInSample() throws Exception { long initialValue = 10; UniqueIndexSampler sampler = new UniqueIndexSampler(); sampler.increment( initialValue ); UniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( remove( 1, descriptor, "removed1" ) ); updater.process( remove( 2, descriptor, "removed2" ) ); verifySamplingResult( sampler, initialValue - 2 ); }
@Test void removedNodePropertyIncludedInSample() throws Exception { NonUniqueIndexSampler sampler = newSampler(); NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, SCHEMA_DESCRIPTOR, "foo" ) ); updater.process( add( 2, SCHEMA_DESCRIPTOR, "bar" ) ); updater.process( add( 3, SCHEMA_DESCRIPTOR, "baz" ) ); updater.process( add( 4, SCHEMA_DESCRIPTOR, "qux" ) ); updater.process( remove( 1, SCHEMA_DESCRIPTOR, "foo" ) ); updater.process( remove( 2, SCHEMA_DESCRIPTOR, "bar" ) ); updater.process( remove( 4, SCHEMA_DESCRIPTOR, "qux" ) ); verifySamplingResult( sampler, 1, 1, 1 ); }
@Test void removedNodeCompositePropertyIncludedInSample() throws Exception { NonUniqueIndexSampler sampler = newSampler(); NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "foo" ) ); updater.process( add( 2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar" ) ); updater.process( add( 3, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "baz" ) ); updater.process( add( 4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux" ) ); updater.process( remove( 1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "foo" ) ); updater.process( remove( 2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar" ) ); updater.process( remove( 4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux" ) ); verifySamplingResult( sampler, 1, 1, 1 ); }
@Test void closeVerifiesUniquenessOfAddedAndChangedValues() throws Exception { SchemaIndex index = mock( SchemaIndex.class ); UniqueLuceneIndexPopulatingUpdater updater = newUpdater( index ); updater.process( add( 1, descriptor, "added1" ) ); updater.process( add( 2, descriptor, "added2" ) ); updater.process( change( 3, descriptor, "before1", "after1" ) ); updater.process( change( 4, descriptor, "before2", "after2" ) ); updater.process( remove( 5, descriptor, "removed1" ) ); verifyZeroInteractions( index ); updater.close(); verifyVerifyUniqueness( index, descriptor, "added1", "added2", "after1", "after2" ); }
@Test public void shouldUpdateEntryForNodeThatHasPropertyRemovedAndThenAddedAgain() throws Exception { // given populator = newPopulator(); addUpdate( populator, 1, "value1" ); // when IndexUpdater updater = populator.newPopulatingUpdater( nodePropertyAccessor ); updater.process( remove( 1, schemaDescriptor, "value1" ) ); updater.process( add( 1, schemaDescriptor, "value1" ) ); populator.close( true ); // then assertEquals( asList(1L), getAllNodes( getDirectory(), "value1" ) ); }
@Test public void shouldRemoveEntryForNodeThatHasAlreadyBeenIndexed() throws Exception { // given populator = newPopulator(); addUpdate( populator, 1, "value1" ); // when IndexUpdater updater = populator.newPopulatingUpdater( nodePropertyAccessor ); updater.process( remove( 1, schemaDescriptor, "value1" ) ); populator.close( true ); // then assertEquals( Collections.EMPTY_LIST, getAllNodes( getDirectory(), "value1" ) ); }
@Test void nodePropertyUpdatesIncludedInSample() throws Exception { UniqueIndexSampler sampler = new UniqueIndexSampler(); UniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, descriptor, "foo" ) ); updater.process( change( 1, descriptor, "foo", "bar" ) ); updater.process( add( 2, descriptor, "baz" ) ); updater.process( add( 3, descriptor, "qux" ) ); updater.process( remove( 4, descriptor, "qux" ) ); verifySamplingResult( sampler, 2 ); }
@Test void nodePropertyUpdatesIncludedInSample() throws Exception { NonUniqueIndexSampler sampler = newSampler(); NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, SCHEMA_DESCRIPTOR, "foo" ) ); updater.process( change( 1, SCHEMA_DESCRIPTOR, "foo", "newFoo1" ) ); updater.process( add( 2, SCHEMA_DESCRIPTOR, "bar" ) ); updater.process( remove( 2, SCHEMA_DESCRIPTOR, "bar" ) ); updater.process( change( 1, SCHEMA_DESCRIPTOR, "newFoo1", "newFoo2" ) ); updater.process( add( 42, SCHEMA_DESCRIPTOR, "qux" ) ); updater.process( add( 3, SCHEMA_DESCRIPTOR, "bar" ) ); updater.process( add( 4, SCHEMA_DESCRIPTOR, "baz" ) ); updater.process( add( 5, SCHEMA_DESCRIPTOR, "bar" ) ); updater.process( remove( 42, SCHEMA_DESCRIPTOR, "qux" ) ); verifySamplingResult( sampler, 4, 3, 4 ); }
@Test void nodeCompositePropertyUpdatesIncludedInSample() throws Exception { NonUniqueIndexSampler sampler = newSampler(); NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "foo" ) ); updater.process( change( 1, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[]{"bit", "foo"}, new Object[]{"bit", "newFoo1"} ) ); updater.process( add( 2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar" ) ); updater.process( remove( 2, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar" ) ); updater.process( change( 1, COMPOSITE_SCHEMA_DESCRIPTOR, new Object[]{"bit", "newFoo1"}, new Object[]{"bit", "newFoo2"} ) ); updater.process( add( 42, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux" ) ); updater.process( add( 3, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar" ) ); updater.process( add( 4, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "baz" ) ); updater.process( add( 5, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "bar" ) ); updater.process( remove( 42, COMPOSITE_SCHEMA_DESCRIPTOR, "bit", "qux" ) ); verifySamplingResult( sampler, 4, 3, 4 ); }