Search in sources :

Example 1 with GuardTimeoutException

use of org.neo4j.kernel.guard.GuardTimeoutException 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 2 with GuardTimeoutException

use of org.neo4j.kernel.guard.GuardTimeoutException 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)

Example 3 with GuardTimeoutException

use of org.neo4j.kernel.guard.GuardTimeoutException in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningQueryWithCustomTimeoutWithoutConfiguredDefault.

@Test
public void terminateLongRunningQueryWithCustomTimeoutWithoutConfiguredDefault() {
    GraphDatabaseAPI database = startDatabaseWithoutTimeout();
    try (Transaction transaction = database.beginTx(5, TimeUnit.SECONDS)) {
        fakeClock.forward(4, TimeUnit.SECONDS);
        database.execute("create (n)");
        transaction.failure();
    }
    try (Transaction transaction = database.beginTx(6, TimeUnit.SECONDS)) {
        fakeClock.forward(7, 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)

Example 4 with GuardTimeoutException

use of org.neo4j.kernel.guard.GuardTimeoutException in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateLongRunningTransactionWithPeriodicCommit.

@Test
public void terminateLongRunningTransactionWithPeriodicCommit() throws Exception {
    GraphDatabaseAPI database = startDatabaseWithTimeoutCustomGuard();
    try {
        URL url = prepareTestImportFile(8);
        database.execute("USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();");
        fail("Transaction should be already terminated.");
    } catch (GuardTimeoutException ignored) {
    }
    assertDatabaseDoesNotHaveNodes(database);
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GuardTimeoutException(org.neo4j.kernel.guard.GuardTimeoutException) URL(java.net.URL) Test(org.junit.Test)

Example 5 with GuardTimeoutException

use of org.neo4j.kernel.guard.GuardTimeoutException in project neo4j by neo4j.

the class TransactionGuardIntegrationTest method terminateTransactionWithCustomTimeoutWithoutConfiguredDefault.

@Test
public void terminateTransactionWithCustomTimeoutWithoutConfiguredDefault() {
    GraphDatabaseAPI database = startDatabaseWithoutTimeout();
    try (Transaction transaction = database.beginTx(27, TimeUnit.SECONDS)) {
        fakeClock.forward(26, TimeUnit.SECONDS);
        database.createNode();
        transaction.failure();
    }
    try (Transaction transaction = database.beginTx(27, TimeUnit.SECONDS)) {
        fakeClock.forward(28, TimeUnit.SECONDS);
        database.createNode();
        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

Test (org.junit.Test)5 GuardTimeoutException (org.neo4j.kernel.guard.GuardTimeoutException)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 Transaction (org.neo4j.graphdb.Transaction)4 URL (java.net.URL)1