use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerReprepareTest method should_try_next_node_when_prepare_fails_with_recoverable_error.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_try_next_node_when_prepare_fails_with_recoverable_error(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withResponse(node1, defaultFrameOf(unprepared)).withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow())).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(recoverable));
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());
// should have tried the next host
verify(harness.getChannel(node2)).write(any(Query.class), anyBoolean(), anyMap(), any());
assertThat(handler.getState()).isEqualTo(-1);
assertThatStage(page1Future).isSuccess(rs -> {
assertThat(rs.currentPage()).hasSize(1);
assertThat(rs.hasMorePages()).isFalse();
assertThat(rs.getExecutionInfo().getCoordinator()).isEqualTo(node2);
assertThat(rs.getExecutionInfo().getErrors()).hasSize(1).allSatisfy(entry -> {
assertThat(entry.getKey()).isEqualTo(node1);
assertThat(entry.getValue()).isInstanceOf(UnexpectedResponseException.class).hasMessageContaining(recoverable.toString());
});
});
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_time_out_if_other_page_takes_too_long.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_time_out_if_other_page_takes_too_long(DseProtocolVersion version) throws Exception {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
CompletionStage<ContinuousAsyncResultSet> page1Future = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
// mark the initial request as successful, which should schedule a timeout for the first page
node1Behavior.setWriteSuccess();
CapturedTimeout page1Timeout = harness.nextScheduledTimeout();
assertThat(page1Timeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(TIMEOUT_FIRST_PAGE.toNanos());
// the server replies with page 1, the corresponding timeout should be cancelled
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
assertThat(page1Timeout.isCancelled()).isTrue();
// request page 2, the queue is empty so this should request more pages and schedule another
// timeout
ContinuousAsyncResultSet page1 = CompletableFutures.getUninterruptibly(page1Future);
CompletionStage<ContinuousAsyncResultSet> page2Future = page1.fetchNextPage();
CapturedTimeout page2Timeout = harness.nextScheduledTimeout();
assertThat(page2Timeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(TIMEOUT_OTHER_PAGES.toNanos());
page2Timeout.task().run(page2Timeout);
assertThatStage(page2Future).isFailed(t -> assertThat(t).isInstanceOf(DriverTimeoutException.class).hasMessageContaining("Timed out waiting for page 2"));
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_time_out_if_first_page_takes_too_long.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_time_out_if_first_page_takes_too_long(DseProtocolVersion version) throws Exception {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
// mark the initial request as successful, which should schedule a timeout for the first page
node1Behavior.setWriteSuccess();
CapturedTimeout page1Timeout = harness.nextScheduledTimeout();
assertThat(page1Timeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(TIMEOUT_FIRST_PAGE.toNanos());
page1Timeout.task().run(page1Timeout);
assertThatStage(resultSetFuture).isFailed(t -> assertThat(t).isInstanceOf(DriverTimeoutException.class).hasMessageContaining("Timed out waiting for page 1"));
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_cancel_future_if_session_cancelled.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_cancel_future_if_session_cancelled(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)));
// will be discarded
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, false)));
ContinuousAsyncResultSet page1 = CompletableFutures.getUninterruptibly(page1Future);
page1.cancel();
assertThat(handler.getState()).isEqualTo(-2);
assertThat(page1.fetchNextPage()).isCancelled();
}
}
use of com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness 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());
}
}
Aggregations