コード例 #1
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);
            }
        }
コード例 #2
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);
        }