Search in sources :

Example 11 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class FrozenUDTTest method testDivergentSchemas.

@Test
public void testDivergentSchemas() throws Throwable {
    try (Cluster cluster = init(Cluster.create(2))) {
        cluster.schemaChange("create type " + KEYSPACE + ".a (foo text)");
        cluster.schemaChange("create table " + KEYSPACE + ".x (id int, ck frozen<a>, i int, primary key (id, ck))");
        cluster.get(1).executeInternal("alter type " + KEYSPACE + ".a add bar text");
        cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (?, " + json(1, 1) + ", ? )", ConsistencyLevel.ALL, 1, 1);
        cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (?, " + json(1, 2) + ", ? )", ConsistencyLevel.ALL, 2, 2);
        cluster.get(2).flush(KEYSPACE);
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 12 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class FrozenUDTTest method testUpgradeSStables.

@Test
public void testUpgradeSStables() throws IOException {
    try (Cluster cluster = init(Cluster.build(1).start())) {
        cluster.schemaChange("create type " + KEYSPACE + ".a (foo text)");
        cluster.schemaChange("create table " + KEYSPACE + ".x (id int, ck frozen<a>, i int, primary key (id, ck))");
        cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (?, " + json(1) + ", ? )", ConsistencyLevel.ALL, 1, 1);
        assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = ? and ck = " + json(1), ConsistencyLevel.ALL, 1), row(1));
        cluster.forEach(i -> i.flush(KEYSPACE));
        assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = ? and ck = " + json(1), ConsistencyLevel.ALL, 1), row(1));
        cluster.schemaChange("alter type " + KEYSPACE + ".a add bar text");
        cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (?, " + json(2) + ", ? )", ConsistencyLevel.ALL, 2, 2);
        cluster.forEach(i -> i.flush(KEYSPACE));
        assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = ? and ck = " + json(2), ConsistencyLevel.ALL, 2), row(2));
        cluster.forEach(i -> i.runOnInstance(() -> {
            try {
                StorageService.instance.upgradeSSTables(KEYSPACE, false, "x");
            } catch (IOException | ExecutionException | InterruptedException e) {
                throw new RuntimeException(e);
            }
        }));
        cluster.forEach(i -> i.forceCompact(KEYSPACE, "x"));
        for (int i = 1; i < 3; i++) assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = ? and ck = " + json(i), ConsistencyLevel.ALL, i), row(i));
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 13 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class FrozenUDTTest method testAddAndUDTField.

@Test
public void testAddAndUDTField() throws IOException {
    try (Cluster cluster = init(Cluster.build(1).start())) {
        cluster.schemaChange("create type " + KEYSPACE + ".a (foo text)");
        cluster.schemaChange("create table " + KEYSPACE + ".x (id int, ck frozen<a>, i int, primary key (id, ck))");
        for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (?, " + json(i) + ", ? )", ConsistencyLevel.ALL, i, i);
        for (int i = 0; i < 10; i++) assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = ? and ck = " + json(i), ConsistencyLevel.ALL, i), row(i));
        cluster.schemaChange("alter type " + KEYSPACE + ".a add bar text");
        for (int i = 5; i < 15; i++) cluster.coordinator(1).execute("insert into " + KEYSPACE + ".x (id, ck, i) VALUES (?, " + json(i) + ", ? )", ConsistencyLevel.ALL, i, i);
        cluster.forEach(i -> i.flush(KEYSPACE));
        for (int i = 5; i < 15; i++) assertRows(cluster.coordinator(1).execute("select i from " + KEYSPACE + ".x WHERE id = ? and ck = " + json(i), ConsistencyLevel.ALL, i), row(i));
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 14 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class GossipTest method testPreventEnablingGossipDuringMove.

@Test
public void testPreventEnablingGossipDuringMove() throws Exception {
    try (Cluster cluster = builder().withNodes(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start()) {
        cluster.get(1).runOnInstance(() -> {
            StorageService.instance.stopGossiping();
            StorageService.instance.setMovingModeUnsafe();
            try {
                StorageService.instance.startGossiping();
                Assert.fail("startGossiping did not fail!");
            } catch (Exception ex) {
                Assert.assertSame(ex.getClass(), IllegalStateException.class);
                Assert.assertEquals(ex.getMessage(), "Unable to start gossip because the node is not in the normal state.");
            }
        });
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ByteBuddy(net.bytebuddy.ByteBuddy) ElementMatchers.takesArguments(net.bytebuddy.matcher.ElementMatchers.takesArguments) PendingRangeCalculatorService(org.apache.cassandra.service.PendingRangeCalculatorService) Gossiper(org.apache.cassandra.gms.Gossiper) ClusterUtils.runAndWaitForLogs(org.apache.cassandra.distributed.shared.ClusterUtils.runAndWaitForLogs) Token(org.apache.cassandra.dht.Token) StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) ClusterUtils.getLocalToken(org.apache.cassandra.distributed.shared.ClusterUtils.getLocalToken) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) ApplicationState(org.apache.cassandra.gms.ApplicationState) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) FBUtilities(org.apache.cassandra.utils.FBUtilities) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) java.util.concurrent(java.util.concurrent) org.apache.cassandra.distributed.api(org.apache.cassandra.distributed.api) Collection(java.util.Collection) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) LockSupport(java.util.concurrent.locks.LockSupport) Futures(com.google.common.util.concurrent.Futures) StreamPlan(org.apache.cassandra.streaming.StreamPlan) Closeable(java.io.Closeable) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 15 with Cluster

use of org.apache.cassandra.distributed.Cluster in project cassandra by apache.

the class GossipTest method gossipShutdownUpdatesTokenMetadata.

@Test
public void gossipShutdownUpdatesTokenMetadata() throws Exception {
    try (Cluster cluster = Cluster.build(3).withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK)).withInstanceInitializer(FailureHelper::installMoveFailure).start()) {
        init(cluster, 2);
        populate(cluster);
        IInvokableInstance node1 = cluster.get(1);
        IInvokableInstance node2 = cluster.get(2);
        IInvokableInstance node3 = cluster.get(3);
        // initiate a move for node2, which will not complete due to the
        // ByteBuddy interceptor we injected. Wait for the other two nodes
        // to mark node2 as moving before proceeding.
        long t2 = Long.parseLong(getLocalToken(node2));
        long t3 = Long.parseLong(getLocalToken(node3));
        long moveTo = t2 + ((t3 - t2) / 2);
        String logMsg = "Node " + node2.broadcastAddress() + " state moving, new token " + moveTo;
        runAndWaitForLogs(() -> node2.nodetoolResult("move", "--", Long.toString(moveTo)).asserts().failure(), logMsg, cluster);
        InetSocketAddress movingAddress = node2.broadcastAddress();
        // node1 & node3 should now consider some ranges pending for node2
        assertPendingRangesForPeer(true, movingAddress, cluster);
        // A controlled shutdown causes peers to replace the MOVING status to be with SHUTDOWN, but prior to
        // CASSANDRA-16796 this doesn't update TokenMetadata, so they maintain pending ranges for the down node
        // indefinitely, even after it has been removed from the ring.
        logMsg = "Marked " + node2.broadcastAddress() + " as shutdown";
        runAndWaitForLogs(() -> Futures.getUnchecked(node2.shutdown()), logMsg, node1, node3);
        // node1 & node3 should not consider any ranges as still pending for node2
        assertPendingRangesForPeer(false, movingAddress, cluster);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Aggregations

Cluster (org.apache.cassandra.distributed.Cluster)161 Test (org.junit.Test)151 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)37 Assert (org.junit.Assert)37 IOException (java.io.IOException)36 Feature (org.apache.cassandra.distributed.api.Feature)34 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)30 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)30 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)29 List (java.util.List)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 InetAddress (java.net.InetAddress)20 TokenSupplier (org.apache.cassandra.distributed.api.TokenSupplier)20 StorageService (org.apache.cassandra.service.StorageService)18 Arrays (java.util.Arrays)17 Collections (java.util.Collections)17 Assertions (org.assertj.core.api.Assertions)17 Map (java.util.Map)16 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)15 ICoordinator (org.apache.cassandra.distributed.api.ICoordinator)14