Esempio n. 1
0
 internal SuspendedTransaction(TransactionHandleRegistry outerInstance, ActiveTransaction activeMarker, TransactionHandle transactionHandle)
 {
     this._outerInstance              = outerInstance;
     this.ActiveMarker                = activeMarker;
     this.TransactionHandle           = transactionHandle;
     this.LastActiveTimestampConflict = outerInstance.clock.millis();
 }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void expiryTimeShouldBeSetToCurrentTimePlusTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ExpiryTimeShouldBeSetToCurrentTimePlusTimeout()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FakeClock             clock       = Clocks.fakeClock();
            int timeoutLength = 123;

            TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
            TransactionHandle         handle   = mock(typeof(TransactionHandle));

            long id = registry.Begin(handle);

            // When
            long timesOutAt = registry.Release(id, handle);

            // Then
            assertThat(timesOutAt, equalTo(clock.Millis() + timeoutLength));

            // And when
            clock.Forward(1337, TimeUnit.MILLISECONDS);
            registry.Acquire(id);
            timesOutAt = registry.Release(id, handle);

            // Then
            assertThat(timesOutAt, equalTo(clock.Millis() + timeoutLength));
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void acquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AcquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess()
        {
            // Given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            long id = registry.Begin(handle);

            registry.Release(id, handle);
            registry.Acquire(id);

            // When
            try
            {
                registry.Acquire(id);
                fail("Should have thrown exception");
            }
            catch (InvalidConcurrentTransactionAccess)
            {
                // expected
            }

            // then
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.server.rest.transactional.error.InvalidTransactionId.class) public void gettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId() throws org.neo4j.server.rest.transactional.error.TransactionLifecycleException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void GettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FakeClock             clock       = Clocks.fakeClock();
            int timeoutLength = 123;

            TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);

            // When
            registry.Terminate(456);
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowSpecificExceptionOnConcurrentTransactionAccess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowSpecificExceptionOnConcurrentTransactionAccess()
        {
            // given
            TransactionRegistry registry = new TransactionHandleRegistry(mock(typeof(Clock)), 0, NullLogProvider.Instance);
            TransitionalPeriodTransactionMessContainer kernel           = mock(typeof(TransitionalPeriodTransactionMessContainer));
            GraphDatabaseQueryService queryService                      = mock(typeof(GraphDatabaseQueryService));
            TransitionalTxManagementKernelTransaction kernelTransaction = mock(typeof(TransitionalTxManagementKernelTransaction));

            when(kernel.NewTransaction(any(typeof(KernelTransaction.Type)), any(typeof(LoginContext)), anyLong())).thenReturn(kernelTransaction);
            TransactionFacade actions = new TransactionFacade(kernel, null, queryService, registry, NullLogProvider.Instance);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TransactionHandle transactionHandle = actions.newTransactionHandle(new DisgustingUriScheme(), true, org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED, -1);
            TransactionHandle transactionHandle = actions.NewTransactionHandle(new DisgustingUriScheme(), true, LoginContext.AUTH_DISABLED, -1);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch();
            DoubleLatch latch = new DoubleLatch();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StatementDeserializer statements = mock(StatementDeserializer.class);
            StatementDeserializer statements = mock(typeof(StatementDeserializer));

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            when(statements.HasNext()).thenAnswer(invocation =>
            {
                latch.StartAndWaitForAllToStartAndFinish();
                return(false);
            });

            (new Thread(() =>
            {
                // start and block until finish
                transactionHandle.Execute(statements, mock(typeof(ExecutionResultSerializer)), mock(typeof(HttpServletRequest)));
            })).Start();

            latch.WaitForAllToStart();

            try
            {
                // when
                actions.FindTransactionHandle(DisgustingUriScheme.ParseTxId(transactionHandle.Uri()));
                fail("should have thrown exception");
            }
            catch (InvalidConcurrentTransactionAccess)
            {
                // then we get here
            }
            finally
            {
                latch.Finish();
            }
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGenerateTransactionId()
        public virtual void ShouldGenerateTransactionId()
        {
            // given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            // when
            long id1 = registry.Begin(handle);
            long id2 = registry.Begin(handle);

            // then
            assertNotEquals(id1, id2);
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStoreSuspendedTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStoreSuspendedTransaction()
        {
            // Given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            long id = registry.Begin(handle);

            // When
            registry.Release(id, handle);
            TransactionHandle acquiredHandle = registry.Acquire(id);

            // Then
            assertSame(handle, acquiredHandle);
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideInterruptHandlerForActiveTransaction() throws org.neo4j.server.rest.transactional.error.TransactionLifecycleException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideInterruptHandlerForActiveTransaction()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FakeClock             clock       = Clocks.fakeClock();
            int timeoutLength = 123;

            TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
            TransactionHandle         handle   = mock(typeof(TransactionHandle));

            // Active Tx in Registry
            long id = registry.Begin(handle);

            // When
            registry.Terminate(id);

            // Then
            verify(handle, times(1)).terminate();
            verifyNoMoreInteractions(handle);
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void acquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AcquiringANonExistentTransactionShouldThrowErrorInvalidTransactionId()
        {
            // Given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);

            long madeUpTransactionId = 1337;

            // When
            try
            {
                registry.Acquire(madeUpTransactionId);
                fail("Should have thrown exception");
            }
            catch (InvalidTransactionId)
            {
                // expected
            }

            // then
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionsShouldBeEvictedWhenUnusedLongerThanTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TransactionsShouldBeEvictedWhenUnusedLongerThanTimeout()
        {
            // Given
            FakeClock                 clock       = Clocks.fakeClock();
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(clock, 0, logProvider);
            TransactionHandle         oldTx       = mock(typeof(TransactionHandle));
            TransactionHandle         newTx       = mock(typeof(TransactionHandle));
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            long txId1 = registry.Begin(handle);
            long txId2 = registry.Begin(handle);

            // And given one transaction was stored one minute ago, and another was stored just now
            registry.Release(txId1, oldTx);
            clock.Forward(1, TimeUnit.MINUTES);
            registry.Release(txId2, newTx);

            // When
            registry.RollbackSuspendedTransactionsIdleSince(clock.Millis() - 1000);

            // Then
            assertThat(registry.Acquire(txId2), equalTo(newTx));

            // And then the other should have been evicted
            try
            {
                registry.Acquire(txId1);
                fail("Should have thrown exception");
            }
            catch (InvalidTransactionId)
            {
                // ok
            }

            logProvider.AssertExactly(inLog(typeof(TransactionHandleRegistry)).info("Transaction with id 1 has been automatically rolled " + "back due to transaction timeout."));
        }