Search in sources :

Example 76 with Cluster

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

the class InternodeEncryptionOptionsTest method allInternodeEncryptionEstablishedTest.

@Test
public void allInternodeEncryptionEstablishedTest() throws Throwable {
    try (Cluster cluster = builder().withNodes(2).withConfig(c -> {
        c.with(Feature.NETWORK).with(// To make sure AllMembersAliveMonitor checks gossip (which uses internode conns)
        Feature.GOSSIP).with(// For virtual tables
        Feature.NATIVE_PROTOCOL);
        c.set("server_encryption_options", ImmutableMap.builder().putAll(validKeystore).put("internode_encryption", "all").build());
    }).start()) {
        // Just check startup - cluster should not be able to establish internode connections xwithout encrypted connections
        for (int i = 1; i <= cluster.size(); i++) {
            Object[][] result = cluster.get(i).executeInternal("SELECT successful_connection_attempts, address, port FROM system_views.internode_outbound");
            Assert.assertEquals(1, result.length);
            long successfulConnectionAttempts = (long) result[0][0];
            Assert.assertTrue("At least one connection: " + successfulConnectionAttempts, successfulConnectionAttempts > 0);
        }
    }
}
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) Test(org.junit.Test)

Example 77 with Cluster

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

the class InternodeEncryptionOptionsTest method negotiatedProtocolMustBeAcceptedProtocolTest.

@Test
public void negotiatedProtocolMustBeAcceptedProtocolTest() 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", "all").put("accepted_protocols", Collections.singletonList("TLSv1.1")).build());
    }).start()) {
        InetAddress address = cluster.get(1).config().broadcastAddress().getAddress();
        int port = cluster.get(1).config().broadcastAddress().getPort();
        TlsConnection tls10Connection = new TlsConnection(address.getHostAddress(), port, Collections.singletonList("TLSv1"));
        Assert.assertEquals("Should not be possible to establish a TLSv1 connection", ConnectResult.FAILED_TO_NEGOTIATE, tls10Connection.connect());
        tls10Connection.assertReceivedHandshakeException();
        TlsConnection tls11Connection = new TlsConnection(address.getHostAddress(), port, Collections.singletonList("TLSv1.1"));
        Assert.assertEquals("Should be possible to establish a TLSv1.1 connection", ConnectResult.NEGOTIATED, tls11Connection.connect());
        Assert.assertEquals("TLSv1.1", tls11Connection.lastProtocol());
        TlsConnection tls12Connection = new TlsConnection(address.getHostAddress(), port, Collections.singletonList("TLSv1.2"));
        Assert.assertEquals("Should not be possible to establish a TLSv1.2 connection", ConnectResult.FAILED_TO_NEGOTIATE, tls12Connection.connect());
        tls12Connection.assertReceivedHandshakeException();
    }
}
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 78 with Cluster

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

the class InternodeEncryptionOptionsTest method legacySslStoragePortEnabledWithSameRegularAndSslPortTest.

@Test
public void legacySslStoragePortEnabledWithSameRegularAndSslPortTest() throws Throwable {
    try (Cluster cluster = builder().withNodes(1).withConfig(c -> {
        c.with(Feature.NETWORK);
        // must match in-jvm dtest assigned ports
        c.set("storage_port", 7012);
        c.set("ssl_storage_port", 7012);
        c.set("server_encryption_options", ImmutableMap.builder().putAll(validKeystore).put("internode_encryption", "none").put("optional", true).put("legacy_ssl_storage_port_enabled", "true").build());
    }).createWithoutStarting()) {
        InetAddress address = cluster.get(1).config().broadcastAddress().getAddress();
        int ssl_port = (int) cluster.get(1).config().get("ssl_storage_port");
        // Create the connections and prove they cannot connect before server start
        TlsConnection connectToSslStoragePort = new TlsConnection(address.getHostAddress(), ssl_port);
        connectToSslStoragePort.assertCannotConnect();
        cluster.startup();
        Assert.assertEquals("TLS native connection should be possible to ssl_storage_port", ConnectResult.NEGOTIATED, connectToSslStoragePort.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 79 with Cluster

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

the class JVMDTestTest method insertTimestampTest.

@Test
public void insertTimestampTest() throws IOException {
    try (Cluster cluster = init(Cluster.build(1).start())) {
        long now = FBUtilities.timestampMicros();
        cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (id int primary key, i int)");
        cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, i) VALUES (1,1)", ConsistencyLevel.ALL);
        cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, i) VALUES (2,2) USING TIMESTAMP 1000", ConsistencyLevel.ALL);
        Object[][] res = cluster.coordinator(1).execute("SELECT writetime(i) FROM " + KEYSPACE + ".tbl WHERE id = 1", ConsistencyLevel.ALL);
        assertEquals(1, res.length);
        assertTrue("ts=" + res[0][0], (long) res[0][0] >= now);
        res = cluster.coordinator(1).execute("SELECT writetime(i) FROM " + KEYSPACE + ".tbl WHERE id = 2", ConsistencyLevel.ALL);
        assertEquals(1, res.length);
        assertEquals(1000, (long) res[0][0]);
    }
}
Also used : Cluster(org.apache.cassandra.distributed.Cluster) Test(org.junit.Test)

Example 80 with Cluster

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

the class LargeMessageTest method testLargeMessage.

@Test
public void testLargeMessage() throws Throwable {
    try (Cluster cluster = init(builder().withNodes(2).start())) {
        cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, v text, PRIMARY KEY (pk, ck))"));
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < LARGE_MESSAGE_THRESHOLD; i++) builder.append('a');
        String s = builder.toString();
        cluster.coordinator(1).execute(withKeyspace("INSERT INTO %s.tbl (pk, ck, v) VALUES (1, 1, ?)"), ALL, s);
        assertRows(cluster.coordinator(1).execute(withKeyspace("SELECT * FROM %s.tbl WHERE pk = ?"), ALL, 1), row(1, 1, s));
    }
}
Also used : 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