@Test
public void shouldOnlyCreateOneApplierPerProvider() throws Exception
{
MutableObjectIntMap<String> names = ObjectIntHashMap.newWithKeysValues( "first", 0, "second", 1 );
MutableObjectIntMap<String> keys = ObjectIntHashMap.newWithKeysValues( "key", 0 );
String applierName = "test-applier";
Commitment commitment = mock( Commitment.class );
when( commitment.hasExplicitIndexChanges() ).thenReturn( true );
IndexConfigStore config = newIndexConfigStore( names, applierName );
ExplicitIndexApplierLookup applierLookup = mock( ExplicitIndexApplierLookup.class );
TransactionApplier transactionApplier = mock( TransactionApplier.class );
when( applierLookup.newApplier( anyString(), anyBoolean() ) ).thenReturn( transactionApplier );
try ( ExplicitBatchIndexApplier applier = new ExplicitBatchIndexApplier( config, applierLookup, BYPASS, INTERNAL ) )
{
TransactionToApply tx = new TransactionToApply( null, 2 );
tx.commitment( commitment, 2 );
try ( TransactionApplier txApplier = applier.startTx( tx ) )
{
IndexDefineCommand definitions = definitions( names, keys );
txApplier.visitIndexDefineCommand( definitions );
txApplier.visitIndexAddNodeCommand( addNodeToIndex( definitions, "first" ) );
txApplier.visitIndexAddNodeCommand( addNodeToIndex( definitions, "second" ) );
txApplier.visitIndexAddRelationshipCommand( addRelationshipToIndex( definitions, "second" ) );
}
}
verify( applierLookup, times( 1 ) ).newApplier( eq( applierName ), anyBoolean() );
}