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);
}
}
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));
}
}
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));
}
}
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.");
}
});
}
}
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);
}
}
Aggregations