private BatchTransactionApplier newApplier( boolean recovery ) { BatchTransactionApplier applier = new NeoStoreBatchTransactionApplier( neoStores, cacheAccess, lockService ); if ( recovery ) { applier = newApplierFacade( new HighIdBatchTransactionApplier( neoStores ), applier, new CacheInvalidationBatchTransactionApplier( neoStores, cacheAccess ) ); } return applier; }
@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 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 shouldApplyCreateIndexRuleSchemaRuleCommandToTheStore() throws Exception { // given final BatchTransactionApplier applier = newApplierFacade( newApplier( false ), newIndexApplier() ); 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 ) ).updateRecord( record ); verify( indexingService, times( 1 ) ).createIndexes( rule ); verify( cacheAccess, times( 1 ) ).addSchemaRule( 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() ); }