Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDisposeTransactionsWhenAsked() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDisposeTransactionsWhenAsked()
        {
            // Given
            KernelTransactions transactions = NewKernelTransactions();

            transactions.DisposeAll();

            KernelTransaction first    = GetKernelTransaction(transactions);
            KernelTransaction second   = GetKernelTransaction(transactions);
            KernelTransaction leftOpen = GetKernelTransaction(transactions);

            first.Close();
            second.Close();

            // When
            transactions.DisposeAll();

            // Then
            KernelTransaction postDispose = GetKernelTransaction(transactions);

            assertThat(postDispose, not(equalTo(first)));
            assertThat(postDispose, not(equalTo(second)));

            assertNotNull(leftOpen.ReasonIfTerminated);
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void unblockNewTransactionsFromWrongThreadThrows() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void UnblockNewTransactionsFromWrongThreadThrows()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            kernelTransactions.BlockNewTransactions();

            Future <KernelTransaction> txOpener = T2.execute(state => kernelTransactions.NewInstance(@explicit, AnonymousContext.write(), 0L));

            T2.get().waitUntilWaiting(location => location.isAt(typeof(KernelTransactions), "newInstance"));

            AssertNotDone(txOpener);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> wrongUnblocker = unblockTxsInSeparateThread(kernelTransactions);
            Future <object> wrongUnblocker = UnblockTxsInSeparateThread(kernelTransactions);

            try
            {
                wrongUnblocker.get();
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(ExecutionException)));
                assertThat(e.InnerException, instanceOf(typeof(System.InvalidOperationException)));
            }
            AssertNotDone(txOpener);

            kernelTransactions.UnblockNewTransactions();
            assertNotNull(txOpener.get());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @BeforeEach void setUp()
        internal virtual void SetUp()
        {
            _kernelTransactions = mock(typeof(KernelTransactions));
            _fakeClock          = Clocks.fakeClock();
            _logProvider        = new AssertableLogProvider();
            _logService         = new SimpleLogService(_logProvider, _logProvider);
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTellWhenTransactionsFromSnapshotHaveBeenClosed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTellWhenTransactionsFromSnapshotHaveBeenClosed()
        {
            // GIVEN
            KernelTransactions         transactions = NewKernelTransactions();
            KernelTransaction          a            = GetKernelTransaction(transactions);
            KernelTransaction          b            = GetKernelTransaction(transactions);
            KernelTransaction          c            = GetKernelTransaction(transactions);
            KernelTransactionsSnapshot snapshot     = transactions.Get();

            assertFalse(snapshot.AllClosed());

            // WHEN a gets closed
            a.Close();
            assertFalse(snapshot.AllClosed());

            // WHEN c gets closed and (test knowing too much) that instance getting reused in another transaction "d".
            c.Close();
            KernelTransaction d = GetKernelTransaction(transactions);

            assertFalse(snapshot.AllClosed());

            // WHEN b finally gets closed
            b.Close();
            assertTrue(snapshot.AllClosed());
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void startNewTransactionOnRestartedKErnelTransactions() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void StartNewTransactionOnRestartedKErnelTransactions()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            kernelTransactions.Stop();
            kernelTransactions.Start();
            assertNotNull("New transaction created by restarted kernel transactions component.", kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AUTH_DISABLED, 0L));
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exceptionWhenStartingNewTransactionOnShutdownInstance() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ExceptionWhenStartingNewTransactionOnShutdownInstance()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            _databaseAvailabilityGuard.shutdown();

            ExpectedException.expect(typeof(DatabaseShutdownException));
            kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AUTH_DISABLED, 0L);
        }
Exemplo n.º 7
0
		 public KernelImpl( KernelTransactions transactionFactory, TransactionHooks hooks, DatabaseHealth health, TransactionMonitor transactionMonitor, Procedures procedures, Config config )
		 {
			  this._transactions = transactionFactory;
			  this._hooks = hooks;
			  this._health = health;
			  this._transactionMonitor = transactionMonitor;
			  this._procedures = procedures;
			  this._config = config;
		 }
Exemplo n.º 8
0
 private static void StopKernelTransactions(KernelTransactions kernelTransactions)
 {
     try
     {
         kernelTransactions.Stop();
     }
     catch (Exception t)
     {
         throw new Exception(t);
     }
 }
