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