private KernelTransactionImplementation CreateTransaction()
        {
            KernelTransactionImplementation transaction = mock(typeof(KernelTransactionImplementation));

            try
            {
                TransactionHeaderInformation        headerInformation        = new TransactionHeaderInformation(-1, -1, new sbyte[0]);
                TransactionHeaderInformationFactory headerInformationFactory = mock(typeof(TransactionHeaderInformationFactory));
                when(headerInformationFactory.Create()).thenReturn(headerInformation);
                StorageEngine storageEngine = mock(typeof(StorageEngine));
                StorageReader storageReader = mock(typeof(StorageReader));
                when(storageEngine.NewReader()).thenReturn(storageReader);

                SimpleStatementLocks locks = new SimpleStatementLocks(mock(typeof(Org.Neo4j.Kernel.impl.locking.Locks_Client)));
                when(transaction.StatementLocks()).thenReturn(locks);
                when(transaction.TokenRead()).thenReturn(_tokenRead);
                when(transaction.SchemaRead()).thenReturn(_schemaRead);
                when(transaction.SchemaWrite()).thenReturn(_schemaWrite);
                TransactionState transactionState = mock(typeof(TransactionState));
                when(transaction.TxState()).thenReturn(transactionState);
                when(transaction.IndexUniqueCreate(any(typeof(SchemaDescriptor)), any(typeof(string)))).thenAnswer(i => IndexDescriptorFactory.uniqueForSchema(i.getArgument(0)));
            }
            catch (InvalidTransactionTypeKernelException)
            {
                fail("Expected write transaction");
            }
            catch (SchemaKernelException e)
            {
                throw new Exception(e);
            }
            return(transaction);
        }
        public virtual KernelTransactionImplementation NewTransaction(long lastTransactionIdWhenStarted, LoginContext loginContext, Org.Neo4j.Kernel.impl.locking.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, Transaction_Type.@implicit, securityContext, transactionTimeout, 1L);
            return(tx);
        }
Exemple #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void initializeAndClose(KernelTransactionImplementation tx, int times) throws Exception
        private void InitializeAndClose(KernelTransactionImplementation tx, int times)
        {
            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();
            }
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncrementReuseCounterOnReuse() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncrementReuseCounterOnReuse()
        {
            // GIVEN
            KernelTransactionImplementation transaction = NewTransaction(LoginContext());
            int reuseCount = transaction.ReuseCount;

            // 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.ReuseCount);
        }
Exemple #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void markForTerminationWithCorrectReuseCount() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MarkForTerminationWithCorrectReuseCount()
        {
            int reuseCount = 10;

            Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction terminationReason = Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.Terminated;

            KernelTransactionImplementation tx = NewNotInitializedTransaction();

            InitializeAndClose(tx, reuseCount);

            Org.Neo4j.Kernel.impl.locking.Locks_Client locksClient = mock(typeof(Org.Neo4j.Kernel.impl.locking.Locks_Client));
            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.ReasonIfTerminated.get());
            verify(locksClient).stop();
        }
Exemple #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Test public void shouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUseStartTimeAndTxIdFromWhenStartingTxAsHeader()
        {
            // GIVEN a transaction starting at one point in time
            long startingTime = Clock.millis();
            ExplicitIndexTransactionState explicitIndexState = mock(typeof(ExplicitIndexTransactionState));

            AuxTxStateManager.registerProvider(new ExplicitIndexTransactionStateProviderAnonymousInnerClass(this, explicitIndexState));
            when(explicitIndexState.hasChanges()).thenReturn(true);
            doAnswer(invocation =>
            {
                ICollection <StorageCommand> commands = invocation.getArgument(0);
                commands.add(mock(typeof(Command)));
                return(null);
            }).when(StorageEngine).createCommands(any(typeof(System.Collections.ICollection)), any(typeof(TransactionState)), any(typeof(StorageReader)), any(typeof(ResourceLocker)), anyLong(), any(typeof(TxStateVisitor.Decorator)));

            using (KernelTransactionImplementation transaction = NewTransaction(LoginContext()))
            {
                SimpleStatementLocks statementLocks = new SimpleStatementLocks(mock(typeof(Org.Neo4j.Kernel.impl.locking.Locks_Client)));
                transaction.Initialize(5L, BASE_TX_COMMIT_TIMESTAMP, statementLocks, KernelTransaction.Type.@implicit, SecurityContext.AUTH_DISABLED, 0L, 1L);
                transaction.TxState();
                using (KernelStatement statement = transaction.AcquireStatement())
                {
                    statement.ExplicitIndexTxState();                              // which will pull it from the supplier and the mocking above
                    // will have it say that it has changes.
                }
                // WHEN committing it at a later point
                Clock.forward(5, MILLISECONDS);
                // ...and simulating some other transaction being committed
                when(MetaDataStore.LastCommittedTransactionId).thenReturn(7L);
                transaction.Success();
            }

            // THEN start time and last tx when started should have been taken from when the transaction started
            assertEquals(5L, CommitProcess.transaction.LatestCommittedTxWhenStarted);
            assertEquals(startingTime, CommitProcess.transaction.TimeStarted);
            assertEquals(startingTime + 5, CommitProcess.transaction.TimeCommitted);
        }