use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.
the class Neo4jErrorTest method shouldSetStatusToDatabaseUnavailableOnDatabaseShutdownException.
@Test
public void shouldSetStatusToDatabaseUnavailableOnDatabaseShutdownException() {
// Given
DatabaseShutdownException ex = new DatabaseShutdownException();
// When
Neo4jError error = Neo4jError.from(ex);
// Then
assertThat(error.status(), equalTo(Status.General.DatabaseUnavailable));
assertThat(error.cause(), equalTo(ex));
}
use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.
the class Cluster method leaderTx.
/**
* Perform a transaction against the leader of the core cluster, retrying as necessary.
*/
private CoreClusterMember leaderTx(BiConsumer<CoreGraphDatabase, Transaction> op, int timeout, TimeUnit timeUnit) throws Exception {
ThrowingSupplier<CoreClusterMember, Exception> supplier = () -> {
CoreClusterMember member = awaitLeader(timeout, timeUnit);
CoreGraphDatabase db = member.database();
if (db == null) {
throw new DatabaseShutdownException();
}
try (Transaction tx = db.beginTx()) {
op.accept(db, tx);
return member;
} catch (Throwable e) {
if (isTransientFailure(e)) {
// this is not the best, but it helps in debugging
System.err.println("Transient failure in leader transaction, trying again.");
e.printStackTrace();
return null;
} else {
throw e;
}
}
};
return awaitEx(supplier, notNull()::test, timeout, timeUnit);
}
use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.
the class WorkLoad method doWork.
@Override
protected void doWork() {
GraphDatabaseService db = dbRef.get();
try (Transaction tx = db.beginTx()) {
Node node = db.createNode(label);
for (int i = 1; i <= 8; i++) {
node.setProperty(prop(i), "let's add some data here so the transaction logs rotate more often...");
}
tx.success();
} catch (DatabaseShutdownException | TransactionFailureException e) {
// whatever let's go on with the workload
}
}
use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.
the class Cluster method dataOnMemberEventuallyLooksLike.
/**
* Waits for {@link #DEFAULT_TIMEOUT_MS} for the <code>memberThatChanges</code> to match the contents of
* <code>memberToLookLike</code>. After calling this method, changes both in <code>memberThatChanges</code> and
* <code>memberToLookLike</code> are picked up.
*/
public static void dataOnMemberEventuallyLooksLike(CoreClusterMember memberThatChanges, CoreClusterMember memberToLookLike) throws TimeoutException, InterruptedException {
await(() -> {
try {
// We recalculate the DbRepresentation of both source and target, so changes can be picked up
DbRepresentation representationToLookLike = DbRepresentation.of(memberToLookLike.database());
DbRepresentation representationThatChanges = DbRepresentation.of(memberThatChanges.database());
return representationToLookLike.equals(representationThatChanges);
} catch (DatabaseShutdownException e) {
/*
* This can happen if the database is still in the process of starting. Yes, the naming
* of the exception is unfortunate, since it is thrown when the database lifecycle is not
* in RUNNING state and therefore signals general unavailability (e.g still starting) and not
* necessarily a database that is shutting down.
*/
}
return false;
}, DEFAULT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
use of org.neo4j.graphdb.DatabaseShutdownException in project neo4j by neo4j.
the class TestNeo4jApiExceptions method shouldGiveNiceErrorWhenShutdownLegacy.
@Test
public void shouldGiveNiceErrorWhenShutdownLegacy() {
GraphDatabaseService graphDb = graph;
Node node = graphDb.createNode();
commit();
graphDb.shutdown();
try {
node.getRelationships();
fail("Did not get a nice exception");
} catch (DatabaseShutdownException e) {
// good
}
try {
graphDb.createNode();
fail("Create node did not produce expected error");
} catch (DatabaseShutdownException e) {
// good
}
}
Aggregations