Search in sources :

Example 46 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class JVMStabilityInspectorCorruptSSTableExceptionTest method test.

private static void test(DiskFailurePolicy policy, boolean expectNativeTransportRunning, boolean expectGossiperEnabled) throws Exception {
    String table = policy.name();
    try (final Cluster cluster = init(getCluster(policy).start())) {
        IInvokableInstance node = cluster.get(1);
        boolean[] setup = node.callOnInstance(() -> {
            CassandraDaemon instanceForTesting = CassandraDaemon.getInstanceForTesting();
            instanceForTesting.completeSetup();
            StorageService.instance.registerDaemon(instanceForTesting);
            return new boolean[] { StorageService.instance.isNativeTransportRunning(), Gossiper.instance.isEnabled() };
        });
        // make sure environment is setup propertly
        Assert.assertTrue("Native support is not running, test is not ready!", setup[0]);
        Assert.assertTrue("Gossiper is not running, test is not ready!", setup[1]);
        cluster.schemaChange("CREATE TABLE " + KEYSPACE + "." + table + " (id bigint PRIMARY KEY)");
        node.executeInternal("INSERT INTO " + KEYSPACE + "." + table + " (id) VALUES (?)", 0L);
        corruptTable(node, KEYSPACE, table);
        try {
            cluster.coordinator(1).execute("SELECT * FROM " + KEYSPACE + '.' + table + " WHERE id=?", ConsistencyLevel.ONE, 0L);
            Assert.fail("Select should fail as we corrupted SSTable on purpose.");
        } catch (final Exception ex) {
        // we expect that above query fails as we corrupted an sstable
        }
        waitForStop(!expectGossiperEnabled, node, new SerializableCallable<Boolean>() {

            public Boolean call() {
                return Gossiper.instance.isEnabled();
            }
        });
        waitForStop(!expectNativeTransportRunning, node, new SerializableCallable<Boolean>() {

            public Boolean call() {
                return StorageService.instance.isNativeTransportRunning();
            }
        });
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) IOException(java.io.IOException) CorruptSSTableException(org.apache.cassandra.io.sstable.CorruptSSTableException) CassandraDaemon(org.apache.cassandra.service.CassandraDaemon)

Example 47 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class NetstatsRepairStreamingTest method executeTest.

private void executeTest(boolean compressionEnabled) throws Exception {
    final ExecutorService executorService = Executors.newFixedThreadPool(1);
    try (final Cluster cluster = Cluster.build().withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(2, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL).set("stream_throughput_outbound", "122KiB/s").set("compaction_throughput", "1MiB/s").set("stream_entire_sstables", false)).start()) {
        final IInvokableInstance node1 = cluster.get(1);
        final IInvokableInstance node2 = cluster.get(2);
        createTable(cluster, 1, compressionEnabled);
        node1.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
        node2.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
        populateData(compressionEnabled);
        node1.flush("netstats_test");
        node2.flush("netstats_test");
        // change RF from 1 to 2 so we need to repair it, repairing will causes streaming shown in netstats
        changeReplicationFactor();
        final Future<NetstatResults> resultsFuture1 = executorService.submit(new NetstatsCallable(node1));
        node1.nodetoolResult("repair", "netstats_test").asserts().success();
        final NetstatResults results = resultsFuture1.get(1, MINUTES);
        results.assertSuccessful();
        NetstatsOutputParser.validate(NetstatsOutputParser.parse(results));
    }
}
Also used : Future(java.util.concurrent.Future) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) MINUTES(java.util.concurrent.TimeUnit.MINUTES) NetworkTopology(org.apache.cassandra.distributed.shared.NetworkTopology) ExecutorService(java.util.concurrent.ExecutorService) Executors(java.util.concurrent.Executors) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) ExecutorService(java.util.concurrent.ExecutorService) Cluster(org.apache.cassandra.distributed.Cluster)

Example 48 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class IPMembershipTest method sameIPFailWithoutReplace.

/**
 * Port of replace_address_test.py::fail_without_replace_test to jvm-dtest
 */
