private List<IndexEntryUpdate<?>> generateUpdatesFromValues( List<Value> values ) { List<IndexEntryUpdate<?>> updates = new ArrayList<>(); int id = 0; for ( Value value : values ) { updates.add( add( id++, descriptor.schema(), value ) ); } return updates; } }
public List<Long> expectedIds( TreeSet<IndexEntryUpdate> sortedValues, Value booleanValue, Value from, Value to, boolean fromInclusive, boolean toInclusive ) { return sortedValues.subSet( add( 0, descriptor.schema(), booleanValue, from ), fromInclusive, add( 0, descriptor.schema(), booleanValue, to ), toInclusive ) .stream() .map( IndexEntryUpdate::getEntityId ) .sorted( Long::compare ) .collect( Collectors.toList() ); }
@Test void sampleIncludedUpdates() throws Exception { populator = newPopulator(); List<IndexEntryUpdate<?>> updates = Arrays.asList( add( 1, labelSchemaDescriptor, "aaa" ), add( 2, labelSchemaDescriptor, "bbb" ), add( 3, labelSchemaDescriptor, "ccc" ) ); updates.forEach( populator::includeSample ); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample( 3, 3, 3 ), sample ); }
@Test void sampleIncludedUpdatesWithDuplicates() throws Exception { populator = newPopulator(); List<IndexEntryUpdate<?>> updates = Arrays.asList( add( 1, labelSchemaDescriptor, "foo" ), add( 2, labelSchemaDescriptor, "bar" ), add( 3, labelSchemaDescriptor, "foo" ) ); updates.forEach( populator::includeSample ); IndexSample sample = populator.sampleResult(); assertEquals( new IndexSample( 3, 2, 3 ), sample ); }
private List<Long> expectedIds( TreeSet<IndexEntryUpdate> sortedValues, Value from, Value to, boolean fromInclusive, boolean toInclusive ) { return sortedValues.subSet( add( 0, descriptor.schema(), from ), fromInclusive, add( 0, descriptor.schema(), to ), toInclusive ) .stream() .map( IndexEntryUpdate::getEntityId ) .sorted( Long::compare ) .collect( Collectors.toList() ); }
private List<IndexEntryUpdate<?>> generateUpdatesFromValues( List<ValueTuple> values ) { List<IndexEntryUpdate<?>> updates = new ArrayList<>(); int id = 0; for ( ValueTuple value : values ) { updates.add( add( id++, descriptor.schema(), (Object[]) value.getValues() ) ); } return updates; } }
private void addUpdate( IndexPopulator populator, long nodeId, Object value ) throws IOException, IndexEntryConflictException { populator.add( singletonList( IndexQueryHelper.add( nodeId, index.schema(), value ) ) ); }
private static void addUpdate( UniqueLuceneIndexPopulator populator, long nodeId, Object value ) throws IOException { IndexEntryUpdate<?> update = add( nodeId, descriptor.schema(), value ); populator.add( asList( update ) ); }
@Test void addedNodePropertiesIncludedInSample() 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, "bar" ) ); verifySamplingResult( sampler, 4, 3, 4 ); }
@Test void addedNodeCompositePropertiesIncludedInSample() 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", "bar" ) ); verifySamplingResult( sampler, 4, 3, 4 ); }
@Test void closeVerifiesUniquenessOfAddedValues() throws Exception { SchemaIndex index = mock( SchemaIndex.class ); UniqueLuceneIndexPopulatingUpdater updater = newUpdater( index ); updater.process( add( 1, descriptor, "foo" ) ); updater.process( add( 1, descriptor, "bar" ) ); updater.process( add( 1, descriptor, "baz" ) ); verifyZeroInteractions( index ); updater.close(); verifyVerifyUniqueness( index, descriptor, "foo", "bar", "baz" ); }
@Test void addedNodePropertiesIncludedInSample() throws Exception { UniqueIndexSampler sampler = new UniqueIndexSampler(); UniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, descriptor, "foo" ) ); updater.process( add( 2, descriptor, "bar" ) ); updater.process( add( 3, descriptor, "baz" ) ); updater.process( add( 4, descriptor, "qux" ) ); verifySamplingResult( sampler, 4 ); }
private void doTestShouldHandleLargeAmountOfDuplicates( Object value ) throws Exception { List<IndexEntryUpdate<?>> updates = new ArrayList<>(); List<Long> nodeIds = new ArrayList<>(); for ( long i = 0; i < 1000; i++ ) { nodeIds.add( i ); updates.add( add( i, descriptor.schema(), value ) ); } updateAndCommit( updates ); assertThat( query( exists( 1 ) ), equalTo( nodeIds ) ); }
@Test public void testIndexRangeSeekByPrefixWithDuplicates() throws Exception { updateAndCommit( asList( add( 1L, descriptor.schema(), "a" ), add( 2L, descriptor.schema(), "A" ), add( 3L, descriptor.schema(), "apa" ), add( 4L, descriptor.schema(), "apa" ), add( 5L, descriptor.schema(), "apa" ) ) ); assertThat( query( stringPrefix( 1, stringValue( "a" ) ) ), equalTo( asList( 1L, 3L, 4L, 5L ) ) ); assertThat( query( stringPrefix( 1, stringValue( "apa" ) ) ), equalTo( asList( 3L, 4L, 5L ) ) ); }
@Test public void testIndexSeekByPrefixOnNonStrings() throws Exception { updateAndCommit( asList( add( 1L, descriptor.schema(), "2a" ), add( 2L, descriptor.schema(), 2L ), add( 2L, descriptor.schema(), 20L ) ) ); assertThat( query( IndexQuery.stringPrefix( 1, stringValue( "2" ) ) ), equalTo( singletonList( 1L ) ) ); }
@Test public void closingAnOnlineIndexUpdaterMustNotThrowEvenIfItHasBeenFedConflictingData() throws Exception { // The reason is that we use and close IndexUpdaters in commit - not in prepare - and therefor // we cannot have them go around and throw exceptions, because that could potentially break // recovery. // Conflicting data can happen because of faulty data coercion. These faults are resolved by // the exact-match filtering we do on index seeks. updateAndCommit( asList( add( 1L, descriptor.schema(), "a" ), add( 2L, descriptor.schema(), "a" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); }
@Test public void testIndexSeekAndScan() throws Exception { updateAndCommit( asList( add( 1L, descriptor.schema(), "a" ), add( 2L, descriptor.schema(), "a" ), add( 3L, descriptor.schema(), "b" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( asList( 1L, 2L ) ) ); assertThat( query( exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); }
@Test public void testIndexSeekAndScan() throws Exception { updateAndCommit( asList( add( 1L, descriptor.schema(), "a" ), add( 2L, descriptor.schema(), "b" ), add( 3L, descriptor.schema(), "c" ) ) ); assertThat( query( exact( 1, "a" ) ), equalTo( singletonList( 1L ) ) ); assertThat( query( IndexQuery.exists( 1 ) ), equalTo( asList( 1L, 2L, 3L ) ) ); } }
@Test void changedNodePropertiesIncludedInSample() throws Exception { NonUniqueIndexSampler sampler = newSampler(); NonUniqueLuceneIndexPopulatingUpdater updater = newUpdater( sampler ); updater.process( add( 1, SCHEMA_DESCRIPTOR, "initial1" ) ); updater.process( add( 2, SCHEMA_DESCRIPTOR, "initial2" ) ); updater.process( add( 3, SCHEMA_DESCRIPTOR, "new2" ) ); updater.process( change( 1, SCHEMA_DESCRIPTOR, "initial1", "new1" ) ); updater.process( change( 1, SCHEMA_DESCRIPTOR, "initial2", "new2" ) ); verifySamplingResult( sampler, 3, 2, 3 ); }
@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 ); }