Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowWhenRestartedAfterTermination()
        public virtual void ShouldThrowWhenRestartedAfterTermination()
        {
            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.CommitAndRestartTx();
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(TransactionTerminatedException)));
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
        }