Search in sources :

Example 1 with ContinuousAsyncResultSet

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

@Test
public void should_create_result_set_from_single_page() {
    // Given
    ContinuousAsyncResultSet page1 = mockPage(false, 0, 1, 2);
    // When
    ResultSet resultSet = new DefaultContinuousResultSet(page1);
    // Then
    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()).isFalse();
}
Also used : ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test)

Example 2 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestHandlerReprepareTest method should_try_next_node_when_prepare_fails_with_recoverable_error.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_try_next_node_when_prepare_fails_with_recoverable_error(DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withResponse(node1, defaultFrameOf(unprepared)).withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow())).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(recoverable));
            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());
        // should have tried the next host
        verify(harness.getChannel(node2)).write(any(Query.class), anyBoolean(), anyMap(), any());
        assertThat(handler.getState()).isEqualTo(-1);
        assertThatStage(page1Future).isSuccess(rs -> {
            assertThat(rs.currentPage()).hasSize(1);
            assertThat(rs.hasMorePages()).isFalse();
            assertThat(rs.getExecutionInfo().getCoordinator()).isEqualTo(node2);
            assertThat(rs.getExecutionInfo().getErrors()).hasSize(1).allSatisfy(entry -> {
                assertThat(entry.getKey()).isEqualTo(node1);
                assertThat(entry.getValue()).isInstanceOf(UnexpectedResponseException.class).hasMessageContaining(recoverable.toString());
            });
        });
    }
}
Also used : Query(com.datastax.oss.protocol.internal.request.Query) 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) UnexpectedResponseException(com.datastax.oss.driver.internal.core.adminrequest.UnexpectedResponseException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 3 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestHandlerTest method should_time_out_if_other_page_takes_too_long.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_time_out_if_other_page_takes_too_long(DseProtocolVersion version) throws Exception {
    RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (RequestHandlerTestHarness harness = builder.build()) {
        CompletionStage<ContinuousAsyncResultSet> page1Future = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        // mark the initial request as successful, which should schedule a timeout for the first page
        node1Behavior.setWriteSuccess();
        CapturedTimeout page1Timeout = harness.nextScheduledTimeout();
        assertThat(page1Timeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(TIMEOUT_FIRST_PAGE.toNanos());
        // the server replies with page 1, the corresponding timeout should be cancelled
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
        assertThat(page1Timeout.isCancelled()).isTrue();
        // request page 2, the queue is empty so this should request more pages and schedule another
        // timeout
        ContinuousAsyncResultSet page1 = CompletableFutures.getUninterruptibly(page1Future);
        CompletionStage<ContinuousAsyncResultSet> page2Future = page1.fetchNextPage();
        CapturedTimeout page2Timeout = harness.nextScheduledTimeout();
        assertThat(page2Timeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(TIMEOUT_OTHER_PAGES.toNanos());
        page2Timeout.task().run(page2Timeout);
        assertThatStage(page2Future).isFailed(t -> assertThat(t).isInstanceOf(DriverTimeoutException.class).hasMessageContaining("Timed out waiting for page 2"));
    }
}
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) CapturedTimeout(com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestHandlerTest method should_time_out_if_first_page_takes_too_long.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_time_out_if_first_page_takes_too_long(DseProtocolVersion version) throws Exception {
    RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (RequestHandlerTestHarness harness = builder.build()) {
        CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        // mark the initial request as successful, which should schedule a timeout for the first page
        node1Behavior.setWriteSuccess();
        CapturedTimeout page1Timeout = harness.nextScheduledTimeout();
        assertThat(page1Timeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(TIMEOUT_FIRST_PAGE.toNanos());
        page1Timeout.task().run(page1Timeout);
        assertThatStage(resultSetFuture).isFailed(t -> assertThat(t).isInstanceOf(DriverTimeoutException.class).hasMessageContaining("Timed out waiting for page 1"));
    }
}
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) CapturedTimeout(com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with ContinuousAsyncResultSet

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

the class ContinuousCqlRequestHandlerTest method should_cancel_future_if_session_cancelled.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_cancel_future_if_session_cancelled(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)));
        // will be discarded
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, false)));
        ContinuousAsyncResultSet page1 = CompletableFutures.getUninterruptibly(page1Future);
        page1.cancel();
        assertThat(handler.getState()).isEqualTo(-2);
        assertThat(page1.fetchNextPage()).isCancelled();
    }
}
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) 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