@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 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 shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem() throws IndexNotFoundKernelException, IndexPopulationFailedKernelException, IndexActivationFailedKernelException { // given final BatchTransactionApplier applier = newIndexApplier( ); doThrow( new IndexNotFoundKernelException( "" ) ).when( indexingService ).activateIndex( anyLong() ); 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 try { apply( applier, command::handle, transactionToApply ); fail( "should have thrown" ); } catch ( Exception e ) { // then assertTrue( e.getCause() instanceof IndexNotFoundKernelException ); } }