Search in sources :

Example 71 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class HAClusterStartupIT method createSomeData.

private static void createSomeData(GraphDatabaseService oldMaster) {
    try (Transaction tx = oldMaster.beginTx()) {
        oldMaster.createNode();
        tx.success();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction)

Example 72 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class ProcedureIT method shouldGiveHelpfulErrorOnExceptionMidStream.

@Test
public void shouldGiveHelpfulErrorOnExceptionMidStream() throws Throwable {
    // run in tx to avoid having to wait for tx rollback on shutdown
    try (Transaction ignore = db.beginTx()) {
        Result result = db.execute("CALL org.neo4j.procedure.throwsExceptionInStream");
        // Expect
        exception.expect(QueryExecutionException.class);
        exception.expectMessage("Failed to call procedure `org.neo4j.procedure.throwsExceptionInStream() :: (someVal :: INTEGER?)" + "`: " + "Kaboom");
        // When
        result.next();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 73 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class ProcedureIT method shouldGiveNiceErrorMessageOnWrongStaticType.

@Test
public void shouldGiveNiceErrorMessageOnWrongStaticType() throws Throwable {
    //Expect
    exception.expect(QueryExecutionException.class);
    exception.expectMessage("Type mismatch: expected Integer but was String (line 1, column 41 (offset: 40))");
    // When
    try (Transaction ignore = db.beginTx()) {
        //Make sure argument here is not auto parameterized away as that will drop all type information on the floor
        db.execute("CALL org.neo4j.procedure.simpleArgument('42')");
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 74 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningTransaction.

@Test
public void terminateLongRunningTransaction() {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    try (Transaction transaction = database.beginTx()) {
        fakeClock.forward(3, TimeUnit.SECONDS);
        transaction.success();
        database.createNode();
        fail("Transaction should be already terminated.");
    } catch (GuardTimeoutException e) {
        assertThat(e.getMessage(), startsWith("Transaction timeout."));
        assertEquals(e.status(), Status.Transaction.TransactionTimedOut);
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) Test(org.junit.Test)

Example 75 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningQueryTransaction.

@Test
public void terminateLongRunningQueryTransaction() {
    GraphDatabaseAPI database = startDatabaseWithTimeout();
    try (Transaction transaction = database.beginTx()) {
        fakeClock.forward(3, TimeUnit.SECONDS);
        transaction.success();
        database.execute("create (n)");
        fail("Transaction should be already terminated.");
    } catch (GuardTimeoutException e) {
        assertThat(e.getMessage(), startsWith("Transaction timeout."));
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) Test(org.junit.Test)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64