use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTestBase method continuousHarnessBuilder.
protected RequestHandlerTestHarness.Builder continuousHarnessBuilder() {
return new RequestHandlerTestHarness.Builder() {
@Override
public RequestHandlerTestHarness build() {
RequestHandlerTestHarness harness = super.build();
DriverExecutionProfile config = harness.getContext().getConfig().getDefaultProfile();
when(config.getDuration(CONTINUOUS_PAGING_TIMEOUT_FIRST_PAGE)).thenReturn(TIMEOUT_FIRST_PAGE);
when(config.getDuration(CONTINUOUS_PAGING_TIMEOUT_OTHER_PAGES)).thenReturn(TIMEOUT_OTHER_PAGES);
when(config.getInt(CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES)).thenReturn(4);
return harness;
}
};
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class CqlRequestReactiveProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseAndOssProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(ProtocolVersion version) {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(singleDseRow())).build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ReactiveResultSet publisher = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor()).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.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class CqlRequestReactiveProcessorTest method should_complete_multi_page_result.
@Test
@UseDataProvider(value = "allDseAndOssProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(ProtocolVersion version) {
RequestHandlerTestHarness.Builder builder = RequestHandlerTestHarness.builder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
// The 2nd page is obtained by an "external" call to session.executeAsync(),
// so we need to mock that.
CompletableFuture<AsyncResultSet> page2Future = new CompletableFuture<>();
when(session.executeAsync(any(Statement.class))).thenAnswer(invocation -> page2Future);
ExecutionInfo mockInfo = mock(ExecutionInfo.class);
ReactiveResultSet publisher = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
// emulate arrival of page 1
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
// emulate arrival of page 2 following the call to session.executeAsync()
page2Future.complete(Conversions.toResultSet(DseTestFixtures.tenDseRows(2, true), mockInfo, harness.getSession(), harness.getContext()));
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).isSameAs(mockInfo);
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.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class CqlRequestReactiveProcessorTest method should_create_request_handler.
@Test
public void should_create_request_handler() {
RequestHandlerTestHarness.Builder builder = RequestHandlerTestHarness.builder().withProtocolVersion(DSE_V1);
try (RequestHandlerTestHarness harness = builder.build()) {
CqlRequestReactiveProcessor processor = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor());
assertThat(processor.process(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test")).isInstanceOf(DefaultReactiveResultSet.class);
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerReprepareTest method should_prepare_and_retry_on_same_node.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_prepare_and_retry_on_same_node(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withResponse(node1, defaultFrameOf(unprepared)).withProtocolVersion(version).build()) {
when(harness.getSession().getRepreparePayloads()).thenReturn(repreparePayloads);
when(harness.getChannel(node1).write(any(Prepare.class), anyBoolean(), anyMap(), any())).then(invocation -> {
AdminRequestHandler<?> admin = invocation.getArgument(3);
admin.onResponse(defaultFrameOf(prepared));
return future;
});
new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
verify(harness.getChannel(node1)).write(any(Prepare.class), anyBoolean(), anyMap(), any());
// should have attempted to execute the query twice on the same node
verify(harness.getChannel(node1), times(2)).write(any(Query.class), anyBoolean(), anyMap(), any());
}
}
Aggregations