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);
}
}
}
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();
}
}
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());
}
}
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]);
}
}
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));
}
}
Aggregations