use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerRetryTest 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) {
RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.IGNORE);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
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);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.errorMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(DefaultNodeMetric.IGNORES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.ignoreMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(1)).isEnabled(DefaultNodeMetric.CQL_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerRetryTest method should_always_try_next_node_if_bootstrapping.
@Test
@UseDataProvider("allIdempotenceConfigs")
public void should_always_try_next_node_if_bootstrapping(boolean defaultIdempotence, Statement<?> statement) {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
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);
assertThat(executionInfo.getErrors().get(0).getValue()).isInstanceOf(BootstrappingException.class);
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
verifyNoMoreInteractions(harness.getContext().getRetryPolicy(anyString()));
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerTest method should_complete_result_if_first_node_replies_immediately.
@Test
public void should_complete_result_if_first_node_replies_immediately() {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withResponse(node1, defaultFrameOf(singleRow())).build()) {
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
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(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();
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class QueryTraceFetcherTest method singlePageEventRows.
private CompletionStage<AsyncResultSet> singlePageEventRows() {
List<Row> rows = new ArrayList<>();
for (int i = 0; i < 3; i++) {
rows.add(eventRow(i));
}
AsyncResultSet rs = mock(AsyncResultSet.class);
when(rs.currentPage()).thenReturn(rows);
ExecutionInfo executionInfo = mock(ExecutionInfo.class);
when(executionInfo.getPagingState()).thenReturn(null);
when(rs.getExecutionInfo()).thenReturn(executionInfo);
return CompletableFuture.completedFuture(rs);
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ReactiveResultSetSubscription method toPage.
/**
* Converts the received result object into a {@link Page}.
*
* @param rs the result object to convert.
* @return a new page.
*/
@NonNull
private Page<ResultSetT> toPage(@NonNull ResultSetT rs) {
ExecutionInfo executionInfo = rs.getExecutionInfo();
Iterator<ReactiveRow> results = Iterators.transform(rs.currentPage().iterator(), row -> new DefaultReactiveRow(Objects.requireNonNull(row), executionInfo));
return new Page<>(results, rs.hasMorePages() ? rs::fetchNextPage : null);
}
Aggregations