Search in sources :

Example 1 with KernelTransaction

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

the class TestPlaceboTransaction method before.

@Before
public void before() throws Exception {
    ThreadToStatementContextBridge bridge = mock(ThreadToStatementContextBridge.class);
    when(bridge.get()).thenReturn(mock(Statement.class));
    kernelTransaction = spy(KernelTransaction.class);
    Statement statement = mock(Statement.class);
    readOps = mock(ReadOperations.class);
    when(statement.readOperations()).thenReturn(readOps);
    when(bridge.get()).thenReturn(statement);
    placeboTx = new PlaceboTransaction(() -> kernelTransaction, bridge);
    resource = mock(Node.class);
    when(resource.getId()).thenReturn(1L);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ReadOperations(org.neo4j.kernel.api.ReadOperations) PlaceboTransaction(org.neo4j.kernel.impl.coreapi.PlaceboTransaction) Statement(org.neo4j.kernel.api.Statement) Node(org.neo4j.graphdb.Node) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Before(org.junit.Before)

Example 2 with KernelTransaction

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

the class TopLevelTransactionTest method shouldThrowTransactionExceptionOnTransientKernelException.

@Test
public void shouldThrowTransactionExceptionOnTransientKernelException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new RuntimeException("Just a random failure")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (org.neo4j.graphdb.TransactionFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 3 with KernelTransaction

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

the class TopLevelTransactionTest method shouldLetThroughTransientFailureException.

@Test
public void shouldLetThroughTransientFailureException() throws Exception {
    // GIVEN
    KernelTransaction kernelTransaction = mock(KernelTransaction.class);
    when(kernelTransaction.isOpen()).thenReturn(true);
    doThrow(new TransientDatabaseFailureException("Just a random failure")).when(kernelTransaction).close();
    ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
    TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
    // WHEN
    transaction.success();
    try {
        transaction.close();
        fail("Should have failed");
    } catch (TransientFailureException e) {
    // THEN Good
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransientFailureException(org.neo4j.graphdb.TransientFailureException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) TransientDatabaseFailureException(org.neo4j.graphdb.TransientDatabaseFailureException) TopLevelTransaction(org.neo4j.kernel.impl.coreapi.TopLevelTransaction) Test(org.junit.Test)

Example 4 with KernelTransaction

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

the class GraphDatabaseShellServer method unbindAndRegisterTransaction.

public void unbindAndRegisterTransaction(Serializable clientId) throws ShellException {
    try {
        ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
        KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread(false);
        threadToStatementContextBridge.unbindTransactionFromCurrentThread();
        if (tx == null) {
            clients.remove(clientId);
        } else {
            clients.put(clientId, tx);
        }
    } catch (Exception e) {
        throw wrapException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

Example 5 with KernelTransaction

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

the class ClusterDiscoveryIT method getMembers.

@SuppressWarnings("unchecked")
private List<Map<String, Object>> getMembers(GraphDatabaseFacade db) throws TransactionFailureException, org.neo4j.kernel.api.exceptions.ProcedureException {
    KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
    try (Statement statement = transaction.acquireStatement()) {
        // when
        List<Object[]> currentMembers = asList(statement.procedureCallOperations().procedureCallRead(procedureName(GET_SERVERS_V1.fullyQualifiedProcedureName()), new Object[0]));
        return (List<Map<String, Object>>) currentMembers.get(0)[1];
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) List(java.util.List) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) Matchers.containsString(org.hamcrest.Matchers.containsString) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Aggregations

KernelTransaction (org.neo4j.kernel.api.KernelTransaction)581 Test (org.junit.jupiter.api.Test)349 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)74 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)66 Transaction (org.neo4j.graphdb.Transaction)64 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)62 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 Write (org.neo4j.internal.kernel.api.Write)51 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)47 TokenRead (org.neo4j.internal.kernel.api.TokenRead)42 ArrayList (java.util.ArrayList)37 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)35 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)34 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)33 Node (org.neo4j.graphdb.Node)31 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)30 MethodSource (org.junit.jupiter.params.provider.MethodSource)28 Read (org.neo4j.internal.kernel.api.Read)28 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)28 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)25