private void addSchema( Collection<DynamicRecord> beforeRecords, Collection<DynamicRecord> afterRecords, SchemaRule rule ) { otherCommands.add( new Command.SchemaRuleCommand( beforeRecords, afterRecords, rule ) ); }
@Test public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplier( true ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyUpdateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier base = newApplier( false ); final BatchTransactionApplier indexApplier = newIndexApplier(); final BatchTransactionApplierFacade applier = new BatchTransactionApplierFacade( base, indexApplier ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setInUse( false ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final StoreIndexDescriptor rule = indexRule( 0, 1, 2, new IndexProviderDescriptor( "K", "X.Y" ) ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( indexingService, times( 1 ) ).dropIndex( rule ); verify( cacheAccess, times( 1 ) ).removeSchemaRuleFromCache( command.getKey() ); }
private Command visitSchemaRuleCommand( ReadableChannel channel ) throws IOException { Collection<DynamicRecord> recordsBefore = new ArrayList<>(); readDynamicRecords( channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER ); Collection<DynamicRecord> recordsAfter = new ArrayList<>(); readDynamicRecords( channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER ); byte isCreated = channel.get(); if ( 1 == isCreated ) { for ( DynamicRecord record : recordsAfter ) { record.setCreated(); } } SchemaRule rule = Iterables.first( recordsAfter ).inUse() ? readSchemaRule( recordsAfter ) : readSchemaRule( recordsBefore ); return new Command.SchemaRuleCommand( recordsBefore, recordsAfter, rule ); }
@Test public void shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplierFacade( newIndexApplier(), newApplier( true ) ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setInUse( false ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final StoreIndexDescriptor rule = indexRule( 0, 1, 2, new IndexProviderDescriptor( "K", "X.Y" ) ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( indexingService, times( 1 ) ).dropIndex( rule ); verify( cacheAccess, times( 1 ) ).removeSchemaRuleFromCache( command.getKey() ); }
private Command visitSchemaRuleCommand( ReadableChannel channel ) throws IOException { Collection<DynamicRecord> recordsBefore = new ArrayList<>(); readDynamicRecords( channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER ); Collection<DynamicRecord> recordsAfter = new ArrayList<>(); readDynamicRecords( channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER ); byte isCreated = channel.get(); if ( 1 == isCreated ) { for ( DynamicRecord record : recordsAfter ) { record.setCreated(); } } SchemaRule rule = Iterables.first( recordsAfter ).inUse() ? readSchemaRule( recordsAfter ) : readSchemaRule( recordsBefore ); return new Command.SchemaRuleCommand( recordsBefore, recordsAfter, rule ); }
@Test public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplierFacade( newIndexApplier(), newApplier( false ) ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final StoreIndexDescriptor rule = constraintIndexRule( 0, 1, 2, new IndexProviderDescriptor( "K", "X.Y" ), 42L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( indexingService, times( 1 ) ).activateIndex( rule.getId() ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyCreateIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplierFacade( newIndexApplier(), newApplier( true ) ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setCreated(); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final StoreIndexDescriptor rule = indexRule( 0, 1, 2, new IndexProviderDescriptor( "K", "X.Y" ) ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( indexingService, times( 1 ) ).createIndexes( rule ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyCreateUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setCreated(); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, times( 1 ) ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception { // given final BatchTransactionApplier applier = newApplierFacade( newIndexApplier(), newApplier( true ) ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final StoreIndexDescriptor rule = constraintIndexRule( 0, 1, 2, new IndexProviderDescriptor( "K", "X.Y" ), 42L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).setHighestPossibleIdInUse( record.getId() ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( indexingService, times( 1 ) ).activateIndex( rule.getId() ); verify( cacheAccess, times( 1 ) ).addSchemaRule( rule ); }
@Test public void shouldApplyDeleteUniquenessConstraintRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplier( false ); final DynamicRecord record = DynamicRecord.dynamicRecord( 21, true ); record.setInUse( false ); final Collection<DynamicRecord> recordsAfter = singletonList( record ); final ConstraintRule rule = uniquenessConstraintRule( 0L, 1, 2, 3L ); final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand( Collections.emptyList(), recordsAfter, rule ); // when boolean result = apply( applier, command::handle, transactionToApply ); // then assertFalse( result ); verify( schemaStore, times( 1 ) ).updateRecord( record ); verify( metaDataStore, never() ).setLatestConstraintIntroducingTx( transactionId ); verify( cacheAccess, times( 1 ) ).removeSchemaRuleFromCache( command.getKey() ); }
@Test public void shouldWriteSchemaRuleToLog() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, false, false); SchemaRecord afterRecords = serialize( rule, id, true, true); SchemaRuleCommand command = new SchemaRuleCommand( beforeRecords, afterRecords, rule ); InMemoryClosableChannel buffer = new InMemoryClosableChannel(); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN command.serialize( buffer ); Command readCommand = reader.read( buffer ); // THEN assertThat( readCommand, instanceOf( SchemaRuleCommand.class ) ); assertSchemaRule( (SchemaRuleCommand)readCommand ); }
@Test public void shouldRecreateSchemaRuleWhenDeleteCommandReadFromDisk() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, true, true); SchemaRecord afterRecords = serialize( rule, id, false, false); SchemaRuleCommand command = new SchemaRuleCommand( beforeRecords, afterRecords, rule ); InMemoryClosableChannel buffer = new InMemoryClosableChannel(); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN command.serialize( buffer ); Command readCommand = reader.read( buffer ); // THEN assertThat( readCommand, instanceOf( SchemaRuleCommand.class ) ); assertSchemaRule( (SchemaRuleCommand)readCommand ); }
@Test public void shouldSetLatestConstraintRule() throws Exception { // Given SchemaRecord beforeRecords = serialize( rule, id, true, true); SchemaRecord afterRecords = serialize( rule, id, true, false); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); ConstraintRule schemaRule = ConstraintRule.constraintRule( id, ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKey ), 0 ); // WHEN visitSchemaRuleCommand( storeApplier, new SchemaRuleCommand( beforeRecords, afterRecords, schemaRule ) ); // THEN verify( schemaStore ).updateRecord( Iterables.first( afterRecords ) ); verify( metaDataStore ).setLatestConstraintIntroducingTx( txId ); }
@Test public void shouldWriteCreatedSchemaRuleToStore() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, false, false); SchemaRecord afterRecords = serialize( rule, id, true, true); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN visitSchemaRuleCommand( storeApplier, new SchemaRuleCommand( beforeRecords, afterRecords, rule ) ); // THEN verify( schemaStore ).updateRecord( Iterables.first( afterRecords ) ); }
@Test public void shouldDropSchemaRuleFromIndex() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, true, true); SchemaRecord afterRecords = serialize( rule, id, false, false); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN visitSchemaRuleCommand( indexApplier, new SchemaRuleCommand( beforeRecords, afterRecords, rule ) ); // THEN verify( indexes ).dropIndex( rule ); }
public static SchemaRuleCommand createIndexRule( IndexProviderDescriptor provider, long id, LabelSchemaDescriptor descriptor ) { SchemaRule rule = IndexDescriptorFactory.forSchema( descriptor, provider ).withId( id ); DynamicRecord record = new DynamicRecord( id ); record.setInUse( true ); record.setCreated(); record.setData( SchemaRuleSerialization.serialize( rule ) ); return new SchemaRuleCommand( Collections.emptyList(), singletonList( record ), rule ); }
@Test public void shouldDropSchemaRuleFromStore() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, true, true); SchemaRecord afterRecords = serialize( rule, id, false, false); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN visitSchemaRuleCommand( storeApplier, new SchemaRuleCommand( beforeRecords, afterRecords, rule ) ); // THEN verify( schemaStore ).updateRecord( Iterables.first( afterRecords ) ); }
@Test public void shouldCreateIndexForCreatedSchemaRule() throws Exception { // GIVEN SchemaRecord beforeRecords = serialize( rule, id, false, false); SchemaRecord afterRecords = serialize( rule, id, true, true); when( neoStores.getSchemaStore() ).thenReturn( schemaStore ); // WHEN visitSchemaRuleCommand( indexApplier, new SchemaRuleCommand( beforeRecords, afterRecords, rule ) ); // THEN verify( indexes ).createIndexes( rule ); }