Search in sources :

Example 11 with ContinuousAsyncResultSet

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_idempotent_and_retry_policy_decides_so.

@Test
@UseDataProvider("failureAndIdempotent")
public void should_rethrow_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.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);
            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);
        });
    }
}
Also used : RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 12 with ContinuousAsyncResultSet

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

the class DriverBlockHoundIntegrationCcmIT method should_not_detect_blocking_call_with_continuous_paging_when_timeout.

/**
 * Copied from com.datastax.dse.driver.api.core.cql.continuous.ContinuousPagingIT.
 */
@Test
public void should_not_detect_blocking_call_with_continuous_paging_when_timeout() throws Exception {
    CqlSession session = SESSION_RULE.session();
    SimpleStatement statement = SimpleStatement.newInstance("SELECT v from test where k=?", KEY);
    // Throttle server at a page per second and set client timeout much lower so that the client
    // will experience a timeout.
    // Note that this might not be perfect if there are pauses in the JVM and the timeout
    // doesn't fire soon enough.
    DriverExecutionProfile profile = session.getContext().getConfig().getDefaultProfile().withInt(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE, 10).withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND, 1).withDuration(DseDriverOption.CONTINUOUS_PAGING_TIMEOUT_OTHER_PAGES, Duration.ofMillis(100));
    CompletionStage<ContinuousAsyncResultSet> future = session.executeContinuouslyAsync(statement.setExecutionProfile(profile));
    ContinuousAsyncResultSet pagingResult = CompletableFutures.getUninterruptibly(future);
    try {
        pagingResult.fetchNextPage().toCompletableFuture().get();
        fail("Expected a timeout");
    } catch (ExecutionException e) {
        assertThat(e.getCause()).isInstanceOf(DriverTimeoutException.class).hasMessageContaining("Timed out waiting for page 2");
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) ExecutionException(java.util.concurrent.ExecutionException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 13 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestSyncProcessor method process.

@Override
public ContinuousResultSet process(Statement<?> request, DefaultSession session, InternalDriverContext context, String sessionLogPrefix) {
    BlockingOperation.checkNotDriverThread();
    ContinuousAsyncResultSet firstPage = CompletableFutures.getUninterruptibly(asyncProcessor.process(request, session, context, sessionLogPrefix));
    return new DefaultContinuousResultSet(firstPage);
}
Also used : ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)

Example 14 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestHandlerReprepareTest method should_abort_when_prepare_fails_with_unrecoverable_error.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_abort_when_prepare_fails_with_unrecoverable_error(DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withResponse(node1, defaultFrameOf(unprepared)).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(unrecoverable));
            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());
        assertThat(handler.getState()).isEqualTo(-2);
        assertThat(page1Future).isCompletedExceptionally();
        Throwable t = catchThrowable(() -> page1Future.toCompletableFuture().get());
        assertThat(t).hasRootCauseInstanceOf(SyntaxError.class).hasMessageContaining("bad query");
    }
}
Also used : Query(com.datastax.oss.protocol.internal.request.Query) SyntaxError(com.datastax.oss.driver.api.core.servererrors.SyntaxError) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) Prepare(com.datastax.oss.protocol.internal.request.Prepare) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 15 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestHandlerTest method should_complete_multi_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(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)));
        assertThatStage(page1Future).isSuccess(page1 -> {
            assertThat(page1.hasMorePages()).isTrue();
            assertThat(page1.pageNumber()).isEqualTo(1);
            Iterator<Row> rows = page1.currentPage().iterator();
            assertThat(rows.hasNext()).isTrue();
            assertThat(rows).toIterable().hasSize(10);
            ExecutionInfo executionInfo = page1.getExecutionInfo();
            assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
            assertThat(executionInfo.getErrors()).isEmpty();
            assertThat(executionInfo.getIncomingPayload()).isEmpty();
            assertThat(executionInfo.getPagingState()).isNotNull();
            assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
            assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
            assertThat(executionInfo.getWarnings()).isEmpty();
        });
        ContinuousAsyncResultSet page1 = CompletableFutures.getCompleted(page1Future);
        assertThat(handler.getPendingResult()).isNull();
        CompletionStage<ContinuousAsyncResultSet> page2Future = page1.fetchNextPage();
        assertThat(handler.getPendingResult()).isNotNull();
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
        assertThatStage(page2Future).isSuccess(page2 -> {
            assertThat(page2.hasMorePages()).isFalse();
            assertThat(page2.pageNumber()).isEqualTo(2);
            Iterator<Row> rows = page2.currentPage().iterator();
            assertThat(rows.hasNext()).isTrue();
            assertThat(rows).toIterable().hasSize(10);
            ExecutionInfo executionInfo = page2.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 : 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) 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