use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class DriverBlockHoundIntegrationCcmIT method should_not_detect_blocking_call_with_continuous_paging_when_timeout.
/**
* Copied from com.datastax.dse.driver.api.core.cql.continuous.ContinuousPagingIT.
*/
@Test
public void should_not_detect_blocking_call_with_continuous_paging_when_timeout() throws Exception {
CqlSession session = SESSION_RULE.session();
SimpleStatement statement = SimpleStatement.newInstance("SELECT v from test where k=?", KEY);
// Throttle server at a page per second and set client timeout much lower so that the client
// will experience a timeout.
// Note that this might not be perfect if there are pauses in the JVM and the timeout
// doesn't fire soon enough.
DriverExecutionProfile profile = session.getContext().getConfig().getDefaultProfile().withInt(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE, 10).withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND, 1).withDuration(DseDriverOption.CONTINUOUS_PAGING_TIMEOUT_OTHER_PAGES, Duration.ofMillis(100));
CompletionStage<ContinuousAsyncResultSet> future = session.executeContinuouslyAsync(statement.setExecutionProfile(profile));
ContinuousAsyncResultSet pagingResult = CompletableFutures.getUninterruptibly(future);
try {
pagingResult.fetchNextPage().toCompletableFuture().get();
fail("Expected a timeout");
} catch (ExecutionException e) {
assertThat(e.getCause()).isInstanceOf(DriverTimeoutException.class).hasMessageContaining("Timed out waiting for page 2");
}
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class ContinuousCqlRequestSyncProcessor method process.
@Override
public ContinuousResultSet process(Statement<?> request, DefaultSession session, InternalDriverContext context, String sessionLogPrefix) {
BlockingOperation.checkNotDriverThread();
ContinuousAsyncResultSet firstPage = CompletableFutures.getUninterruptibly(asyncProcessor.process(request, session, context, sessionLogPrefix));
return new DefaultContinuousResultSet(firstPage);
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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");
}
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest 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()) {
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> page1Future = handler.handle();
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
assertThatStage(page1Future).isSuccess(page1 -> {
assertThat(page1.hasMorePages()).isTrue();
assertThat(page1.pageNumber()).isEqualTo(1);
Iterator<Row> rows = page1.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows).toIterable().hasSize(10);
ExecutionInfo executionInfo = page1.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNotNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
ContinuousAsyncResultSet page1 = CompletableFutures.getCompleted(page1Future);
assertThat(handler.getPendingResult()).isNull();
CompletionStage<ContinuousAsyncResultSet> page2Future = page1.fetchNextPage();
assertThat(handler.getPendingResult()).isNotNull();
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
assertThatStage(page2Future).isSuccess(page2 -> {
assertThat(page2.hasMorePages()).isFalse();
assertThat(page2.pageNumber()).isEqualTo(2);
Iterator<Row> rows = page2.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows).toIterable().hasSize(10);
ExecutionInfo executionInfo = page2.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();
});
}
}
Aggregations