Search in sources :

Example 41 with ExecutionInfo

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);
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 42 with ExecutionInfo

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()));
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) Error(com.datastax.oss.protocol.internal.response.Error) ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 43 with ExecutionInfo

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();
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test)

Example 44 with ExecutionInfo

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);
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) ArrayList(java.util.ArrayList) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row)

Example 45 with ExecutionInfo

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);
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)64 Test (org.junit.Test)36 Row (com.datastax.oss.driver.api.core.cql.Row)23 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)17 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)13 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)12 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)12 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)9 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)9 CompletableFuture (java.util.concurrent.CompletableFuture)9 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)8 CqlSession (com.datastax.oss.driver.api.core.CqlSession)7 Test (org.junit.jupiter.api.Test)7 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)6 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)6 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)6 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)5 ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4