Search in sources :

Example 6 with BoundCluster

use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.

the class ProtocolVersionMixedClusterIT method should_not_downgrade_and_force_down_old_nodes_if_version_forced.

@Test
public void should_not_downgrade_and_force_down_old_nodes_if_version_forced() {
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V4").withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false).build();
    try (BoundCluster simulacron = mixedVersions("3.0.0", "2.2.0", "2.0.0");
        BoundNode contactPoint = simulacron.node(0);
        CqlSession session = (CqlSession) SessionUtils.baseBuilder().addContactPoint(contactPoint.inetSocketAddress()).withConfigLoader(loader).build()) {
        assertThat(session.getContext().getProtocolVersion()).isEqualTo(DefaultProtocolVersion.V4);
        assertThat(queries(simulacron)).hasSize(4);
        assertThat(protocolQueries(contactPoint, 4)).containsExactly(// Initial connection with protocol v4
        "SELECT cluster_name FROM system.local", "SELECT * FROM system.local", "SELECT * FROM system.peers_v2", "SELECT * FROM system.peers");
    // Note: the 2.0.0 would be forced down if we try to open a connection to it. We can't check
    // that here because Simulacron can't prime STARTUP requests.
    }
}
Also used : DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) BoundCluster(com.datastax.oss.simulacron.server.BoundCluster) BoundNode(com.datastax.oss.simulacron.server.BoundNode) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 7 with BoundCluster

use of com.datastax.oss.simulacron.server.BoundCluster in project java-driver by datastax.

the class ProtocolVersionMixedClusterIT method should_fail_if_peer_does_not_support_v3.

@Test
public void should_fail_if_peer_does_not_support_v3() {
    Throwable t = catchThrowable(() -> {
        try (BoundCluster simulacron = mixedVersions("3.0.0", "2.0.9", "3.11");
            BoundNode contactPoint = simulacron.node(0);
            CqlSession ignored = (CqlSession) SessionUtils.baseBuilder().addContactPoint(contactPoint.inetSocketAddress()).build()) {
            fail("Cluster init should have failed");
        }
    });
    assertThat(t).isInstanceOf(UnsupportedProtocolVersionException.class).hasMessageContaining("reports Cassandra version 2.0.9, but the driver only supports 2.1.0 and above");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) BoundCluster(com.datastax.oss.simulacron.server.BoundCluster) BoundNode(com.datastax.oss.simulacron.server.BoundNode) UnsupportedProtocolVersionException(com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Aggregations

BoundCluster (com.datastax.oss.simulacron.server.BoundCluster)7 CqlSession (com.datastax.oss.driver.api.core.CqlSession)6 Test (org.junit.Test)6 BoundNode (com.datastax.oss.simulacron.server.BoundNode)5 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)3 Node (com.datastax.oss.driver.api.core.metadata.Node)2 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)2 UUID (java.util.UUID)2 Metric (com.codahale.metrics.Metric)1 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)1 UnsupportedProtocolVersionException (com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)1 LoadBalancingPolicy (com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy)1 NodeDistance (com.datastax.oss.driver.api.core.loadbalancing.NodeDistance)1 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)1 Metrics (com.datastax.oss.driver.api.core.metrics.Metrics)1 UnavailableException (com.datastax.oss.driver.api.core.servererrors.UnavailableException)1 Request (com.datastax.oss.driver.api.core.session.Request)1 Session (com.datastax.oss.driver.api.core.session.Session)1