### Question:
TransactionStateMachineV1SPI implements TransactionStateMachineSPI { @Override public void awaitUpToDate( long oldestAcceptableTxId ) throws TransactionFailureException { transactionIdTracker.awaitUpToDate( oldestAcceptableTxId, txAwaitDuration ); } TransactionStateMachineV1SPI( GraphDatabaseAPI db, BoltChannel boltChannel, Duration txAwaitDuration, Clock clock ); @Override void awaitUpToDate( long oldestAcceptableTxId ); @Override long newestEncounteredTxId(); @Override KernelTransaction beginTransaction( LoginContext loginContext, Duration txTimeout, Map<String,Object> txMetadata ); @Override void bindTransactionToCurrentThread( KernelTransaction tx ); @Override void unbindTransactionFromCurrentThread(); @Override boolean isPeriodicCommit( String query ); @Override BoltResultHandle executeQuery( LoginContext loginContext, String statement, MapValue params, Duration txTimeout,
            Map<String,Object> txMetadata );  }### Answer:
@Test public void throwsWhenTxAwaitDurationExpires() { long lastClosedTransactionId = 100; Supplier<TransactionIdStore> txIdStore = () -> fixedTxIdStore( lastClosedTransactionId ); Duration txAwaitDuration = Duration.ofSeconds( 42 ); FakeClock clock = new FakeClock(); DatabaseAvailabilityGuard databaseAvailabilityGuard = spy( new DatabaseAvailabilityGuard( DEFAULT_DATABASE_NAME, clock, NullLog.getInstance() ) ); when( databaseAvailabilityGuard.isAvailable() ).then( invocation -> { boolean available = (boolean) invocation.callRealMethod(); clock.forward( txAwaitDuration.getSeconds() + 1, SECONDS ); return available; } ); TransactionStateMachineV1SPI txSpi = createTxSpi( txIdStore, txAwaitDuration, databaseAvailabilityGuard, clock ); Future<Void> result = otherThread.execute( state -> { txSpi.awaitUpToDate( lastClosedTransactionId + 42 ); return null; } ); try { result.get( 20, SECONDS ); } catch ( Exception e ) { assertThat( e, instanceOf( ExecutionException.class ) ); assertThat( e.getCause(), instanceOf( TransactionFailureException.class ) ); } }
@Test public void doesNotWaitWhenTxIdUpToDate() throws Exception { long lastClosedTransactionId = 100; Supplier<TransactionIdStore> txIdStore = () -> fixedTxIdStore( lastClosedTransactionId ); TransactionStateMachineV1SPI txSpi = createTxSpi( txIdStore, Duration.ZERO, Clock.systemUTC() ); Future<Void> result = otherThread.execute( state -> { txSpi.awaitUpToDate( lastClosedTransactionId - 42 ); return null; } ); assertNull( result.get( 20, SECONDS ) ); }