Search in sources :

Example 11 with ICoordinator

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));
        }
    }
}
Also used : AssertUtils.assertRows(org.apache.cassandra.distributed.shared.AssertUtils.assertRows) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) AssertUtils.row(org.apache.cassandra.distributed.shared.AssertUtils.row) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) NATIVE_PROTOCOL(org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) Cluster(org.apache.cassandra.distributed.Cluster)

Aggregations

ICoordinator (org.apache.cassandra.distributed.api.ICoordinator)11 Cluster (org.apache.cassandra.distributed.Cluster)9 Test (org.junit.Test)8 Arrays (java.util.Arrays)4 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)4 IOException (java.io.IOException)3 AssertUtils.assertRows (org.apache.cassandra.distributed.shared.AssertUtils.assertRows)3 AssertUtils.row (org.apache.cassandra.distributed.shared.AssertUtils.row)3 Assert (org.junit.Assert)3 SimpleStatement (com.datastax.driver.core.SimpleStatement)2 List (java.util.List)2 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 QUORUM (org.apache.cassandra.distributed.api.ConsistencyLevel.QUORUM)2 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)2 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)2 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)2 AssertUtils.fail (org.apache.cassandra.distributed.shared.AssertUtils.fail)2 TestBaseImpl (org.apache.cassandra.distributed.test.TestBaseImpl)2 ResultSet (com.datastax.driver.core.ResultSet)1