use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_send_backpressure_request_if_dse_v2.
@Test
public void should_send_backpressure_request_if_dse_v2() {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(DSE_V2);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
CompletionStage<ContinuousAsyncResultSet> page1Future = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
// simulate the arrival of 4 pages, the first one will complete page1 future above,
// the following 3 will be enqueued
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, false)));
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(3, false)));
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(4, false)));
// simulate the retrieval of 2 pages, this should dequeue page 2
// and trigger a backpressure request as the queue is now half empty (2/4)
ContinuousAsyncResultSet page1 = CompletableFutures.getCompleted(page1Future);
CompletableFutures.getCompleted(page1.fetchNextPage());
verify(node1Behavior.getChannel()).write(argThat(this::isBackpressureRequest), anyBoolean(), anyMap(), any());
// should not mess with autoread in dse v2
verify(node1Behavior.getChannel().config(), never()).setAutoRead(anyBoolean());
}
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_fail_if_no_node_available.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_fail_if_no_node_available(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).build()) {
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isFailed(error -> assertThat(error).isInstanceOf(NoNodeAvailableException.class));
}
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class ContinuousCqlRequestHandlerRetryTest method should_ignore_error_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_ignore_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.IGNORE);
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()).isFalse();
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).hasSize(0);
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.errorMetric), anyString());
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.IGNORES), anyString());
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.ignoreMetric), anyString());
Mockito.verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class ContinuousCqlRequestHandlerRetryTest method should_always_rethrow_query_validation_error.
@Test
@UseDataProvider("allIdempotenceConfigs")
public void should_always_rethrow_query_validation_error(boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.INVALID, "mock message"))).build()) {
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(InvalidQueryException.class).hasMessage("mock message");
Mockito.verifyNoMoreInteractions(harness.getContext().getRetryPolicy(anyString()));
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.OTHER_ERRORS), anyString());
Mockito.verify(nodeMetricUpdater1).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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);
});
}
}
Aggregations