use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.
the class DefaultContinuousResultSetTest method should_create_result_set_from_single_page.
@Test
public void should_create_result_set_from_single_page() {
// Given
ContinuousAsyncResultSet page1 = mockPage(false, 0, 1, 2);
// When
ResultSet resultSet = new DefaultContinuousResultSet(page1);
// Then
assertThat(resultSet.getColumnDefinitions()).isSameAs(page1.getColumnDefinitions());
assertThat(resultSet.getExecutionInfo()).isSameAs(page1.getExecutionInfo());
assertThat(resultSet.getExecutionInfos()).containsExactly(page1.getExecutionInfo());
Iterator<Row> iterator = resultSet.iterator();
assertNextRow(iterator, 0);
assertNextRow(iterator, 1);
assertNextRow(iterator, 2);
assertThat(iterator.hasNext()).isFalse();
}
use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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();
}
}
Aggregations