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 ContinuousCqlRequestReactiveProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
List<ReactiveRow> rows = Flowable.fromPublisher(publisher).toList().blockingGet();
assertThat(rows).hasSize(1);
ReactiveRow row = rows.get(0);
assertThat(row.getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = row.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(executionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(row.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(row.wasApplied());
}
}
use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.
the class ContinuousCqlRequestReactiveProcessorTest method should_complete_multi_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version) {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
List<ReactiveRow> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(20);
ReactiveRow first = rows.get(0);
ExecutionInfo firstExecutionInfo = first.getExecutionInfo();
assertThat(firstExecutionInfo.getCoordinator()).isEqualTo(node1);
assertThat(firstExecutionInfo.getErrors()).isEmpty();
assertThat(firstExecutionInfo.getIncomingPayload()).isEmpty();
assertThat(firstExecutionInfo.getPagingState()).isNotNull();
assertThat(firstExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(firstExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(firstExecutionInfo.getWarnings()).isEmpty();
ReactiveRow inSecondPage = rows.get(10);
ExecutionInfo secondExecutionInfo = inSecondPage.getExecutionInfo();
assertThat(secondExecutionInfo.getCoordinator()).isEqualTo(node1);
assertThat(secondExecutionInfo.getErrors()).isEmpty();
assertThat(secondExecutionInfo.getIncomingPayload()).isEmpty();
assertThat(secondExecutionInfo.getPagingState()).isNull();
assertThat(secondExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(secondExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(secondExecutionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(firstExecutionInfo, secondExecutionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(first.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(first.wasApplied());
}
}
use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.
the class GraphSupportCheckerTest method should_not_support_paging_when_statement_profile_not_present.
@Test
public void should_not_support_paging_when_statement_profile_not_present() {
// given
GraphStatement graphStatement = mock(GraphStatement.class);
InternalDriverContext context = protocolWithPagingSupport(true);
contextGraphPagingEnabled(context, DISABLED);
addNodeWithDseVersion(context, Collections.singletonList(Version.parse("6.8.0")));
// when
boolean pagingEnabled = new GraphSupportChecker().isPagingEnabled(graphStatement, context);
// then
assertThat(pagingEnabled).isEqualTo(false);
}
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