use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.
the class NeoStoreDataSourceTest method shouldAlwaysShutdownLifeEvenWhenCheckPointingFails.
@Test
public void shouldAlwaysShutdownLifeEvenWhenCheckPointingFails() throws Exception {
// Given
File storeDir = dir.graphDbDir();
FileSystemAbstraction fs = this.fs.get();
PageCache pageCache = pageCacheRule.getPageCache(fs);
DatabaseHealth databaseHealth = mock(DatabaseHealth.class);
when(databaseHealth.isHealthy()).thenReturn(true);
IOException ex = new IOException("boom!");
doThrow(ex).when(databaseHealth).assertHealthy(// <- this is a trick to simulate a failure during checkpointing
IOException.class);
NeoStoreDataSource dataSource = dsRule.getDataSource(storeDir, fs, pageCache, emptyMap(), databaseHealth);
dataSource.start();
try {
// When
dataSource.stop();
fail("it should have thrown");
} catch (LifecycleException e) {
// Then
assertEquals(ex, e.getCause());
}
}
use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.
the class ServerStartupErrorsTest method shouldDescribeUpgradeFailureInAFriendlyWay.
@Test
public void shouldDescribeUpgradeFailureInAFriendlyWay() {
// given
AssertableLogProvider logging = new AssertableLogProvider();
LifecycleException error = new LifecycleException(new Object(), STARTING, STARTED, new RuntimeException("Error starting org.neo4j.kernel.ha.factory.EnterpriseFacadeFactory", new LifecycleException(new Object(), STARTING, STARTED, new LifecycleException(new Object(), STARTING, STARTED, new UpgradeNotAllowedByConfigurationException()))));
// when
translateToServerStartupError(error).describeTo(logging.getLog("console"));
// then
logging.assertExactly(inLog("console").error("Neo4j cannot be started, because the database files require upgrading and upgrades are " + "disabled in configuration. Please set '%s' to 'true' in your configuration file and try " + "again.", "dbms.allow_format_migration"));
}
use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed.
@Test
public void startTheDatabaseWithWrongVersionShouldFailWithUpgradeNotAllowed() throws Throwable {
// given
// create a store
File storeDir = testDirectory.graphDbDir();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
db.shutdown();
// mess up the version in the metadatastore
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong("bad"));
}
// when
try {
new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
fail("It should have failed.");
} catch (RuntimeException ex) {
// then
assertTrue(ex.getCause() instanceof LifecycleException);
assertTrue(ex.getCause().getCause() instanceof UpgradeNotAllowedByConfigurationException);
assertEquals("Failed to start Neo4j with an older data store version. To enable automatic upgrade, " + "please set configuration parameter \"dbms.allow_format_migration=true\"", ex.getCause().getCause().getMessage());
}
}
use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.
the class ArbiterBootstrapper method start.
@SafeVarargs
@Override
public final int start(File homeDir, Optional<File> configFile, Pair<String, String>... configOverrides) {
Config config = getConfig(configFile, configOverrides);
try {
DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
life.add(new FileSystemLifecycleAdapter(fileSystem));
life.add(new Neo4jJobScheduler());
new ClusterClientModule(life, new Dependencies(), new Monitors(), config, logService(fileSystem, config), new NotElectableElectionCredentialsProvider());
} catch (LifecycleException e) {
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "unchecked" }) Throwable cause = peel(e, Predicates.<Throwable>instanceOf(LifecycleException.class));
if (cause instanceof ChannelException) {
System.err.println("ERROR: " + cause.getMessage() + (cause.getCause() != null ? ", caused by:" + cause.getCause().getMessage() : ""));
} else {
System.err.println("ERROR: Unknown error");
throw e;
}
}
addShutdownHook();
life.start();
return 0;
}
use of org.neo4j.kernel.lifecycle.LifecycleException in project neo4j by neo4j.
the class DatabaseStartupTest method startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed.
@Test
public void startTheDatabaseWithWrongVersionShouldFailAlsoWhenUpgradeIsAllowed() throws Throwable {
// given
// create a store
File storeDir = testDirectory.graphDbDir();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
db.shutdown();
// mess up the version in the metadatastore
String badStoreVersion = "bad";
try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
MetaDataStore.setRecord(pageCache, new File(storeDir, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.STORE_VERSION, MetaDataStore.versionStringToLong(badStoreVersion));
}
// when
try {
new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.allow_store_upgrade, "true").newGraphDatabase();
fail("It should have failed.");
} catch (RuntimeException ex) {
// then
assertTrue(ex.getCause() instanceof LifecycleException);
assertTrue(ex.getCause().getCause() instanceof StoreUpgrader.UnexpectedUpgradingStoreVersionException);
}
}
Aggregations