コード例 #1
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();
        }
コード例 #2
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();
        }
コード例 #3
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));
        }
コード例 #4
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."));
        }
コード例 #5
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();
        }
コード例 #6
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);
        }