Exemplo n.º 9
0
 private static void StartAndCloseTransaction(KernelTransactions kernelTransactions)
 {
     try
     {
         kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AUTH_DISABLED, 0L).close();
     }
     catch (TransactionFailureException e)
     {
         throw new Exception(e);
     }
 }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotLeakTransactionOnSecurityContextFreezeFailure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotLeakTransactionOnSecurityContextFreezeFailure()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();
            LoginContext       loginContext       = mock(typeof(LoginContext));

            when(loginContext.Authorize(any(), any())).thenThrow(new AuthorizationExpiredException("Freeze failed."));

            assertException(() => kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, loginContext, 0L), typeof(AuthorizationExpiredException), "Freeze failed.");

            assertThat("We should not have any transaction", kernelTransactions.ActiveTransactions(), @is(empty()));
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void exceptionWhenStartingNewTransactionOnStoppedKernelTransactions() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ExceptionWhenStartingNewTransactionOnStoppedKernelTransactions()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            T2.execute((OtherThreadExecutor.WorkerCommand <Void, Void>)state =>
            {
                StopKernelTransactions(kernelTransactions);
                return(null);
            }).get();

            ExpectedException.expect(typeof(System.InvalidOperationException));
            kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AUTH_DISABLED, 0L);
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReuseClosedTransactionObjects() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReuseClosedTransactionObjects()
        {
            // GIVEN
            KernelTransactions transactions = NewKernelTransactions();
            KernelTransaction  a            = GetKernelTransaction(transactions);

            // WHEN
            a.Close();
            KernelTransaction b = GetKernelTransaction(transactions);

            // THEN
            assertSame(a, b);
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionCloseRemovesTxFromActiveTransactions() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TransactionCloseRemovesTxFromActiveTransactions()
        {
            KernelTransactions kernelTransactions = NewTestKernelTransactions();

            KernelTransaction tx1 = GetKernelTransaction(kernelTransactions);
            KernelTransaction tx2 = GetKernelTransaction(kernelTransactions);
            KernelTransaction tx3 = GetKernelTransaction(kernelTransactions);

            tx1.Close();
            tx3.Close();

            assertEquals(asSet(NewHandle(tx2)), kernelTransactions.ActiveTransactions());
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void disposeAllMarksAllTransactionsForTermination() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DisposeAllMarksAllTransactionsForTermination()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            KernelTransaction tx1 = GetKernelTransaction(kernelTransactions);
            KernelTransaction tx2 = GetKernelTransaction(kernelTransactions);
            KernelTransaction tx3 = GetKernelTransaction(kernelTransactions);

            kernelTransactions.DisposeAll();

            assertEquals(Org.Neo4j.Kernel.Api.Exceptions.Status_General.DatabaseUnavailable, tx1.ReasonIfTerminated.get());
            assertEquals(Org.Neo4j.Kernel.Api.Exceptions.Status_General.DatabaseUnavailable, tx2.ReasonIfTerminated.get());
            assertEquals(Org.Neo4j.Kernel.Api.Exceptions.Status_General.DatabaseUnavailable, tx3.ReasonIfTerminated.get());
        }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldListActiveTransactions() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldListActiveTransactions()
        {
            // Given
            KernelTransactions transactions = NewTestKernelTransactions();

            // When
            KernelTransaction first  = GetKernelTransaction(transactions);
            KernelTransaction second = GetKernelTransaction(transactions);
            KernelTransaction third  = GetKernelTransaction(transactions);

            first.Close();

            // Then
            assertThat(transactions.ActiveTransactions(), equalTo(asSet(NewHandle(second), NewHandle(third))));
        }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void blockNewTransactions() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void BlockNewTransactions()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            kernelTransactions.BlockNewTransactions();

            Future <KernelTransaction> txOpener = T2.execute(state => kernelTransactions.NewInstance(@explicit, AnonymousContext.write(), 0L));

            T2.get().waitUntilWaiting(location => location.isAt(typeof(KernelTransactions), "newInstance"));

            AssertNotDone(txOpener);

            kernelTransactions.UnblockNewTransactions();
            assertNotNull(txOpener.get());
        }
Exemplo n.º 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void threadThatBlocksNewTxsCantStartNewTxs() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ThreadThatBlocksNewTxsCantStartNewTxs()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            kernelTransactions.BlockNewTransactions();
            try
            {
                kernelTransactions.NewInstance(KernelTransaction.Type.@implicit, AnonymousContext.write(), 0L);
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(System.InvalidOperationException)));
            }
        }
Exemplo n.º 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void incrementalUserTransactionId() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IncrementalUserTransactionId()
        {
            KernelTransactions kernelTransactions = NewKernelTransactions();

            using (KernelTransaction kernelTransaction = kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AnonymousContext.none(), 0L))
            {
                assertEquals(1, kernelTransactions.ActiveTransactions().GetEnumerator().next().UserTransactionId);
            }

            using (KernelTransaction kernelTransaction = kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AnonymousContext.none(), 0L))
            {
                assertEquals(2, kernelTransactions.ActiveTransactions().GetEnumerator().next().UserTransactionId);
            }

            using (KernelTransaction kernelTransaction = kernelTransactions.NewInstance(KernelTransaction.Type.@explicit, AnonymousContext.none(), 0L))
            {
                assertEquals(3, kernelTransactions.ActiveTransactions().GetEnumerator().next().UserTransactionId);
            }
        }
Exemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionClosesUnderlyingStoreReaderWhenDisposed() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TransactionClosesUnderlyingStoreReaderWhenDisposed()
        {
            StorageReader storeStatement1 = mock(typeof(StorageReader));
            StorageReader storeStatement2 = mock(typeof(StorageReader));
            StorageReader storeStatement3 = mock(typeof(StorageReader));

            KernelTransactions kernelTransactions = newKernelTransactions(mock(typeof(TransactionCommitProcess)), storeStatement1, storeStatement2, storeStatement3);

            // start and close 3 transactions from different threads
            StartAndCloseTransaction(kernelTransactions);
            Executors.newSingleThreadExecutor().submit(() => startAndCloseTransaction(kernelTransactions)).get();
            Executors.newSingleThreadExecutor().submit(() => startAndCloseTransaction(kernelTransactions)).get();

            kernelTransactions.DisposeAll();

            verify(storeStatement1).close();
            verify(storeStatement2).close();
            verify(storeStatement3).close();
        }
Exemplo n.º 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeRandomBytesInAdditionalHeader() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncludeRandomBytesInAdditionalHeader()
        {
            // Given
            TransactionRepresentation[] transactionRepresentation = new TransactionRepresentation[1];

            KernelTransactions registry = NewKernelTransactions(NewRememberingCommitProcess(transactionRepresentation));

            // When
            using (KernelTransaction transaction = GetKernelTransaction(registry))
            {
                // Just pick anything that can flag that changes have been made to this transaction
                (( KernelTransactionImplementation )transaction).TxState().nodeDoCreate(0);
                transaction.Success();
            }

            // Then
            sbyte[] additionalHeader = transactionRepresentation[0].AdditionalHeader();
            assertNotNull(additionalHeader);
            assertTrue(additionalHeader.Length > 0);
        }
Exemplo n.º 21
0
 internal KernelTransactionImplementationFactory(KernelTransactions outerInstance, ISet <KernelTransactionImplementation> transactions)
 {
     this._outerInstance = outerInstance;
     this.Transactions   = transactions;
 }
Exemplo n.º 22
0
 private static KernelTransaction GetKernelTransaction(KernelTransactions transactions)
 {
     return(transactions.NewInstance(KernelTransaction.Type.@implicit, AnonymousContext.none(), 0L));
 }
Exemplo n.º 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToSnapshotDuringHeavyLoad() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToSnapshotDuringHeavyLoad()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final KernelTransactions transactions = newKernelTransactions();
            KernelTransactions transactions = NewKernelTransactions();
            Race      race    = new Race();
            const int threads = 50;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean end = new AtomicBoolean();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicReferenceArray<KernelTransactionsSnapshot> snapshots = new java.util.concurrent.atomic.AtomicReferenceArray<>(threads);
            AtomicReferenceArray <KernelTransactionsSnapshot> snapshots = new AtomicReferenceArray <KernelTransactionsSnapshot>(threads);

            // Representing "transaction" threads
            for (int i = 0; i < threads; i++)
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int threadIndex = i;
                int threadIndex = i;
                race.AddContestant(() =>
                {
                    ThreadLocalRandom random = ThreadLocalRandom.current();
                    while (!end.get())
                    {
                        try
                        {
                            using (KernelTransaction transaction = GetKernelTransaction(transactions))
                            {
                                KernelTransactionsSnapshot snapshot = null;
                                try
                                {
                                    parkNanos(MILLISECONDS.toNanos(random.Next(3)));
                                    if (snapshots.get(threadIndex) == null)
                                    {
                                        requireNonNull(transactions, "transactions is null");
                                        snapshot = requireNonNull(transactions.Get(), "transactions.get() returned null");
                                        snapshots.set(threadIndex, snapshot);
                                        parkNanos(MILLISECONDS.toNanos(random.Next(3)));
                                    }
                                }
                                catch (Exception e)
                                {
                                    StringBuilder sb = (new StringBuilder("Gotcha!\n")).Append("threadIndex=").Append(threadIndex).Append('\n').Append("transaction=").Append(transaction).Append('\n').Append("snapshots=").Append(snapshots).Append('\n').Append("snapshot=").Append(snapshot).Append('\n').Append("end=").Append(end);
                                    throw new Exception(sb.ToString(), e);
                                }
                            }
                        }
                        catch (TransactionFailureException e)
                        {
                            throw new Exception(e);
                        }
                    }
                });
            }

            // Just checks snapshots
            race.AddContestant(() =>
            {
                ThreadLocalRandom random = ThreadLocalRandom.current();
                int snapshotsLeft        = 1_000;
                while (snapshotsLeft > 0)
                {
                    int threadIndex = random.Next(threads);
                    KernelTransactionsSnapshot snapshot = snapshots.get(threadIndex);
                    if (snapshot != null && snapshot.AllClosed())
                    {
                        snapshotsLeft--;
                        snapshots.set(threadIndex, null);
                    }
                }

                // End condition of this test can be described as:
                //   when 1000 snapshots have been seen as closed.
                // setting this boolean to true will have all other threads end as well so that race.go() will end
                end.set(true);
            });

            // WHEN
            race.Go();
        }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private static java.util.concurrent.Future<?> unblockTxsInSeparateThread(final KernelTransactions kernelTransactions)
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
        private static Future <object> UnblockTxsInSeparateThread(KernelTransactions kernelTransactions)
        {
            return(Executors.newSingleThreadExecutor().submit(kernelTransactions.unblockNewTransactions));
        }