Exemple #1
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;
                    }
                }
            }
Exemple #2
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);
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRollbackAndThrowOnFailedAndSuccess()
        public virtual void ShouldRollbackAndThrowOnFailedAndSuccess()
        {
            // GIVEN
            bool exceptionReceived = false;

            try
            {
                using (KernelTransaction transaction = NewTransaction(LoginContext()))
                {
                    // WHEN
                    TransactionInitializer.accept(transaction);
                    transaction.Failure();
                    transaction.Success();
                }
            }
            catch (TransactionFailureException)
            {
                // Expected.
                exceptionReceived = true;
            }

            // THEN
            assertTrue(exceptionReceived);
            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 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());
        }
//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 shouldThrowTerminateExceptionWhenTransactionTerminated() throws org.neo4j.internal.kernel.api.exceptions.KernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowTerminateExceptionWhenTransactionTerminated()
        {
            KernelTransaction transaction = newTransaction(AnonymousContext.write());

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

            TransactionOperation.operate(transaction.DataRead(), transaction.DataWrite(), transaction.SchemaRead());
        }
Exemple #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();
        }
//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);
        }
Exemple #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreTerminateAfterCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIgnoreTerminateAfterCommit()
        {
            KernelTransaction transaction = NewTransaction(LoginContext());

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

            // THEN
            verify(TransactionMonitor, times(1)).transactionFinished(true, IsWriteTx);
            VerifyExtraInteractionWithTheMonitor(TransactionMonitor, IsWriteTx);
        }
Exemple #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCommitSuccessfulTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCommitSuccessfulTransaction()
        {
            // GIVEN
            using (KernelTransaction transaction = NewTransaction(LoginContext()))
            {
                // WHEN
                TransactionInitializer.accept(transaction);
                transaction.Success();
            }

            // THEN
            verify(TransactionMonitor, times(1)).transactionFinished(true, IsWriteTx);
            VerifyExtraInteractionWithTheMonitor(TransactionMonitor, IsWriteTx);
        }
Exemple #10
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);
        }
Exemple #11
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);
        }
Exemple #12
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();
     }
 }