static IndexEntryUpdate<LabelSchemaDescriptor> change( Value[] before, Value[] after ) { return IndexEntryUpdate.change( 0, compositeIndexKey, before, after ); }
static IndexEntryUpdate<LabelSchemaDescriptor> change( Value before, Value after ) { return IndexEntryUpdate.change( 0, indexKey, before, after ); }
public static IndexEntryUpdate<SchemaDescriptor> change( long nodeId, SchemaDescriptor schema, Object[] o1, Object[] o2 ) { return IndexEntryUpdate.change( nodeId, schema, toValues( o1 ), toValues( o2 ) ); }
public static IndexEntryUpdate<SchemaDescriptor> change( long nodeId, SchemaDescriptor schema, Object o1, Object o2 ) { return IndexEntryUpdate.change( nodeId, schema, Values.of( o1 ), Values.of( o2 ) ); }
@Test public void changedShouldRetainValues() { Value singleAfter = Values.of( "Hello" ); IndexEntryUpdate<?> singleChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue, singleAfter ); Value[] multiAfter = {Values.of( "Hello" ), Values.of( "Hi" )}; IndexEntryUpdate<?> multiChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4, 5 ), multiValue, multiAfter ); assertThat( new Object[]{singleValue}, equalTo( singleChange.beforeValues() ) ); assertThat( new Object[]{singleAfter}, equalTo( singleChange.values() ) ); assertThat( multiValue, equalTo( multiChange.beforeValues() ) ); assertThat( multiAfter, equalTo( multiChange.values() ) ); } }
@SuppressWarnings( "ConstantConditions" ) private <INDEX_KEY extends SchemaDescriptorSupplier> Iterable<IndexEntryUpdate<INDEX_KEY>> gatherUpdatesForPotentials( Iterable<INDEX_KEY> potentiallyRelevant ) { List<IndexEntryUpdate<INDEX_KEY>> indexUpdates = new ArrayList<>(); for ( INDEX_KEY indexKey : potentiallyRelevant ) { SchemaDescriptor schema = indexKey.schema(); boolean relevantBefore = relevantBefore( schema ); boolean relevantAfter = relevantAfter( schema ); int[] propertyIds = schema.getPropertyIds(); if ( relevantBefore && !relevantAfter ) { indexUpdates.add( IndexEntryUpdate.remove( entityId, indexKey, valuesBefore( propertyIds ) ) ); } else if ( !relevantBefore && relevantAfter ) { indexUpdates.add( IndexEntryUpdate.add( entityId, indexKey, valuesAfter( propertyIds ) ) ); } else if ( relevantBefore && relevantAfter ) { if ( valuesChanged( propertyIds, schema.propertySchemaType() ) ) { indexUpdates.add( IndexEntryUpdate.change( entityId, indexKey, valuesBefore( propertyIds ), valuesAfter( propertyIds ) ) ); } } } return indexUpdates; }
@Test public void updatesShouldEqualRegardlessOfCreationMethod() { IndexEntryUpdate<?> singleAdd = IndexEntryUpdate.add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); Value[] singleAsArray = {singleValue}; IndexEntryUpdate<?> multiAdd = IndexEntryUpdate .add( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleAsArray ); IndexEntryUpdate<?> singleRemove = IndexEntryUpdate .remove( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue ); IndexEntryUpdate<?> multiRemove = IndexEntryUpdate .remove( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleAsArray ); IndexEntryUpdate<?> singleChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleValue, singleValue ); IndexEntryUpdate<?> multiChange = IndexEntryUpdate .change( 0, SchemaDescriptorFactory.forLabel( 3, 4 ), singleAsArray, singleAsArray ); assertThat( singleAdd, equalTo( multiAdd ) ); assertThat( singleRemove, equalTo( multiRemove ) ); assertThat( singleChange, equalTo( multiChange ) ); }
@Override public void receive( StorageNodeCursor node ) { if ( node.entityReference() == 7 ) { indexPopulator.queueUpdate( IndexEntryUpdate.change( 8L, index, Values.of( "a" ), Values.of( "b" ) ) ); } } }
void add( IndexEntryUpdate<?> update ) { if ( update.getEntityId() == 2 ) { job.update( IndexEntryUpdate.change( nodeToChange, index, previousValue, newValue ) ); } added.add( Pair.of( update.getEntityId(), update.values()[0].asObjectCopy() ) ); }
case 2: // change removal = batch.get( randomValues.nextInt( batch.size() ) ); change( removal.getEntityId(), descriptor, removal.values(), toArray( valueGenerator.apply( randomValues ) ) ); break; default:
@Test public void shouldGenerateUpdateWhenRemovingOnePropertyForNonSchemaIndex() { // When EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( label ) .removed( property2.propertyKeyId(), property2.value() ) .build(); // Then assertThat( updates.forIndexKeys( singleton( nonSchemaIndex ), propertyLoader( property1, property2, property3 ), EntityType.NODE ), containsInAnyOrder( IndexEntryUpdate.change( nodeId, nonSchemaIndex, values123, new Value[]{property1.value(), null, property3.value()} ) ) ); }
List<IndexEntryUpdate<IndexDescriptor>> updates = new ArrayList<>(); updates.add( add( nodeId++, descriptor, tuple( 10, 11 ) ) ); updates.add( change( nodeId++, descriptor, tuple( "abc", "def" ), tuple( "ghi", "klm" ) ) ); updates.add( remove( nodeId++, descriptor, tuple( 1001L, 1002L ) ) ); updates.add( change( nodeId++, descriptor, tuple( (byte) 2, (byte) 3 ), tuple( (byte) 4, (byte) 5 ) ) ); updates.add( add( nodeId++, descriptor, tuple( 5, "5" ) ) ); try ( DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater( actual, () -> reader, descriptor ) )
updates[i] = change( toChange.getEntityId(), indexDescriptor, toChange.values(), updateContainingValue.values() );
@Test public void shouldGenerateUpdateForSingleChangeNonSchemaIndex() { // When Value newValue2 = Values.of( 10L ); EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( label ) .changed( property2.propertyKeyId(), property2.value(), newValue2 ) .build(); // Then assertThat( updates.forIndexKeys( singleton( nonSchemaIndex ), propertyLoader( property1, property2, property3 ), EntityType.NODE ), containsInAnyOrder( IndexEntryUpdate.change( nodeId, nonSchemaIndex, values123, new Value[]{property1.value(), newValue2, property3.value()} ) ) ); }
@Test public void shouldGenerateUpdateForAllChangedNonSchemaIndex() { // When Value newValue1 = Values.of( "Nio" ); Value newValue2 = Values.of( 10L ); Value newValue3 = Values.pointValue( CoordinateReferenceSystem.WGS84, 32.3, 15.6 ); EntityUpdates updates = EntityUpdates.forEntity( nodeId ).withTokens( label ).withTokensAfter( label ) .changed( property1.propertyKeyId(), property1.value(), newValue1 ) .changed( property2.propertyKeyId(), property2.value(), newValue2 ) .changed( property3.propertyKeyId(), property3.value(), newValue3 ) .build(); // Then assertThat( updates.forIndexKeys( singleton( nonSchemaIndex ), propertyLoader( property1, property2, property3 ), EntityType.NODE ), containsInAnyOrder( IndexEntryUpdate.change( nodeId, nonSchemaIndex, values123, new Value[]{newValue1, newValue2, newValue3} ) ) ); }
@Test public void shouldIndexChange() throws Exception { // given IndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType(); processAll( updates ); Iterator<IndexEntryUpdate<IndexDescriptor>> generator = filter( skipExisting( updates ), valueCreatorUtil.randomUpdateGenerator( random ) ); for ( int i = 0; i < updates.length; i++ ) { IndexEntryUpdate<IndexDescriptor> update = updates[i]; Value newValue = generator.next().values()[0]; updates[i] = change( update.getEntityId(), indexDescriptor, update.values()[0], newValue ); } // when processAll( updates ); // then forceAndCloseAccessor(); verifyUpdates( updates ); }
@SuppressWarnings( "ConstantConditions" ) private <INDEX_KEY extends SchemaDescriptorSupplier> Iterable<IndexEntryUpdate<INDEX_KEY>> gatherUpdatesForPotentials( Iterable<INDEX_KEY> potentiallyRelevant ) { List<IndexEntryUpdate<INDEX_KEY>> indexUpdates = new ArrayList<>(); for ( INDEX_KEY indexKey : potentiallyRelevant ) { SchemaDescriptor schema = indexKey.schema(); boolean relevantBefore = relevantBefore( schema ); boolean relevantAfter = relevantAfter( schema ); int[] propertyIds = schema.getPropertyIds(); if ( relevantBefore && !relevantAfter ) { indexUpdates.add( IndexEntryUpdate.remove( entityId, indexKey, valuesBefore( propertyIds ) ) ); } else if ( !relevantBefore && relevantAfter ) { indexUpdates.add( IndexEntryUpdate.add( entityId, indexKey, valuesAfter( propertyIds ) ) ); } else if ( relevantBefore && relevantAfter ) { if ( valuesChanged( propertyIds, schema.propertySchemaType() ) ) { indexUpdates.add( IndexEntryUpdate.change( entityId, indexKey, valuesBefore( propertyIds ), valuesAfter( propertyIds ) ) ); } } } return indexUpdates; }