use of org.apache.cassandra.distributed.api.ICoordinator in project cassandra by apache.
the class CountersTest method testUpdateCounter.
private static void testUpdateCounter(boolean droppedCompactStorage) throws Throwable {
try (Cluster cluster = Cluster.build(2).withConfig(c -> c.with(GOSSIP, NATIVE_PROTOCOL).set("drop_compact_storage_enabled", true)).start()) {
cluster.schemaChange("CREATE KEYSPACE k WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
String createTable = "CREATE TABLE k.t ( k int, c int, total counter, PRIMARY KEY (k, c))";
if (droppedCompactStorage) {
cluster.schemaChange(createTable + " WITH COMPACT STORAGE");
cluster.schemaChange("ALTER TABLE k.t DROP COMPACT STORAGE");
} else {
cluster.schemaChange(createTable);
}
ConsistencyLevel cl = ConsistencyLevel.ONE;
String select = "SELECT total FROM k.t WHERE k = 1 AND c = ?";
for (int i = 1; i <= cluster.size(); i++) {
ICoordinator coordinator = cluster.coordinator(i);
coordinator.execute("UPDATE k.t SET total = total + 1 WHERE k = 1 AND c = ?", cl, i);
assertRows(coordinator.execute(select, cl, i), row(1L));
coordinator.execute("UPDATE k.t SET total = total - 4 WHERE k = 1 AND c = ?", cl, i);
assertRows(coordinator.execute(select, cl, i), row(-3L));
}
}
}
Aggregations