@Test
public void sameIPFailWithoutReplace() throws IOException {
    try (Cluster cluster = Cluster.build(3).withConfig(c -> c.with(Feature.GOSSIP, Feature.NATIVE_PROTOCOL).set(Constants.KEY_DTEST_API_STARTUP_FAILURE_AS_SHUTDOWN, false)).start()) {
        IInvokableInstance nodeToReplace = cluster.get(3);
        ToolRunner.invokeCassandraStress("write", "n=10000", "-schema", "replication(factor=3)", "-port", "native=9042").assertOnExitCode();
        for (boolean auto_bootstrap : Arrays.asList(true, false)) {
            stopUnchecked(nodeToReplace);
            getDirectories(nodeToReplace).forEach(FileUtils::deleteRecursive);
            nodeToReplace.config().set("auto_bootstrap", auto_bootstrap);
            Assertions.assertThatThrownBy(() -> nodeToReplace.startup()).hasMessage("A node with address /127.0.0.3:7012 already exists, cancelling join. Use cassandra.replace_address if you want to replace this node.");
        }
    }
}
Also used : Arrays(java.util.Arrays) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableSet(com.google.common.collect.ImmutableSet) ToolRunner(org.apache.cassandra.tools.ToolRunner) ClusterUtils(org.apache.cassandra.distributed.shared.ClusterUtils) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) ClusterUtils.stopUnchecked(org.apache.cassandra.distributed.shared.ClusterUtils.stopUnchecked) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) FileUtils(org.apache.cassandra.io.util.FileUtils) Assertions(org.assertj.core.api.Assertions) Cluster(org.apache.cassandra.distributed.Cluster) ClusterUtils.getDirectories(org.apache.cassandra.distributed.shared.ClusterUtils.getDirectories) Constants(org.apache.cassandra.distributed.Constants) ClusterUtils.assertRingIs(org.apache.cassandra.distributed.shared.ClusterUtils.assertRingIs) ClusterUtils.updateAddress(org.apache.cassandra.distributed.shared.ClusterUtils.updateAddress) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) FileUtils(org.apache.cassandra.io.util.FileUtils) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 49 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class FailingRepairTest method cleanupState.

@Before
public void cleanupState() {
    for (int i = 1; i <= CLUSTER.size(); i++) {
        IInvokableInstance inst = CLUSTER.get(i);
        if (inst.isShutdown())
            inst.startup();
        inst.runOnInstance(InstanceKiller::clear);
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) InstanceKiller(org.apache.cassandra.distributed.impl.InstanceKiller) Before(org.junit.Before)

Example 50 with IInvokableInstance

use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.

the class IncRepairAdminTest method repairAdminCancelHelper.

private void repairAdminCancelHelper(boolean coordinator, boolean force) throws IOException {
    try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start())) {
        boolean shouldFail = !coordinator && !force;
        cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (k INT PRIMARY KEY, v INT)");
        cluster.forEach(i -> {
            NodeToolResult res = i.nodetoolResult("repair_admin");
            res.asserts().stdoutContains("no sessions");
        });
        UUID uuid = makeFakeSession(cluster);
        awaitNodetoolRepairAdminContains(cluster, uuid, "REPAIRING", false);
        IInvokableInstance instance = cluster.get(coordinator ? 1 : 2);
        NodeToolResult res;
        if (force) {
            res = instance.nodetoolResult("repair_admin", "cancel", "--session", uuid.toString(), "--force");
        } else {
            res = instance.nodetoolResult("repair_admin", "cancel", "--session", uuid.toString());
        }
        if (shouldFail) {
            res.asserts().failure();
            // if nodetool repair_admin cancel fails, the session should still be repairing:
            awaitNodetoolRepairAdminContains(cluster, uuid, "REPAIRING", true);
        } else {
            res.asserts().success();
            awaitNodetoolRepairAdminContains(cluster, uuid, "FAILED", true);
        }
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult) UUID(java.util.UUID)

Aggregations

IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)55 Test (org.junit.Test)36 Cluster (org.apache.cassandra.distributed.Cluster)31 List (java.util.List)16 IOException (java.io.IOException)15 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)14 Feature (org.apache.cassandra.distributed.api.Feature)13 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)13 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)13 ICluster (org.apache.cassandra.distributed.api.ICluster)13 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)13 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)12 Session (com.datastax.driver.core.Session)11 Arrays (java.util.Arrays)11 Assertions (org.assertj.core.api.Assertions)10 Set (java.util.Set)9 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)9 Assert (org.junit.Assert)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)8 Map (java.util.Map)8