Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCloseResultHandlesWhenConsumeFailsInExplicitTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldCloseResultHandlesWhenConsumeFailsInExplicitTransaction()
        {
            KernelTransaction            transaction     = NewTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            stateMachine.BeginTransaction(null);
            stateMachine.StreamResult(boltResult =>
            {
            });
            stateMachine.Run("SOME STATEMENT", null);

            assertNotNull(stateMachine.Ctx.currentResultHandle);
            assertNotNull(stateMachine.Ctx.currentResult);

            Exception e = assertThrows(typeof(Exception), () =>
            {
                stateMachine.StreamResult(boltResult =>
                {
                    throw new Exception("some error");
                });
            });

            assertEquals("some error", e.Message);

            assertNull(stateMachine.Ctx.currentResultHandle);
            assertNull(stateMachine.Ctx.currentResult);
            assertNotNull(stateMachine.Ctx.currentTransaction);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldResetInExplicitTransactionWhileStatementIsRunningWhenValidated() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldResetInExplicitTransactionWhileStatementIsRunningWhenValidated()
        {
            KernelTransaction            transaction     = NewTimedOutTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            // start an explicit transaction
            stateMachine.BeginTransaction(null);
            assertThat(stateMachine.StateConflict, @is(TransactionStateMachine.State.ExplicitTransaction));
            assertNotNull(stateMachine.Ctx.currentTransaction);

            stateMachine.Run("RETURN 1", null);

            // verify transaction, which is timed out
            stateMachine.ValidateTransaction();

            assertThat(stateMachine.StateConflict, @is(TransactionStateMachine.State.AutoCommit));
            assertNull(stateMachine.Ctx.currentTransaction);
            assertNull(stateMachine.Ctx.currentResult);
            assertNull(stateMachine.Ctx.currentResultHandle);

            verify(transaction, times(1)).ReasonIfTerminated;
            verify(transaction, times(1)).failure();
            verify(transaction, times(1)).close();
        }
 public BoltResultHandleV1(TransactionStateMachineV1SPI outerInstance, string statement, MapValue @params, TransactionalContext transactionalContext)
 {
     this._outerInstance       = outerInstance;
     this.Statement            = statement;
     this.Params               = @params;
     this.TransactionalContext = transactionalContext;
 }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static TransactionStateMachineV1SPI newTransactionStateMachineSPI(org.neo4j.kernel.api.KernelTransaction transaction, org.neo4j.bolt.runtime.BoltResultHandle resultHandle) throws org.neo4j.internal.kernel.api.exceptions.KernelException
        private static TransactionStateMachineV1SPI NewTransactionStateMachineSPI(KernelTransaction transaction, BoltResultHandle resultHandle)
        {
            TransactionStateMachineV1SPI stateMachineSPI = mock(typeof(TransactionStateMachineV1SPI));

            when(stateMachineSPI.BeginTransaction(any(), any(), any())).thenReturn(transaction);
            when(stateMachineSPI.ExecuteQuery(any(), anyString(), any(), any(), any())).thenReturn(resultHandle);

            return(stateMachineSPI);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotMarkForTerminationWhenNoTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotMarkForTerminationWhenNoTransaction()
        {
            KernelTransaction            transaction     = NewTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);

            TransactionStateMachine stateMachine = NewTransactionStateMachine(stateMachineSPI);

            stateMachine.MarkCurrentTransactionForTermination();
            verify(transaction, never()).markForTermination(any());
        }
Beispiel #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldUnbindTxAfterRun() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldUnbindTxAfterRun()
        {
            KernelTransaction            transaction     = NewTimedOutTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            stateMachine.Run("SOME STATEMENT", null);

            verify(stateMachineSPI, times(1)).unbindTransactionFromCurrentThread();
        }
Beispiel #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStartWithAutoCommitState()
        internal virtual void ShouldStartWithAutoCommitState()
        {
            TransactionStateMachineV1SPI stateMachineSPI = mock(typeof(TransactionStateMachineV1SPI));
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            assertThat(stateMachine.StateConflict, @is(TransactionStateMachine.State.AutoCommit));
            assertNull(stateMachine.Ctx.currentTransaction);
            assertNull(stateMachine.Ctx.currentResultHandle);
            assertNull(stateMachine.Ctx.currentResult);
        }
Beispiel #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldThrowDuringRunIfPendingTerminationNoticeExists() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldThrowDuringRunIfPendingTerminationNoticeExists()
        {
            KernelTransaction            transaction     = NewTimedOutTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            stateMachine.Ctx.pendingTerminationNotice = Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut;

            TransactionTerminatedException e = assertThrows(typeof(TransactionTerminatedException), () => stateMachine.Run("SOME STATEMENT", null));

            assertEquals(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut, e.Status());
        }
Beispiel #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldCloseResultAndTransactionHandlesWhenExecutionFails() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldCloseResultAndTransactionHandlesWhenExecutionFails()
        {
            KernelTransaction            transaction     = NewTransaction();
            BoltResultHandle             resultHandle    = NewResultHandle(new Exception("some error"));
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction, resultHandle);
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            Exception e = assertThrows(typeof(Exception), () => stateMachine.Run("SOME STATEMENT", null));

            assertEquals("some error", e.Message);

            assertNull(stateMachine.Ctx.currentResultHandle);
            assertNull(stateMachine.Ctx.currentResult);
            assertNull(stateMachine.Ctx.currentTransaction);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void doesNotWaitWhenTxIdUpToDate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DoesNotWaitWhenTxIdUpToDate()
        {
            long lastClosedTransactionId = 100;

            System.Func <TransactionIdStore> txIdStore = () => FixedTxIdStore(lastClosedTransactionId);

            TransactionStateMachineV1SPI txSpi = CreateTxSpi(txIdStore, Duration.ZERO, Clock.systemUTC());

            Future <Void> result = OtherThread.execute(state =>
            {
                txSpi.AwaitUpToDate(lastClosedTransactionId - 42);
                return(null);
            });

            assertNull(result.get(20, SECONDS));
        }
Beispiel #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDoNothingInAutoCommitTransactionUponInitialisationWhenValidated() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldDoNothingInAutoCommitTransactionUponInitialisationWhenValidated()
        {
            KernelTransaction            transaction     = NewTimedOutTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);
            TransactionStateMachine      stateMachine    = NewTransactionStateMachine(stateMachineSPI);

            // We're in auto-commit state
            assertThat(stateMachine.StateConflict, @is(TransactionStateMachine.State.AutoCommit));
            assertNull(stateMachine.Ctx.currentTransaction);

            // call validate transaction
            stateMachine.ValidateTransaction();

            assertThat(stateMachine.StateConflict, @is(TransactionStateMachine.State.AutoCommit));
            assertNull(stateMachine.Ctx.currentTransaction);

            verify(transaction, never()).ReasonIfTerminated;
            verify(transaction, never()).failure();
            verify(transaction, never()).close();
        }
