@Override public TransactionExecutionStatistic transactionStatistic() { if ( txReuseCount == tx.getReuseCount() ) { return new TransactionExecutionStatistic( tx, clock, startTime ); } else { return TransactionExecutionStatistic.NOT_AVAILABLE; } }
@Override public boolean isOpen() { return tx.isOpen() && txReuseCount == tx.getReuseCount(); }
private static KernelTransactionImplementation prepareTxMock( long userTxId, long startMillis, long timeoutMillis ) { KernelTransactionImplementation transaction = mock( KernelTransactionImplementation.class ); when( transaction.startTime() ).thenReturn( startMillis ); when( transaction.userTransactionId() ).thenReturn( userTxId ); when( transaction.getReuseCount() ).thenReturn( EXPECTED_REUSE_COUNT ); when( transaction.timeout() ).thenReturn( timeoutMillis ); when( transaction.markForTermination( EXPECTED_REUSE_COUNT, Status.Transaction.TransactionTimedOut ) ).thenReturn( true ); return transaction; } }
@Test public void markForTerminationCallsKernelTransactionImplementation() { int reuseCount = 42; Status.Transaction terminationReason = Status.Transaction.Terminated; KernelTransactionImplementation tx = mock( KernelTransactionImplementation.class ); when( tx.getReuseCount() ).thenReturn( reuseCount ); KernelTransactionImplementationHandle handle = new KernelTransactionImplementationHandle( tx, clock ); handle.markForTermination( terminationReason ); verify( tx ).markForTermination( reuseCount, terminationReason ); }
@Test public void transactionStatisticForReusedTransactionIsNotAvailable() { KernelTransactionImplementation tx = mock( KernelTransactionImplementation.class ); when( tx.isOpen() ).thenReturn( true ); when( tx.getReuseCount() ).thenReturn( 2 ).thenReturn( 3 ); KernelTransactionImplementationHandle handle = new KernelTransactionImplementationHandle( tx, clock ); assertSame( TransactionExecutionStatistic.NOT_AVAILABLE, handle.transactionStatistic() ); } }
@Test public void isOpenForReusedKernelTransactionImplementation() { int initialReuseCount = 42; int nextReuseCount = 4242; KernelTransactionImplementation tx = mock( KernelTransactionImplementation.class ); when( tx.isOpen() ).thenReturn( true ); when( tx.getReuseCount() ).thenReturn( initialReuseCount ).thenReturn( nextReuseCount ); KernelTransactionImplementationHandle handle = new KernelTransactionImplementationHandle( tx, clock ); assertFalse( handle.isOpen() ); }
@Test public void isOpenForUnchangedKernelTransactionImplementation() { int reuseCount = 42; KernelTransactionImplementation tx = mock( KernelTransactionImplementation.class ); when( tx.isOpen() ).thenReturn( true ); when( tx.getReuseCount() ).thenReturn( reuseCount ); KernelTransactionImplementationHandle handle = new KernelTransactionImplementationHandle( tx, clock ); assertTrue( handle.isOpen() ); }
@Test public void markForTerminationReturnsTrueWhenSuccessful() { KernelTransactionImplementation tx = mock( KernelTransactionImplementation.class ); when( tx.getReuseCount() ).thenReturn( 42 ); when( tx.markForTermination( anyLong(), any() ) ).thenReturn( true ); KernelTransactionImplementationHandle handle = new KernelTransactionImplementationHandle( tx, clock ); assertTrue( handle.markForTermination( Status.Transaction.Terminated ) ); }
@Test public void markForTerminationReturnsFalseWhenNotSuccessful() { KernelTransactionImplementation tx = mock( KernelTransactionImplementation.class ); when( tx.getReuseCount() ).thenReturn( 42 ); when( tx.markForTermination( anyLong(), any() ) ).thenReturn( false ); KernelTransactionImplementationHandle handle = new KernelTransactionImplementationHandle( tx, clock ); assertFalse( handle.markForTermination( Status.Transaction.Terminated ) ); }
KernelTransactionImplementationHandle( KernelTransactionImplementation tx, SystemNanoClock clock ) { this.txReuseCount = tx.getReuseCount(); this.lastTransactionIdWhenStarted = tx.lastTransactionIdWhenStarted(); this.lastTransactionTimestampWhenStarted = tx.lastTransactionTimestampWhenStarted(); this.startTime = tx.startTime(); this.timeoutMillis = tx.timeout(); this.subject = tx.subjectOrAnonymous(); this.terminationReason = tx.getReasonIfTerminated(); this.executingQueries = tx.executingQueries(); this.metaData = tx.getMetaData(); this.userTransactionId = tx.userTransactionId(); this.tx = tx; this.clock = clock; }
@Test public void shouldIncrementReuseCounterOnReuse() throws Exception { // GIVEN KernelTransactionImplementation transaction = newTransaction( loginContext() ); int reuseCount = transaction.getReuseCount(); // WHEN transaction.close(); SimpleStatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() ); transaction.initialize( 1, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 1L ); // THEN assertEquals( reuseCount + 1, transaction.getReuseCount() ); }
@Override public TransactionExecutionStatistic transactionStatistic() { if ( txReuseCount == tx.getReuseCount() ) { return new TransactionExecutionStatistic( tx, clock, startTime ); } else { return TransactionExecutionStatistic.NOT_AVAILABLE; } }
@Override public boolean isOpen() { return tx.isOpen() && txReuseCount == tx.getReuseCount(); }
KernelTransactionImplementationHandle( KernelTransactionImplementation tx, SystemNanoClock clock ) { this.txReuseCount = tx.getReuseCount(); this.lastTransactionIdWhenStarted = tx.lastTransactionIdWhenStarted(); this.lastTransactionTimestampWhenStarted = tx.lastTransactionTimestampWhenStarted(); this.startTime = tx.startTime(); this.timeoutMillis = tx.timeout(); this.subject = tx.subjectOrAnonymous(); this.terminationReason = tx.getReasonIfTerminated(); this.executingQueries = tx.executingQueries(); this.metaData = tx.getMetaData(); this.userTransactionId = tx.userTransactionId(); this.tx = tx; this.clock = clock; }