use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerRetryTest method should_try_next_node_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_try_next_node_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
RequestHandlerTestHarness.Builder harnessBuilder = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
harnessBuilder.withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow()));
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.RETRY_NEXT);
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = handler.handle();
assertThat(handler.getState()).isEqualTo(-1);
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()).hasSize(1);
assertThat(executionInfo.getErrors().get(0).getKey()).isEqualTo(node1);
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.errorMetric), anyString());
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.RETRIES), anyString());
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.retryMetric), anyString());
Mockito.verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerRetryTest method should_rethrow_error_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_rethrow_error_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
RequestHandlerTestHarness.Builder harnessBuilder = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.RETHROW);
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = handler.handle();
assertThat(handler.getState()).isEqualTo(-2);
assertThatStage(resultSetFuture).isFailed(error -> {
assertThat(error).isInstanceOf(failureScenario.expectedExceptionClass);
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.errorMetric), anyString());
Mockito.verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_return_paged_results.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_return_paged_results(GraphProtocol graphProtocol) throws IOException {
String profileName = "test-graph";
when(nodeMetricUpdater1.isEnabled(DseNodeMetric.GRAPH_MESSAGES, profileName)).thenReturn(true);
GraphBinaryModule module = createGraphBinaryModule(mockContext);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol);
PoolBehavior node1Behavior = builder.customBehavior(node);
try (RequestHandlerTestHarness harness = builder.build()) {
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName(profileName);
ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", module, new GraphSupportChecker());
// send the initial request
CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, module, 1, false)));
assertThatStage(page1Future).isSuccess(page1 -> {
assertThat(page1.hasMorePages()).isTrue();
assertThat(page1.currentPage()).hasSize(10).allMatch(GraphNode::isVertex);
ExecutionInfo executionInfo = page1.getRequestExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
AsyncGraphResultSet page1 = CompletableFutures.getCompleted(page1Future);
CompletionStage<AsyncGraphResultSet> page2Future = page1.fetchNextPage();
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, module, 2, true)));
assertThatStage(page2Future).isSuccess(page2 -> {
assertThat(page2.hasMorePages()).isFalse();
assertThat(page2.currentPage()).hasSize(10).allMatch(GraphNode::isVertex);
ExecutionInfo executionInfo = page2.getRequestExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
validateMetrics(profileName, harness);
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_honor_default_timeout.
@Test
public void should_honor_default_timeout() throws Exception {
// given
GraphBinaryModule binaryModule = createGraphBinaryModule(mockContext);
Duration defaultTimeout = Duration.ofSeconds(1);
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");
// 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(defaultTimeout.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 " + defaultTimeout);
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerReprepareTest method should_abort_when_prepare_fails_with_unrecoverable_error.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_abort_when_prepare_fails_with_unrecoverable_error(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(unrecoverable));
return future;
});
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> page1Future = handler.handle();
verify(harness.getChannel(node1)).write(any(Query.class), anyBoolean(), anyMap(), any());
verify(harness.getChannel(node1)).write(any(Prepare.class), anyBoolean(), anyMap(), any());
assertThat(handler.getState()).isEqualTo(-2);
assertThat(page1Future).isCompletedExceptionally();
Throwable t = catchThrowable(() -> page1Future.toCompletableFuture().get());
assertThat(t).hasRootCauseInstanceOf(SyntaxError.class).hasMessageContaining("bad query");
}
}
Aggregations