use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_not_cancel_session_if_future_cancelled_but_already_done.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_not_cancel_session_if_future_cancelled_but_already_done(DseProtocolVersion version) {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> page1Future = handler.handle();
// this will complete page 1 future
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, true)));
// to late
page1Future.toCompletableFuture().cancel(true);
assertThat(handler.getState()).isEqualTo(-1);
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_invoke_request_tracker.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_invoke_request_tracker(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(new com.datastax.oss.protocol.internal.response.Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
RequestTracker requestTracker = mock(RequestTracker.class);
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows.next().getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node2);
assertThat(executionInfo.getErrors()).isNotEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
verify(requestTracker).onNodeError(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), any(BootstrappingException.class), anyLong(), any(DriverExecutionProfile.class), eq(node1), matches(LOG_PREFIX_PER_REQUEST));
verify(requestTracker).onNodeSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), matches(LOG_PREFIX_PER_REQUEST));
verify(requestTracker).onSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), matches(LOG_PREFIX_PER_REQUEST));
verifyNoMoreInteractions(requestTracker);
});
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest 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()) {
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows.next().getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = resultSet.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();
});
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestReactiveProcessorTest method should_create_request_handler.
@Test
public void should_create_request_handler() {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(DSE_V1);
try (RequestHandlerTestHarness harness = builder.build()) {
ContinuousCqlRequestReactiveProcessor processor = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor());
assertThat(processor.process(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test")).isInstanceOf(DefaultContinuousReactiveResultSet.class);
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_honor_statement_timeout.
@Test
public void should_honor_statement_timeout() throws Exception {
// given
GraphBinaryModule binaryModule = createGraphBinaryModule(mockContext);
Duration defaultTimeout = Duration.ofSeconds(1);
Duration statementTimeout = Duration.ofSeconds(2);
RequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphTimeout(defaultTimeout);
PoolBehavior node1Behavior = builder.customBehavior(node);
try (RequestHandlerTestHarness harness = builder.build()) {
DriverExecutionProfile profile = harness.getContext().getConfig().getDefaultProfile();
when(profile.isDefined(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(true);
when(profile.getString(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(GraphProtocol.GRAPH_BINARY_1_0.toInternalCode());
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setTimeout(statementTimeout);
// when
ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", binaryModule, new GraphSupportChecker());
// send the initial request
CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
// acknowledge the write, will set the global timeout
node1Behavior.verifyWrite();
node1Behavior.setWriteSuccess();
CapturedTimeout globalTimeout = harness.nextScheduledTimeout();
assertThat(globalTimeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(statementTimeout.toNanos());
// will trigger the global timeout and complete it exceptionally
globalTimeout.task().run(globalTimeout);
assertThat(page1Future.toCompletableFuture()).isCompletedExceptionally();
assertThatThrownBy(() -> page1Future.toCompletableFuture().get()).hasRootCauseExactlyInstanceOf(DriverTimeoutException.class).hasMessageContaining("Query timed out after " + statementTimeout);
}
}
Aggregations