use of org.apache.cassandra.service.CassandraDaemon in project cassandra by apache.
the class CommitLogFailurePolicyTest method testCommitFailurePolicy_ignore_afterStartup.
@Test
public void testCommitFailurePolicy_ignore_afterStartup() throws Exception {
CassandraDaemon daemon = new CassandraDaemon();
//startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
daemon.completeSetup();
StorageService.instance.registerDaemon(daemon);
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try {
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.ignore);
CommitLog.handleCommitError("Testing ignore policy", new Throwable());
//error policy is set to IGNORE, so JVM must not be killed if error ocurs after startup
Assert.assertFalse(killerForTests.wasKilled());
} finally {
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
use of org.apache.cassandra.service.CassandraDaemon in project cassandra by apache.
the class CommitLogFailurePolicyTest method testCommitFailurePolicy_stop.
@Test
public void testCommitFailurePolicy_stop() throws ConfigurationException {
CassandraDaemon daemon = new CassandraDaemon();
//startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
daemon.completeSetup();
StorageService.instance.registerDaemon(daemon);
// Need storage service active so stop policy can shutdown gossip
StorageService.instance.initServer();
Assert.assertTrue(Gossiper.instance.isEnabled());
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try {
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.stop);
CommitLog.handleCommitError("Test stop error", new Throwable());
Assert.assertFalse(Gossiper.instance.isEnabled());
} finally {
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
}
}
use of org.apache.cassandra.service.CassandraDaemon in project cassandra by apache.
the class CommitLogFailurePolicyTest method testCommitFailurePolicy_die.
@Test
public void testCommitFailurePolicy_die() {
CassandraDaemon daemon = new CassandraDaemon();
//startup must be completed, otherwise commit log failure must kill JVM regardless of failure policy
daemon.completeSetup();
StorageService.instance.registerDaemon(daemon);
KillerForTests killerForTests = new KillerForTests();
JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
Config.CommitFailurePolicy oldPolicy = DatabaseDescriptor.getCommitFailurePolicy();
try {
DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.die);
CommitLog.handleCommitError("Testing die policy", new Throwable());
Assert.assertTrue(killerForTests.wasKilled());
//only killed quietly on startup failure
Assert.assertFalse(killerForTests.wasKilledQuietly());
} finally {
DatabaseDescriptor.setCommitFailurePolicy(oldPolicy);
JVMStabilityInspector.replaceKiller(originalKiller);
}
}
use of org.apache.cassandra.service.CassandraDaemon in project presto by prestodb.
the class EmbeddedCassandra method start.
public static synchronized void start() throws Exception {
if (initialized) {
return;
}
log.info("Starting cassandra...");
System.setProperty("cassandra.config", "file:" + prepareCassandraYaml());
System.setProperty("cassandra-foreground", "true");
System.setProperty("cassandra.native.epoll.enabled", "false");
CassandraDaemon cassandraDaemon = new CassandraDaemon();
cassandraDaemon.activate();
Cluster cluster = Cluster.builder().withProtocolVersion(V3).withClusterName("TestCluster").addContactPointsWithPorts(ImmutableList.of(new InetSocketAddress(HOST, PORT))).build();
CassandraSession session = new NativeCassandraSession("EmbeddedCassandra", JsonCodec.listJsonCodec(ExtraColumnMetadata.class), cluster, new Duration(1, MINUTES));
try {
checkConnectivity(session);
} catch (RuntimeException e) {
cluster.close();
cassandraDaemon.deactivate();
throw e;
}
EmbeddedCassandra.session = session;
initialized = true;
}
Aggregations