@Override public StatementLocks newInstance() { if ( locks == null ) { throw new IllegalStateException( "Factory has not been initialized" ); } return new SimpleStatementLocks( locks.newClient() ); } }
public KernelTransactionImplementation newTransaction( long lastTransactionIdWhenStarted, LoginContext loginContext, Locks.Client locks, long transactionTimeout ) { KernelTransactionImplementation tx = newNotInitializedTransaction(); StatementLocks statementLocks = new SimpleStatementLocks( locks ); SecurityContext securityContext = loginContext.authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ); tx.initialize( lastTransactionIdWhenStarted, BASE_TX_COMMIT_TIMESTAMP,statementLocks, Type.implicit, securityContext, transactionTimeout, 1L ); return tx; }
when( storageEngine.newReader() ).thenReturn( storageReader ); SimpleStatementLocks locks = new SimpleStatementLocks( mock( org.neo4j.kernel.impl.locking.Locks.Client.class ) ); when( transaction.statementLocks() ).thenReturn( locks ); when( transaction.tokenRead() ).thenReturn( tokenRead );
when( transaction.statementLocks() ).thenReturn( new SimpleStatementLocks( locks ) ); when( transaction.dataWrite() ).thenReturn( write ); when( transaction.isOpen() ).thenReturn( true );
TestKernelTransaction initialize() { initialize( 42, 42, new SimpleStatementLocks( new NoOpClient() ), Type.implicit, AUTH_DISABLED, 0L, 1L ); monitor.reset(); return this; }
static Instances kernelTransactionWithInternals( LoginContext loginContext ) { TransactionHeaderInformation headerInformation = new TransactionHeaderInformation( -1, -1, new byte[0] ); TransactionHeaderInformationFactory headerInformationFactory = mock( TransactionHeaderInformationFactory.class ); when( headerInformationFactory.create() ).thenReturn( headerInformation ); StorageEngine storageEngine = mock( StorageEngine.class ); StorageReader storageReader = mock( StorageReader.class ); when( storageEngine.newReader() ).thenReturn( storageReader ); KernelTransactionImplementation transaction = new KernelTransactionImplementation( Config.defaults(), mock( StatementOperationParts.class ), mock( SchemaWriteGuard.class ), new TransactionHooks(), mock( ConstraintIndexCreator.class ), new Procedures(), headerInformationFactory, mock( TransactionRepresentationCommitProcess.class ), mock( TransactionMonitor.class ), mock( AuxiliaryTransactionStateManager.class ), mock( Pool.class ), Clocks.systemClock(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite(), AutoIndexing.UNSUPPORTED, mock( ExplicitIndexStore.class ), EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock( SchemaState.class ), mock( IndexingService.class ), mockedTokenHolders(), new Dependencies() ); StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() ); transaction.initialize( 0, 0, statementLocks, KernelTransaction.Type.implicit, loginContext.authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 1L ); return new Instances( transaction ); }
@Test public void markForTerminationWithIncorrectReuseCount() throws Exception { int reuseCount = 13; int nextReuseCount = reuseCount + 2; Status.Transaction terminationReason = Status.Transaction.Terminated; KernelTransactionImplementation tx = newNotInitializedTransaction( ); initializeAndClose( tx, reuseCount ); Locks.Client locksClient = mock( Locks.Client.class ); SimpleStatementLocks statementLocks = new SimpleStatementLocks( locksClient ); tx.initialize( 42, 42, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 0L ); assertFalse( tx.markForTermination( nextReuseCount, terminationReason ) ); assertFalse( tx.getReasonIfTerminated().isPresent() ); verify( locksClient, never() ).stop(); }
@Test public void markForTerminationWithCorrectReuseCount() throws Exception { int reuseCount = 10; Status.Transaction terminationReason = Status.Transaction.Terminated; KernelTransactionImplementation tx = newNotInitializedTransaction( ); initializeAndClose( tx, reuseCount ); Locks.Client locksClient = mock( Locks.Client.class ); SimpleStatementLocks statementLocks = new SimpleStatementLocks( locksClient ); tx.initialize( 42, 42, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 0L ); assertTrue( tx.markForTermination( reuseCount, terminationReason ) ); assertEquals( terminationReason, tx.getReasonIfTerminated().get() ); verify( locksClient ).stop(); }
private void initializeAndClose( KernelTransactionImplementation tx, int times ) throws Exception { for ( int i = 0; i < times; i++ ) { SimpleStatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() ); tx.initialize( i + 10, i + 10, statementLocks, KernelTransaction.Type.implicit, loginContext().authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 0L ); tx.close(); } }
SimpleStatementLocks statementLocks = new SimpleStatementLocks( mock( Locks.Client.class ) ); transaction.initialize( 5L, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.implicit, SecurityContext.AUTH_DISABLED, 0L, 1L );
@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 StatementLocks newInstance() { if ( locks == null ) { throw new IllegalStateException( "Factory has not been initialized" ); } return new SimpleStatementLocks( locks.newClient() ); } }