Search in sources :

Example 6 with CassandraDaemon

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);
    }
}
Also used : JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) KillerForTests(org.apache.cassandra.utils.KillerForTests) Config(org.apache.cassandra.config.Config) CassandraDaemon(org.apache.cassandra.service.CassandraDaemon) Test(org.junit.Test)

Example 7 with CassandraDaemon

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);
    }
}
Also used : Config(org.apache.cassandra.config.Config) CassandraDaemon(org.apache.cassandra.service.CassandraDaemon) Test(org.junit.Test)

Example 8 with CassandraDaemon

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);
    }
}
Also used : JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) KillerForTests(org.apache.cassandra.utils.KillerForTests) Config(org.apache.cassandra.config.Config) CassandraDaemon(org.apache.cassandra.service.CassandraDaemon) Test(org.junit.Test)

Example 9 with CassandraDaemon

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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Cluster(com.datastax.driver.core.Cluster) Duration(io.airlift.units.Duration) CassandraDaemon(org.apache.cassandra.service.CassandraDaemon)

Aggregations

CassandraDaemon (org.apache.cassandra.service.CassandraDaemon)9 Config (org.apache.cassandra.config.Config)4 Test (org.junit.Test)4 JVMStabilityInspector (org.apache.cassandra.utils.JVMStabilityInspector)3 KillerForTests (org.apache.cassandra.utils.KillerForTests)3 Cluster (com.datastax.driver.core.Cluster)1 Duration (io.airlift.units.Duration)1 InetSocketAddress (java.net.InetSocketAddress)1 Before (org.junit.Before)1