Beispiel #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotOpenExplicitTransactionForPeriodicCommitQuery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotOpenExplicitTransactionForPeriodicCommitQuery()
        {
            KernelTransaction            transaction     = NewTransaction();
            TransactionStateMachineV1SPI stateMachineSPI = NewTransactionStateMachineSPI(transaction);

            when(stateMachineSPI.IsPeriodicCommit(_periodicCommitQuery)).thenReturn(true);

            TransactionStateMachine stateMachine = NewTransactionStateMachine(stateMachineSPI);

            stateMachine.Run(_periodicCommitQuery, EMPTY_MAP);

            // transaction was created only to stream back result of the periodic commit query
            assertEquals(transaction, stateMachine.Ctx.currentTransaction);

            InOrder inOrder = inOrder(stateMachineSPI);

            inOrder.verify(stateMachineSPI).isPeriodicCommit(_periodicCommitQuery);
            // periodic commit query was executed without starting an explicit transaction
            inOrder.verify(stateMachineSPI).executeQuery(any(typeof(LoginContext)), eq(_periodicCommitQuery), eq(EMPTY_MAP), any(), any());
            // explicit transaction was started only after query execution to stream the result
            inOrder.verify(stateMachineSPI).beginTransaction(any(typeof(LoginContext)), any(), any());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void throwsWhenTxAwaitDurationExpires()
        public virtual void ThrowsWhenTxAwaitDurationExpires()
        {
            long lastClosedTransactionId = 100;

            System.Func <TransactionIdStore> txIdStore = () => FixedTxIdStore(lastClosedTransactionId);
            Duration  txAwaitDuration = Duration.ofSeconds(42);
            FakeClock clock           = new FakeClock();

            DatabaseAvailabilityGuard databaseAvailabilityGuard = spy(new DatabaseAvailabilityGuard(DEFAULT_DATABASE_NAME, clock, NullLog.Instance));

            when(databaseAvailabilityGuard.Available).then(invocation =>
            {
                // move clock forward on the first availability check
                // this check is executed on every tx id polling iteration
                bool available = ( bool )invocation.callRealMethod();
                clock.Forward(txAwaitDuration.Seconds + 1, SECONDS);
                return(available);
            });

            TransactionStateMachineV1SPI txSpi = CreateTxSpi(txIdStore, txAwaitDuration, databaseAvailabilityGuard, clock);

            Future <Void> result = OtherThread.execute(state =>
            {
                txSpi.AwaitUpToDate(lastClosedTransactionId + 42);
                return(null);
            });

            try
            {
                result.get(20, SECONDS);
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(ExecutionException)));
                assertThat(e.InnerException, instanceOf(typeof(TransactionFailureException)));
            }
        }
Beispiel #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeEach void createMocks()
        internal virtual void CreateMocks()
        {
            _stateMachineSPI = mock(typeof(TransactionStateMachineV1SPI));
            _mutableState    = mock(typeof(TransactionStateMachine.MutableTransactionState));
            _stateMachine    = new TransactionStateMachine(_stateMachineSPI, AUTH_DISABLED, new FakeClock());
        }
Beispiel #15
0
 private static TransactionStateMachine NewTransactionStateMachine(TransactionStateMachineV1SPI stateMachineSPI)
 {
     return(new TransactionStateMachine(stateMachineSPI, AUTH_DISABLED, new FakeClock()));
 }