use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.
the class AbstractDatabaseManager method startDatabase.
protected void startDatabase(NamedDatabaseId namedDatabaseId, DB context) {
try {
log.info("Starting '%s'.", namedDatabaseId);
Database database = context.database();
database.start();
} catch (Throwable t) {
throw new DatabaseManagementException(format("An error occurred! Unable to start `%s`.", namedDatabaseId), t);
}
}
use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.
the class AbstractDatabaseManager method stopDatabase.
protected void stopDatabase(NamedDatabaseId namedDatabaseId, DB context) {
try {
log.info("Stopping '%s'.", namedDatabaseId);
Database database = context.database();
database.stop();
log.info("Stopped '%s' successfully.", namedDatabaseId);
} catch (Throwable t) {
log.error("Error stopping '%s'.", namedDatabaseId);
throw new DatabaseManagementException(format("An error occurred! Unable to stop `%s`.", namedDatabaseId), t);
}
}
use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.
the class AbstractDatabaseManager method forEachDatabase.
private void forEachDatabase(BiConsumer<NamedDatabaseId, DB> consumer, boolean systemDatabaseLast, String operationName) {
var snapshot = systemDatabaseLast ? databasesSnapshot().descendingMap().entrySet() : databasesSnapshot().entrySet();
DatabaseManagementException dbmsExceptions = null;
for (var entry : snapshot) {
NamedDatabaseId namedDatabaseId = entry.getKey();
DB context = entry.getValue();
try {
consumer.accept(namedDatabaseId, context);
} catch (Throwable t) {
var dbmsException = new DatabaseManagementException(format("An error occurred! Unable to %s the database `%s`.", operationName, namedDatabaseId), t);
dbmsExceptions = Exceptions.chain(dbmsExceptions, dbmsException);
}
}
if (dbmsExceptions != null) {
throw dbmsExceptions;
}
}
use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.
the class DefaultDatabaseManagerTest method shouldThrowIfUpgradingNonExistingDatabase.
@Test
void shouldThrowIfUpgradingNonExistingDatabase() {
// Given
NamedDatabaseId namedDatabaseId = DatabaseIdFactory.from("foo", UUID.randomUUID());
GlobalModule mock = mock(GlobalModule.class, RETURNS_MOCKS);
DefaultDatabaseManager databaseManager = new DefaultDatabaseManager(mock, mock(AbstractEditionModule.class));
// Then
DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
assertThat(e).hasMessage("Database not found: " + namedDatabaseId);
}
use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.
the class DefaultDatabaseManagerUpgradeIT method upgradeDatabaseMustThrowOnFailure.
@Test
void upgradeDatabaseMustThrowOnFailure() {
// Given
RuntimeException expectedException = new RuntimeException("Dammit Leroy!");
useThrowingMigrationLogProvider(expectedException);
createDbms();
GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
DefaultDatabaseManager databaseManager = getDatabaseManager(db);
RecordStoreVersionCheck check = new RecordStoreVersionCheck(fs, getPageCache(db), databaseLayout, NullLogProvider.getInstance(), Config.defaults(), NULL);
assertFalse(db.isAvailable(100), "Expected database to have failed during startup because we don't allow upgrade.");
// When
NamedDatabaseId namedDatabaseId = db.databaseId();
DatabaseManagementException e = assertThrows(DatabaseManagementException.class, () -> databaseManager.upgradeDatabase(namedDatabaseId));
// Then
assertThat(e).hasMessage("Failed to upgrade " + namedDatabaseId);
assertThat(e).hasRootCause(expectedException);
assertFalse(db.isAvailable(100), "Expected database to be available after upgrade");
assertTrue(MigrationTestUtils.checkNeoStoreHasFormatVersion(check, StandardV3_4.RECORD_FORMATS), "Expected store not upgraded.");
}
Aggregations