Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowWhenGettingTxAfterTermination()
        public virtual void ShouldThrowWhenGettingTxAfterTermination()
        {
            MutableObject <Status> terminationReason = new MutableObject <Status>();
            InternalTransaction    tx = mock(typeof(InternalTransaction));

            doAnswer(invocation =>
            {
                terminationReason.Value = Status.Transaction.Terminated;
                return(null);
            }).when(tx).terminate();
            when(tx.TerminationReason()).then(invocation => Optional.ofNullable(terminationReason.Value));

            Neo4jTransactionalContext context = NewContext(tx);

            context.Terminate();

            try
            {
                context.OrBeginNewIfClosed;
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(TransactionTerminatedException)));
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void accumulateExecutionStatisticOverCommitAndRestart()
        public virtual void AccumulateExecutionStatisticOverCommitAndRestart()
        {
            InternalTransaction initialTransaction = mock(typeof(InternalTransaction), new ReturnsDeepStubs());

            when(initialTransaction.TerminationReason()).thenReturn(null);
            Kernel kernel = mock(typeof(Kernel));
            Neo4jTransactionalContext transactionalContext = new Neo4jTransactionalContext(_queryService, _txBridge, null, initialTransaction, _initialStatement, null, kernel);

            _statistics.Faults = 2;
            _statistics.Hits   = 5;

            transactionalContext.CommitAndRestartTx();

            _statistics.Faults = 2;
            _statistics.Hits   = 5;

            transactionalContext.CommitAndRestartTx();

            _statistics.Faults = 2;
            _statistics.Hits   = 5;

            StatisticProvider statisticProvider = transactionalContext.KernelStatisticProvider();

            assertEquals("Expect to see accumulated number of page cache misses.", 6, statisticProvider.PageCacheMisses);
            assertEquals("Expected to see accumulated number of page cache hits.", 15, statisticProvider.PageCacheHits);
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeOpenAfterCreation()
        public virtual void ShouldBeOpenAfterCreation()
        {
            InternalTransaction tx = mock(typeof(InternalTransaction));

            Neo4jTransactionalContext context = NewContext(tx);

            assertTrue(context.Open);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBeTopLevelWithExplicitTx()
        public virtual void ShouldNotBeTopLevelWithExplicitTx()
        {
            InternalTransaction tx = mock(typeof(InternalTransaction));

            when(tx.TransactionType()).thenReturn(KernelTransaction.Type.@explicit);

            Neo4jTransactionalContext context = NewContext(tx);

            assertFalse(context.TopLevelTx);
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBePossibleToTerminateWithoutActiveTransaction()
        public virtual void ShouldBePossibleToTerminateWithoutActiveTransaction()
        {
            InternalTransaction       tx      = mock(typeof(InternalTransaction));
            Neo4jTransactionalContext context = NewContext(tx);

            context.Close(true);
            verify(tx).success();
            verify(tx).close();

            context.Terminate();
            verify(tx, never()).terminate();
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBePossibleToCloseMultipleTimes()
        public virtual void ShouldNotBePossibleToCloseMultipleTimes()
        {
            InternalTransaction       tx      = mock(typeof(InternalTransaction));
            Neo4jTransactionalContext context = NewContext(tx);

            context.Close(false);
            context.Close(true);
            context.Close(false);

            verify(tx).failure();
            verify(tx, never()).success();
            verify(tx).close();
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCloseTransactionDuringTermination()
        public virtual void ShouldNotCloseTransactionDuringTermination()
        {
            InternalTransaction tx = mock(typeof(InternalTransaction));

            when(tx.TransactionType()).thenReturn(KernelTransaction.Type.@implicit);

            Neo4jTransactionalContext context = NewContext(tx);

            context.Terminate();

            verify(tx).terminate();
            verify(tx, never()).close();
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void checkKernelStatementOnCheck()
        public virtual void CheckKernelStatementOnCheck()
        {
            InternalTransaction initialTransaction = mock(typeof(InternalTransaction), new ReturnsDeepStubs());
            Kernel kernel = mock(typeof(Kernel));
            ThreadToStatementContextBridge txBridge = mock(typeof(ThreadToStatementContextBridge));
            KernelTransaction kernelTransaction     = MockTransaction(_initialStatement);

            when(txBridge.GetKernelTransactionBoundToThisThread(true)).thenReturn(kernelTransaction);

            Neo4jTransactionalContext transactionalContext = new Neo4jTransactionalContext(null, txBridge, null, initialTransaction, _initialStatement, null, kernel);

            transactionalContext.Check();

            verify(kernelTransaction).assertOpen();
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBePossibleToCloseAfterTermination()
        public virtual void ShouldBePossibleToCloseAfterTermination()
        {
            InternalTransaction tx = mock(typeof(InternalTransaction));

            when(tx.TransactionType()).thenReturn(KernelTransaction.Type.@implicit);

            Neo4jTransactionalContext context = NewContext(tx);

            context.Terminate();

            verify(tx).terminate();
            verify(tx, never()).close();

            context.Close(false);
            verify(tx).failure();
            verify(tx).close();
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("ConstantConditions") @Test public void rollsBackNewlyCreatedTransactionIfTerminationDetectedOnCloseDuringPeriodicCommit()
        public virtual void RollsBackNewlyCreatedTransactionIfTerminationDetectedOnCloseDuringPeriodicCommit()
        {
            // Given
            InternalTransaction initialTransaction = mock(typeof(InternalTransaction), new ReturnsDeepStubs());

            KernelTransaction.Type transactionType = KernelTransaction.Type.@implicit;
            SecurityContext        securityContext = SecurityContext.AUTH_DISABLED;

            when(initialTransaction.TransactionType()).thenReturn(transactionType);
            when(initialTransaction.SecurityContext()).thenReturn(securityContext);
            when(initialTransaction.TerminationReason()).thenReturn(null);

            GraphDatabaseQueryService queryService              = mock(typeof(GraphDatabaseQueryService));
            Statement                      initialStatement     = mock(typeof(Statement));
            KernelTransaction              initialKTX           = MockTransaction(initialStatement);
            QueryRegistryOperations        initialQueryRegistry = mock(typeof(QueryRegistryOperations));
            ExecutingQuery                 executingQuery       = mock(typeof(ExecutingQuery));
            PropertyContainerLocker        locker   = new PropertyContainerLocker();
            ThreadToStatementContextBridge txBridge = mock(typeof(ThreadToStatementContextBridge));

            Statement           secondStatement   = mock(typeof(Statement));
            KernelTransaction   secondKTX         = MockTransaction(secondStatement);
            InternalTransaction secondTransaction = mock(typeof(InternalTransaction));

            when(secondTransaction.TerminationReason()).thenReturn(null);
            QueryRegistryOperations secondQueryRegistry = mock(typeof(QueryRegistryOperations));

            when(executingQuery.QueryText()).thenReturn("X");
            when(executingQuery.QueryParameters()).thenReturn(EMPTY_MAP);
            Mockito.doThrow(typeof(Exception)).when(initialTransaction).close();
            when(initialStatement.QueryRegistration()).thenReturn(initialQueryRegistry);
            when(queryService.BeginTransaction(transactionType, securityContext)).thenReturn(secondTransaction);
            when(txBridge.GetKernelTransactionBoundToThisThread(true)).thenReturn(initialKTX, initialKTX, secondKTX);
            when(txBridge.Get()).thenReturn(secondStatement);
            when(secondStatement.QueryRegistration()).thenReturn(secondQueryRegistry);

            Kernel kernel = mock(typeof(Kernel));
            Neo4jTransactionalContext context = new Neo4jTransactionalContext(queryService, txBridge, locker, initialTransaction, initialStatement, executingQuery, kernel);

            // When
            try
            {
                context.CommitAndRestartTx();
                throw new AssertionError("Expected RuntimeException to be thrown");
            }
            catch (Exception)
            {
                // Then
                object[] mocks = new object[] { txBridge, initialTransaction, initialQueryRegistry, initialKTX, secondQueryRegistry, secondKTX, secondTransaction };
                InOrder  order = Mockito.inOrder(mocks);

                // (0) Constructor
                order.verify(initialTransaction).transactionType();
                order.verify(initialTransaction).securityContext();
                order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
                order.verify(initialTransaction).terminationReason();                           // not terminated check

                // (1) Collect statistics
                order.verify(initialKTX).executionStatistics();

                // (2) Unbind old
                order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
                order.verify(txBridge).unbindTransactionFromCurrentThread();

                // (3) Register and unbind new
                order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
                order.verify(secondKTX).acquireStatement();
                order.verify(secondQueryRegistry).registerExecutingQuery(executingQuery);
                order.verify(txBridge).unbindTransactionFromCurrentThread();

                // (4) Rebind, unregister, and close old
                order.verify(txBridge).bindTransactionToCurrentThread(initialKTX);
                order.verify(initialQueryRegistry).unregisterExecutingQuery(executingQuery);
                order.verify(initialTransaction).success();
                order.verify(initialTransaction).close();
                order.verify(txBridge).bindTransactionToCurrentThread(secondKTX);
                order.verify(secondTransaction).failure();
                order.verify(secondTransaction).close();
                order.verify(txBridge).unbindTransactionFromCurrentThread();

                verifyNoMoreInteractions(mocks);
            }
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("ConstantConditions") @Test public void neverStopsExecutingQueryDuringCommitAndRestartTx()
        public virtual void NeverStopsExecutingQueryDuringCommitAndRestartTx()
        {
            // Given
            KernelTransaction   initialKTX         = MockTransaction(_initialStatement);
            InternalTransaction initialTransaction = mock(typeof(InternalTransaction), new ReturnsDeepStubs());

            KernelTransaction.Type transactionType = KernelTransaction.Type.@implicit;
            SecurityContext        securityContext = SecurityContext.AUTH_DISABLED;

            when(initialTransaction.TransactionType()).thenReturn(transactionType);
            when(initialTransaction.SecurityContext()).thenReturn(securityContext);
            when(initialTransaction.TerminationReason()).thenReturn(null);
            QueryRegistryOperations        initialQueryRegistry = mock(typeof(QueryRegistryOperations));
            ExecutingQuery                 executingQuery       = mock(typeof(ExecutingQuery));
            PropertyContainerLocker        locker   = null;
            ThreadToStatementContextBridge txBridge = mock(typeof(ThreadToStatementContextBridge));

            Statement           secondStatement   = mock(typeof(Statement));
            KernelTransaction   secondKTX         = MockTransaction(secondStatement);
            InternalTransaction secondTransaction = mock(typeof(InternalTransaction));

            when(secondTransaction.TerminationReason()).thenReturn(null);
            QueryRegistryOperations secondQueryRegistry = mock(typeof(QueryRegistryOperations));

            when(executingQuery.QueryText()).thenReturn("X");
            when(executingQuery.QueryParameters()).thenReturn(EMPTY_MAP);
            when(_initialStatement.queryRegistration()).thenReturn(initialQueryRegistry);
            when(_queryService.beginTransaction(transactionType, securityContext)).thenReturn(secondTransaction);
            when(txBridge.GetKernelTransactionBoundToThisThread(true)).thenReturn(initialKTX, initialKTX, secondKTX);
            when(secondStatement.QueryRegistration()).thenReturn(secondQueryRegistry);

            Kernel kernel = mock(typeof(Kernel));
            Neo4jTransactionalContext context = new Neo4jTransactionalContext(_queryService, txBridge, locker, initialTransaction, _initialStatement, executingQuery, kernel);

            // When
            context.CommitAndRestartTx();

            // Then
            object[] mocks = new object[] { txBridge, initialTransaction, initialKTX, initialQueryRegistry, secondQueryRegistry, secondKTX };
            InOrder  order = Mockito.inOrder(mocks);

            // (0) Constructor
            order.verify(initialTransaction).transactionType();
            order.verify(initialTransaction).securityContext();
            order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
            order.verify(initialTransaction).terminationReason();                 // not terminated check

            // (1) Collect stats
            order.verify(initialKTX).executionStatistics();

            // (2) Unbind old
            order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
            order.verify(txBridge).unbindTransactionFromCurrentThread();

            // (3) Register and unbind new
            order.verify(txBridge).getKernelTransactionBoundToThisThread(true);
            order.verify(secondKTX).acquireStatement();
            order.verify(secondQueryRegistry).registerExecutingQuery(executingQuery);
            order.verify(txBridge).unbindTransactionFromCurrentThread();

            // (4) Rebind, unregister, and close old
            order.verify(txBridge).bindTransactionToCurrentThread(initialKTX);
            order.verify(initialQueryRegistry).unregisterExecutingQuery(executingQuery);
            order.verify(initialTransaction).success();
            order.verify(initialTransaction).close();
            order.verify(txBridge).unbindTransactionFromCurrentThread();

            // (5) Rebind new
            order.verify(txBridge).bindTransactionToCurrentThread(secondKTX);
            verifyNoMoreInteractions(mocks);
        }
Exemplo n.º 12
0
 internal TransactionalContextStatisticProvider(Neo4jTransactionalContext outerInstance, ExecutionStatistics executionStatistics)
 {
     this._outerInstance      = outerInstance;
     this.ExecutionStatistics = executionStatistics;
 }