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_not_idempotent_and_error_unsafe_or_policy_rethrows.
@Test
@UseDataProvider("failureAndNotIdempotent")
public void should_rethrow_error_if_not_idempotent_and_error_unsafe_or_policy_rethrows(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
// For two of the possible exceptions, the retry policy is called even if the statement is not
// idempotent
boolean shouldCallRetryPolicy = (failureScenario.expectedExceptionClass.equals(UnavailableException.class) || failureScenario.expectedExceptionClass.equals(ReadTimeoutException.class));
RequestHandlerTestHarness.Builder harnessBuilder = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
harnessBuilder.withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow()));
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
if (shouldCallRetryPolicy) {
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);
// When non idempotent, the policy is bypassed completely:
if (!shouldCallRetryPolicy) {
Mockito.verifyNoMoreInteractions(harness.getContext().getRetryPolicy(anyString()));
}
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 DefaultContinuousResultSetTest method mockPage.
private static ContinuousAsyncResultSet mockPage(boolean nextPage, Integer... data) {
ContinuousAsyncResultSet page = Mockito.mock(ContinuousAsyncResultSet.class);
ColumnDefinitions columnDefinitions = Mockito.mock(ColumnDefinitions.class);
Mockito.when(page.getColumnDefinitions()).thenReturn(columnDefinitions);
ExecutionInfo executionInfo = Mockito.mock(ExecutionInfo.class);
Mockito.when(page.getExecutionInfo()).thenReturn(executionInfo);
if (nextPage) {
Mockito.when(page.hasMorePages()).thenReturn(true);
Mockito.when(page.fetchNextPage()).thenReturn(Mockito.spy(new CompletableFuture<>()));
} else {
Mockito.when(page.hasMorePages()).thenReturn(false);
Mockito.when(page.fetchNextPage()).thenThrow(new IllegalStateException());
}
Iterator<Integer> rows = Arrays.asList(data).iterator();
CountingIterator<Row> iterator = new CountingIterator<Row>(data.length) {
@Override
protected Row computeNext() {
return rows.hasNext() ? mockRow(rows.next()) : endOfData();
}
};
Mockito.when(page.currentPage()).thenReturn(() -> iterator);
Mockito.when(page.remaining()).thenAnswer(invocation -> iterator.remaining());
return page;
}
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_multiple_pages.
@Test
public void should_create_result_set_from_multiple_pages() {
// Given
ContinuousAsyncResultSet page1 = mockPage(true, 0, 1, 2);
ContinuousAsyncResultSet page2 = mockPage(true, 3, 4, 5);
ContinuousAsyncResultSet page3 = mockPage(false, 6, 7, 8);
complete(page1.fetchNextPage(), page2);
complete(page2.fetchNextPage(), page3);
// When
ResultSet resultSet = new DefaultContinuousResultSet(page1);
// Then
assertThat(resultSet.iterator().hasNext()).isTrue();
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()).isTrue();
// This should have triggered the fetch of page2
assertThat(resultSet.getExecutionInfo()).isEqualTo(page2.getExecutionInfo());
assertThat(resultSet.getExecutionInfos()).containsExactly(page1.getExecutionInfo(), page2.getExecutionInfo());
assertNextRow(iterator, 3);
assertNextRow(iterator, 4);
assertNextRow(iterator, 5);
assertThat(iterator.hasNext()).isTrue();
// This should have triggered the fetch of page3
assertThat(resultSet.getExecutionInfo()).isEqualTo(page3.getExecutionInfo());
assertThat(resultSet.getExecutionInfos()).containsExactly(page1.getExecutionInfo(), page2.getExecutionInfo(), page3.getExecutionInfo());
assertNextRow(iterator, 6);
assertNextRow(iterator, 7);
assertNextRow(iterator, 8);
}
Aggregations