Search in sources :

Example 6 with ContinuousAsyncResultSet

use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet 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());
    }
}
Also used : PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Test(org.junit.Test)

Example 7 with ContinuousAsyncResultSet

use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.

the class ContinuousCqlRequestHandlerTest method should_fail_if_no_node_available.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_fail_if_no_node_available(DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).build()) {
        CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isFailed(error -> assertThat(error).isInstanceOf(NoNodeAvailableException.class));
    }
}
Also used : RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) NoNodeAvailableException(com.datastax.oss.driver.api.core.NoNodeAvailableException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 8 with ContinuousAsyncResultSet

use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.

the class ContinuousCqlRequestHandlerRetryTest 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, DseProtocolVersion version) {
    RequestHandlerTestHarness.Builder harnessBuilder = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence);
    failureScenario.mockRequestError(harnessBuilder, node1);
    try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
        failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.IGNORE);
        ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test");
        CompletionStage<ContinuousAsyncResultSet> resultSetFuture = handler.handle();
        assertThat(handler.getState()).isEqualTo(-1);
        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);
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.errorMetric), anyString());
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.IGNORES), anyString());
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.ignoreMetric), anyString());
            Mockito.verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
            Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
        });
    }
}
Also used : RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) 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 9 with ContinuousAsyncResultSet

use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.

the class ContinuousCqlRequestHandlerRetryTest method should_always_rethrow_query_validation_error.

@Test
@UseDataProvider("allIdempotenceConfigs")
public void should_always_rethrow_query_validation_error(boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.INVALID, "mock message"))).build()) {
        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(InvalidQueryException.class).hasMessage("mock message");
            Mockito.verifyNoMoreInteractions(harness.getContext().getRetryPolicy(anyString()));
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.OTHER_ERRORS), anyString());
            Mockito.verify(nodeMetricUpdater1).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
            Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
        });
    }
}
Also used : RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) Error(com.datastax.oss.protocol.internal.response.Error) ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) InvalidQueryException(com.datastax.oss.driver.api.core.servererrors.InvalidQueryException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 10 with ContinuousAsyncResultSet

use of com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet in project java-driver by datastax.

the class ContinuousCqlRequestHandlerRetryTest method should_try_next_node_if_idempotent_and_retry_policy_decides_so.

@Test
@UseDataProvider("failureAndIdempotent")
public void should_try_next_node_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
    RequestHandlerTestHarness.Builder harnessBuilder = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence);
    failureScenario.mockRequestError(harnessBuilder, node1);
    harnessBuilder.withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow()));
    try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
        failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.RETRY_NEXT);
        ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test");
        CompletionStage<ContinuousAsyncResultSet> resultSetFuture = handler.handle();
        assertThat(handler.getState()).isEqualTo(-1);
        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);
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.errorMetric), anyString());
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.RETRIES), anyString());
            Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.retryMetric), anyString());
            Mockito.verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
            Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
        });
    }
}
Also used : RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) 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)

Aggregations

ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)28 Test (org.junit.Test)26 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)23 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)20 Row (com.datastax.oss.driver.api.core.cql.Row)10 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)9 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)8 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)2 ServerError (com.datastax.oss.driver.api.core.servererrors.ServerError)2 Request (com.datastax.oss.driver.api.core.session.Request)2 Session (com.datastax.oss.driver.api.core.session.Session)2 LoadBalancingPolicyWrapper (com.datastax.oss.driver.internal.core.metadata.LoadBalancingPolicyWrapper)2 CapturedTimeout (com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout)2 Prepare (com.datastax.oss.protocol.internal.request.Prepare)2 Query (com.datastax.oss.protocol.internal.request.Query)2 Error (com.datastax.oss.protocol.internal.response.Error)2 InOrder (org.mockito.InOrder)2 Revise (com.datastax.dse.protocol.internal.request.Revise)1 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)1