Search in sources :

Example 1 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class BoundStatementCcmIT method supportsPerRequestKeyspace.

private boolean supportsPerRequestKeyspace(CqlSession session) {
    InternalDriverContext context = (InternalDriverContext) session.getContext();
    ProtocolVersionRegistry protocolVersionRegistry = context.getProtocolVersionRegistry();
    return protocolVersionRegistry.supports(context.getProtocolVersion(), DefaultProtocolFeature.PER_REQUEST_KEYSPACE);
}
Also used : InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) ProtocolVersionRegistry(com.datastax.oss.driver.internal.core.ProtocolVersionRegistry)

Example 2 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class ProtocolVersionMixedClusterIT method should_downgrade_if_peer_does_not_support_negotiated_version.

@Test
public void should_downgrade_if_peer_does_not_support_negotiated_version() {
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withBoolean(DefaultDriverOption.METADATA_SCHEMA_ENABLED, false).build();
    try (BoundCluster simulacron = mixedVersions("3.0.0", "2.2.0", "2.1.0");
        BoundNode contactPoint = simulacron.node(0);
        CqlSession session = (CqlSession) SessionUtils.baseBuilder().addContactPoint(contactPoint.inetSocketAddress()).withConfigLoader(loader).build()) {
        InternalDriverContext context = (InternalDriverContext) session.getContext();
        // General version should have been downgraded to V3
        assertThat(context.getProtocolVersion()).isEqualTo(DefaultProtocolVersion.V3);
        // But control connection should still be using protocol V4 since node0 supports V4
        assertThat(context.getControlConnection().channel().protocolVersion()).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");
    }
}
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) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) Test(org.junit.Test)

Example 3 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class DefaultLoadBalancingPolicyIT method should_hit_non_replicas_when_routing_information_present_but_all_replicas_down.

@Test
public void should_hit_non_replicas_when_routing_information_present_but_all_replicas_down() {
    CqlIdentifier keyspace = CqlIdentifier.fromCql("test");
    ByteBuffer routingKey = TypeCodecs.INT.encodePrimitive(1, ProtocolVersion.DEFAULT);
    TokenMap tokenMap = SESSION_RULE.session().getMetadata().getTokenMap().get();
    InternalDriverContext context = (InternalDriverContext) SESSION_RULE.session().getContext();
    Set<Node> localReplicas = new HashSet<>();
    for (Node replica : tokenMap.getReplicas(keyspace, routingKey)) {
        if (replica.getDatacenter().equals(LOCAL_DC)) {
            localReplicas.add(replica);
            context.getEventBus().fire(TopologyEvent.forceDown(replica.getBroadcastRpcAddress().get()));
            await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).untilAsserted(() -> assertThat(replica.getOpenConnections()).isZero());
        }
    }
    assertThat(localReplicas).hasSize(2);
    // TODO add statements with setKeyspace when that is supported
    List<Statement> statements = ImmutableList.of(SimpleStatement.newInstance("SELECT * FROM test.foo WHERE k = 1").setRoutingKeyspace(keyspace).setRoutingKey(routingKey), SimpleStatement.newInstance("SELECT * FROM test.foo WHERE k = 1").setRoutingKeyspace(keyspace).setRoutingToken(tokenMap.newToken(routingKey)));
    for (Statement statement : statements) {
        List<Node> coordinators = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            ResultSet rs = SESSION_RULE.session().execute(statement);
            Node coordinator = rs.getExecutionInfo().getCoordinator();
            coordinators.add(coordinator);
            assertThat(coordinator.getDatacenter()).isEqualTo(LOCAL_DC);
            assertThat(localReplicas).doesNotContain(coordinator);
        }
        // Should round-robin on the two non-replicas
        for (int i = 0; i < 2; i++) {
            assertThat(coordinators.get(i)).isEqualTo(coordinators.get(2 + i)).isEqualTo(coordinators.get(4 + i));
        }
    }
    for (Node replica : localReplicas) {
        context.getEventBus().fire(TopologyEvent.forceUp(replica.getBroadcastRpcAddress().get()));
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).untilAsserted(() -> assertThat(replica.getOpenConnections()).isPositive());
    }
}
Also used : SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Statement(com.datastax.oss.driver.api.core.cql.Statement) Node(com.datastax.oss.driver.api.core.metadata.Node) ArrayList(java.util.ArrayList) TokenMap(com.datastax.oss.driver.api.core.metadata.TokenMap) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) ByteBuffer(java.nio.ByteBuffer) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class ExecutionProfilesInfoFinderTest method should_include_info_about_default_profile.

@Test
public void should_include_info_about_default_profile() {
    // given
    DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
    Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile);
    InternalDriverContext context = mockDriverContextWithProfiles(defaultExecutionProfile, profiles);
    // when
    Map<String, SpecificExecutionProfile> executionProfilesInfo = new ExecutionProfilesInfoFinder().getExecutionProfilesInfo(context);
    // then
    assertThat(executionProfilesInfo).isEqualTo(ImmutableMap.of("default", new SpecificExecutionProfile(100, new LoadBalancingInfo("LoadBalancingPolicyImpl", ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), DEFAULT_LOAD_BALANCING_PACKAGE), new SpeculativeExecutionInfo("SpeculativeExecutionImpl", ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), "LOCAL_ONE", "SERIAL", ImmutableMap.of("source", "src-graph"))));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) LoadBalancingInfo(com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo) SpecificExecutionProfile(com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo) ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo) Test(org.junit.Test)

Example 5 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class ExecutionProfilesInfoFinderTest method mockDriverContextWithProfiles.

private InternalDriverContext mockDriverContextWithProfiles(DriverExecutionProfile defaultExecutionProfile, Map<String, DriverExecutionProfile> profiles) {
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverConfig driverConfig = mock(DriverConfig.class);
    Mockito.<Map<String, ? extends DriverExecutionProfile>>when(driverConfig.getProfiles()).thenReturn(profiles);
    when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile);
    when(context.getConfig()).thenReturn(driverConfig);
    return context;
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Aggregations

InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)45 Test (org.junit.Test)29 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)16 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)15 Node (com.datastax.oss.driver.api.core.metadata.Node)13 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)12 MetricIdGenerator (com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 MetricRegistry (com.codahale.metrics.MetricRegistry)5 CqlSession (com.datastax.oss.driver.api.core.CqlSession)5 MetricId (com.datastax.oss.driver.internal.core.metrics.MetricId)5 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)4 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)4 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)4 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)4 DefaultSessionMetric (com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric)4 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)4