### Question:
TransactionBatchCommitter implements TransactionQueue.Applier { @Override public void apply( TransactionToApply first, TransactionToApply last ) throws Exception { if ( batchSizeExceedsSafeZone( first, last ) ) { kernelTransactions.blockNewTransactions(); try { markUnsafeTransactionsForTermination( first, last ); commit( first ); } finally { kernelTransactions.unblockNewTransactions(); } } else { markUnsafeTransactionsForTermination( first, last ); commit( first ); } } TransactionBatchCommitter( KernelTransactions kernelTransactions, long idReuseSafeZoneTime,
            TransactionCommitProcess commitProcess, Log log ); @Override void apply( TransactionToApply first, TransactionToApply last );  }### Answer:
@Test public void shouldNotBlockTransactionsForSmallBatch() throws Exception { long safeZone = 10; TransactionBatchCommitter committer = newBatchCommitter( safeZone ); TransactionChain chain = createTxChain( 3, 1, 1 ); committer.apply( chain.first, chain.last ); verify( kernelTransactions, never() ).blockNewTransactions(); verify( kernelTransactions, never() ).unblockNewTransactions(); }
@Test public void shouldBlockTransactionsForLargeBatch() throws Exception { long safeZone = 10; TransactionBatchCommitter committer = newBatchCommitter( safeZone ); TransactionChain chain = createTxChain( 100, 1, 10 ); committer.apply( chain.first, chain.last ); InOrder inOrder = inOrder( kernelTransactions ); inOrder.verify( kernelTransactions ).blockNewTransactions(); inOrder.verify( kernelTransactions ).unblockNewTransactions(); }
@Test public void shouldTerminateOutdatedTransactions() throws Exception { long safeZone = 10; int txCount = 3; long firstCommitTimestamp = 10; long commitTimestampInterval = 2; TransactionBatchCommitter committer = newBatchCommitter( safeZone ); TransactionChain chain = createTxChain( txCount, firstCommitTimestamp, commitTimestampInterval ); long timestampOutsideSafeZone = chain.last.transactionRepresentation().getLatestCommittedTxWhenStarted() - safeZone - 1; KernelTransaction txToTerminate = newKernelTransaction( timestampOutsideSafeZone ); KernelTransaction tx = newKernelTransaction( firstCommitTimestamp - 1 ); when( kernelTransactions.activeTransactions() ) .thenReturn( Iterators.asSet( newHandle( txToTerminate ), newHandle( tx ) ) ); committer.apply( chain.first, chain.last ); verify( txToTerminate ).markForTermination( Status.Transaction.Outdated ); verify( tx, never() ).markForTermination( any() ); logProvider.formattedMessageMatcher().assertContains( "Marking transaction for termination" ); logProvider.formattedMessageMatcher().assertContains( "lastCommittedTxId:" + (BASE_TX_ID + txCount - 1) ); }