Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRollbackOnClosingTerminatedButSuccessfulTransaction()
        public virtual void ShouldRollbackOnClosingTerminatedButSuccessfulTransaction()
        {
            // GIVEN
            KernelTransaction transaction = NewTransaction(LoginContext());

            TransactionInitializer.accept(transaction);
            transaction.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError);
            transaction.Success();
            assertEquals(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError, transaction.ReasonIfTerminated.get());

            try
            {
                // WHEN
                transaction.Close();
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(TransactionTerminatedException)));
            }

            // THEN
            verify(TransactionMonitor, times(1)).transactionFinished(false, IsWriteTx);
            verify(TransactionMonitor, times(1)).transactionTerminated(IsWriteTx);
            VerifyExtraInteractionWithTheMonitor(TransactionMonitor, IsWriteTx);
        }
Esempio n. 2
0
            /*
             * This is overly careful about always closing and nulling the transaction since
             * reset can cause ctx.currentTransaction to be null we store in local variable.
             */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void closeTransaction(MutableTransactionState ctx, boolean success) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException
            internal void CloseTransaction(MutableTransactionState ctx, bool success)
            {
                KernelTransaction tx = ctx.CurrentTransaction;

                ctx.CurrentTransaction = null;
                if (tx != null)
                {
                    try
                    {
                        if (success)
                        {
                            tx.Success();
                        }
                        else
                        {
                            tx.Failure();
                        }
                        if (tx.Open)
                        {
                            tx.Close();
                        }
                    }
                    finally
                    {
                        ctx.CurrentTransaction = null;
                    }
                }
            }
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 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());
        }
Esempio n. 4
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);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.NotInTransactionException.class) public void shouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNotInTransactionWhenTransactionClosedAndAccessingOperations()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            transaction.Success();
            transaction.Close();

            TransactionOperation.operate(transaction.DataRead(), transaction.DataWrite(), transaction.SchemaRead());
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.TransactionTerminatedException.class) public void shouldThrowOnTerminationInCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowOnTerminationInCommit()
        {
            KernelTransaction transaction = NewTransaction(LoginContext());

            TransactionInitializer.accept(transaction);
            transaction.Success();
            transaction.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError);

            transaction.Close();
        }
 private static void Close(KernelTransaction tx)
 {
     try
     {
         tx.Close();
     }
     catch (TransactionFailureException e)
     {
         throw new Exception(e);
     }
 }
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 shouldIgnoreTerminateAfterRollback() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIgnoreTerminateAfterRollback()
        {
            KernelTransaction transaction = NewTransaction(LoginContext());

            TransactionInitializer.accept(transaction);
            transaction.Close();
            transaction.MarkForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_General.UnknownError);

            // THEN
            verify(TransactionMonitor, times(1)).transactionFinished(false, IsWriteTx);
            VerifyExtraInteractionWithTheMonitor(TransactionMonitor, IsWriteTx);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.NotInTransactionException.class) public void shouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowNotInTransactionWhenTransactionClosedAndAttemptingOperations()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

            Read       read       = transaction.DataRead();
            Write      write      = transaction.DataWrite();
            SchemaRead schemaRead = transaction.SchemaRead();

            transaction.Success();
            transaction.Close();

            TransactionOperation.operate(read, write, schemaRead);
        }
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 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());
        }
Esempio n. 11
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);
        }
Esempio n. 12
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))));
        }
Esempio n. 13
0
 public virtual void Rollback()
 {
     try
     {
         KernelTransaction kernelTransactionBoundToThisThread = _bridge.getKernelTransactionBoundToThisThread(false);
         kernelTransactionBoundToThisThread.Failure();
         kernelTransactionBoundToThisThread.Close();
     }
     catch (TransactionFailureException e)
     {
         throw new Exception(e);
     }
     finally
     {
         _bridge.unbindTransactionFromCurrentThread();
     }
 }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowTerminatingFromADifferentThread() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowTerminatingFromADifferentThread()
        {
            // GIVEN
//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(1);
            DoubleLatch latch = new DoubleLatch(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.api.KernelTransaction transaction = newTransaction(loginContext());
            KernelTransaction transaction = NewTransaction(LoginContext());

            TransactionInitializer.accept(transaction);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?> terminationFuture = java.util.concurrent.Executors.newSingleThreadExecutor().submit(() ->
            Future <object> terminationFuture = Executors.newSingleThreadExecutor().submit(() =>
            {
                latch.WaitForAllToStart();
                transaction.MarkForTermination(Status.General.UnknownError);
                latch.Finish();
            });

            // WHEN
            transaction.Success();
            latch.StartAndWaitForAllToStartAndFinish();

            assertNull(terminationFuture.get(1, TimeUnit.MINUTES));

            try
            {
                transaction.Close();
                fail("Exception expected");
            }
            catch (Exception e)
            {
                assertThat(e, instanceOf(typeof(TransactionTerminatedException)));
            }

            // THEN
            verify(TransactionMonitor, times(1)).transactionFinished(false, IsWriteTx);
            verify(TransactionMonitor, times(1)).transactionTerminated(IsWriteTx);
            VerifyExtraInteractionWithTheMonitor(TransactionMonitor, IsWriteTx);
        }
Esempio n. 15
0
 public virtual void Commit()
 {
     try
     {
         KernelTransaction kernelTransactionBoundToThisThread = _bridge.getKernelTransactionBoundToThisThread(true);
         kernelTransactionBoundToThisThread.Success();
         kernelTransactionBoundToThisThread.Close();
     }
     catch (NotInTransactionException)
     {
         // if the transaction was already terminated there is nothing more to do
     }
     catch (TransactionFailureException e)
     {
         throw new Exception(e);
     }
     finally
     {
         _bridge.unbindTransactionFromCurrentThread();
     }
 }