Search in sources :

Example 71 with Cluster

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

the class GroupByTest method groupByWithDeletesAndSrpOnPartitions.

@Test
public void groupByWithDeletesAndSrpOnPartitions() throws Throwable {
    try (Cluster cluster = init(builder().withNodes(2).withConfig((cfg) -> cfg.set("user_defined_functions_enabled", "true")).start())) {
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck text, PRIMARY KEY (pk, ck))"));
        initFunctions(cluster);
        cluster.get(1).executeInternal(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (1, '1') USING TIMESTAMP 0"));
        cluster.get(1).executeInternal(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (2, '2') USING TIMESTAMP 0"));
        cluster.get(1).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=0 AND ck='0'"));
        cluster.get(2).executeInternal(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (0, '0') USING TIMESTAMP 0"));
        cluster.get(2).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=1 AND ck='1'"));
        cluster.get(2).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=2 AND ck='2'"));
        for (String limitClause : new String[] { "", "LIMIT 1", "LIMIT 10", "PER PARTITION LIMIT 1", "PER PARTITION LIMIT 10" }) {
            String query = withKeyspace("SELECT concat(ck) FROM %s.tbl GROUP BY pk " + limitClause);
            for (int i = 1; i <= 4; i++) {
                Iterator<Object[]> rows = cluster.coordinator(2).executeWithPaging(query, ConsistencyLevel.ALL, i);
                assertRows(Iterators.toArray(rows, Object[].class));
            }
        }
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 72 with Cluster

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

the class GroupByTest method groupByWithDeletesAndSrpOnRows.

@Test
public void groupByWithDeletesAndSrpOnRows() throws Throwable {
    try (Cluster cluster = init(builder().withNodes(2).withConfig((cfg) -> cfg.set("user_defined_functions_enabled", "true")).start())) {
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck text, PRIMARY KEY (pk, ck))"));
        initFunctions(cluster);
        cluster.get(1).executeInternal(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (0, '1') USING TIMESTAMP 0"));
        cluster.get(1).executeInternal(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (0, '2') USING TIMESTAMP 0"));
        cluster.get(1).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=0 AND ck='0'"));
        cluster.get(2).executeInternal(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (0, '0') USING TIMESTAMP 0"));
        cluster.get(2).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=0 AND ck='1'"));
        cluster.get(2).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=0 AND ck='2'"));
        for (String limitClause : new String[] { "", "LIMIT 1", "LIMIT 10", "PER PARTITION LIMIT 1", "PER PARTITION LIMIT 10" }) {
            String query = withKeyspace("SELECT concat(ck) FROM %s.tbl GROUP BY pk " + limitClause);
            for (int i = 1; i <= 4; i++) {
                Iterator<Object[]> rows = cluster.coordinator(2).executeWithPaging(query, ConsistencyLevel.ALL, i);
                assertRows(Iterators.toArray(rows, Object[].class));
            }
        }
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 73 with Cluster

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

the class GroupByTest method testGroupWithDeletesAndPaging.

@Test
public void testGroupWithDeletesAndPaging() throws Throwable {
    try (Cluster cluster = init(builder().withNodes(2).withConfig(cfg -> cfg.with(Feature.GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, PRIMARY KEY (pk, ck))"));
        ICoordinator coordinator = cluster.coordinator(1);
        coordinator.execute(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (0, 0)"), ConsistencyLevel.ALL);
        coordinator.execute(withKeyspace("INSERT INTO %s.tbl (pk, ck) VALUES (1, 1)"), ConsistencyLevel.ALL);
        cluster.get(1).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=0 AND ck=0"));
        cluster.get(2).executeInternal(withKeyspace("DELETE FROM %s.tbl WHERE pk=1 AND ck=1"));
        String query = withKeyspace("SELECT * FROM %s.tbl GROUP BY pk");
        Iterator<Object[]> rows = coordinator.executeWithPaging(query, ConsistencyLevel.ALL, 1);
        assertRows(Iterators.toArray(rows, Object[].class));
        try (com.datastax.driver.core.Cluster c = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
            Session session = c.connect()) {
            SimpleStatement stmt = new SimpleStatement(withKeyspace("select * from %s.tbl where pk = 1 group by pk"));
            stmt.setFetchSize(1);
            Iterator<Row> rs = session.execute(stmt).iterator();
            Assert.assertFalse(rs.hasNext());
        }
    }
}
Also used : ICoordinator(org.apache.cassandra.distributed.api.ICoordinator) SimpleStatement(com.datastax.driver.core.SimpleStatement) Cluster(org.apache.cassandra.distributed.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 74 with Cluster

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

the class InternodeEncryptionOptionsTest method optionalTlsConnectionAllowedWithKeystoreTest.

@Test
public void optionalTlsConnectionAllowedWithKeystoreTest() throws Throwable {
    try (Cluster cluster = builder().withNodes(1).withConfig(c -> {
        c.with(Feature.NETWORK);
        c.set("server_encryption_options", validKeystore);
    }).createWithoutStarting()) {
        InetAddress address = cluster.get(1).config().broadcastAddress().getAddress();
        int port = cluster.get(1).config().broadcastAddress().getPort();
        TlsConnection tlsConnection = new TlsConnection(address.getHostAddress(), port);
        tlsConnection.assertCannotConnect();
        cluster.startup();
        Assert.assertEquals("TLS connection should be possible with keystore by default", ConnectResult.NEGOTIATED, tlsConnection.connect());
    }
}
Also used : InetAddress(java.net.InetAddress) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Collections(java.util.Collections) Cluster(org.apache.cassandra.distributed.Cluster) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 75 with Cluster

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

the class InternodeEncryptionOptionsTest method tlsConnectionRejectedWhenUnencrypted.

@Test
public void tlsConnectionRejectedWhenUnencrypted() throws Throwable {
    try (Cluster cluster = builder().withNodes(1).withConfig(c -> {
        c.with(Feature.NETWORK);
        c.set("server_encryption_options", ImmutableMap.builder().putAll(validKeystore).put("internode_encryption", "none").put("optional", false).build());
    }).createWithoutStarting()) {
        InetAddress address = cluster.get(1).config().broadcastAddress().getAddress();
        int regular_port = (int) cluster.get(1).config().get("storage_port");
        // Create the connections and prove they cannot connect before server start
        TlsConnection connection = new TlsConnection(address.getHostAddress(), regular_port);
        connection.assertCannotConnect();
        cluster.startup();
        Assert.assertEquals("TLS native connection should be possible with valid keystore by default", ConnectResult.FAILED_TO_NEGOTIATE, connection.connect());
    }
}
Also used : InetAddress(java.net.InetAddress) Feature(org.apache.cassandra.distributed.api.Feature) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Collections(java.util.Collections) Cluster(org.apache.cassandra.distributed.Cluster) InetAddress(java.net.InetAddress) 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