Search in sources :

Example 21 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionsTest method disposeAllMarksAllTransactionsForTermination.

@Test
public void disposeAllMarksAllTransactionsForTermination() throws Throwable {
    KernelTransactions kernelTransactions = newKernelTransactions();
    KernelTransaction tx1 = getKernelTransaction(kernelTransactions);
    KernelTransaction tx2 = getKernelTransaction(kernelTransactions);
    KernelTransaction tx3 = getKernelTransaction(kernelTransactions);
    kernelTransactions.disposeAll();
    assertEquals(Status.General.DatabaseUnavailable, tx1.getReasonIfTerminated().get());
    assertEquals(Status.General.DatabaseUnavailable, tx2.getReasonIfTerminated().get());
    assertEquals(Status.General.DatabaseUnavailable, tx3.getReasonIfTerminated().get());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 22 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionsTest method shouldIncludeRandomBytesInAdditionalHeader.

@Test
public void shouldIncludeRandomBytesInAdditionalHeader() throws Throwable {
    // Given
    TransactionRepresentation[] transactionRepresentation = new TransactionRepresentation[1];
    KernelTransactions registry = newKernelTransactions(newRememberingCommitProcess(transactionRepresentation));
    // When
    try (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
    byte[] additionalHeader = transactionRepresentation[0].additionalHeader();
    assertNotNull(additionalHeader);
    assertTrue(additionalHeader.length > 0);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) Test(org.junit.Test)

Example 23 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionsTest method shouldReuseClosedTransactionObjects.

@Test
public void shouldReuseClosedTransactionObjects() throws Throwable {
    // GIVEN
    KernelTransactions transactions = newKernelTransactions();
    KernelTransaction a = getKernelTransaction(transactions);
    // WHEN
    a.close();
    KernelTransaction b = getKernelTransaction(transactions);
    // THEN
    assertSame(a, b);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 24 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionsTest method transactionCloseRemovesTxFromActiveTransactions.

@Test
public void transactionCloseRemovesTxFromActiveTransactions() throws Throwable {
    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());
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 25 with KernelTransaction

use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.

the class KernelTransactionImplementationTest method shouldIgnoreTerminateAfterCommit.

@Test
public void shouldIgnoreTerminateAfterCommit() throws Exception {
    KernelTransaction transaction = newTransaction(securityContext());
    transactionInitializer.accept(transaction);
    transaction.success();
    transaction.close();
    transaction.markForTermination(Status.General.UnknownError);
    // THEN
    verify(transactionMonitor, times(1)).transactionFinished(true, isWriteTx);
    verifyExtraInteractionWithTheMonitor(transactionMonitor, isWriteTx);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)77 Test (org.junit.Test)37 Statement (org.neo4j.kernel.api.Statement)30 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)14 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)14 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 TopLevelTransaction (org.neo4j.kernel.impl.coreapi.TopLevelTransaction)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)7 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 QueryRegistryOperations (org.neo4j.kernel.api.QueryRegistryOperations)4 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)4 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)4 RemoteException (java.rmi.RemoteException)3 ExpectedException (org.junit.rules.ExpectedException)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)3 ShellException (org.neo4j.shell.ShellException)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2