Search in sources :

Example 16 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class ContinuousCqlRequestReactiveProcessorTest 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()) {
        DefaultSession session = harness.getSession();
        InternalDriverContext context = harness.getContext();
        ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
        Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
        rowsPublisher.subscribe();
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
        List<ReactiveRow> rows = rowsPublisher.toList().blockingGet();
        assertThat(rows).hasSize(20);
        ReactiveRow first = rows.get(0);
        ExecutionInfo firstExecutionInfo = first.getExecutionInfo();
        assertThat(firstExecutionInfo.getCoordinator()).isEqualTo(node1);
        assertThat(firstExecutionInfo.getErrors()).isEmpty();
        assertThat(firstExecutionInfo.getIncomingPayload()).isEmpty();
        assertThat(firstExecutionInfo.getPagingState()).isNotNull();
        assertThat(firstExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(firstExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(firstExecutionInfo.getWarnings()).isEmpty();
        ReactiveRow inSecondPage = rows.get(10);
        ExecutionInfo secondExecutionInfo = inSecondPage.getExecutionInfo();
        assertThat(secondExecutionInfo.getCoordinator()).isEqualTo(node1);
        assertThat(secondExecutionInfo.getErrors()).isEmpty();
        assertThat(secondExecutionInfo.getIncomingPayload()).isEmpty();
        assertThat(secondExecutionInfo.getPagingState()).isNull();
        assertThat(secondExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(secondExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(secondExecutionInfo.getWarnings()).isEmpty();
        Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
        assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(firstExecutionInfo, secondExecutionInfo);
        Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
        assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(first.getColumnDefinitions());
        Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
        assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(first.wasApplied());
    }
}
Also used : ContinuousCqlRequestAsyncProcessor(com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) ContinuousReactiveResultSet(com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 17 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class GraphResultSetTestBase method mockPage.

/**
 * Mocks an async result set where column 0 has type INT, with rows with the provided data.
 */
protected AsyncGraphResultSet mockPage(boolean nextPage, Integer... data) {
    AsyncGraphResultSet page = mock(AsyncGraphResultSet.class);
    ExecutionInfo executionInfo = mock(ExecutionInfo.class);
    when(page.getRequestExecutionInfo()).thenReturn(executionInfo);
    if (nextPage) {
        when(page.hasMorePages()).thenReturn(true);
        when(page.fetchNextPage()).thenReturn(spy(new CompletableFuture<>()));
    } else {
        when(page.hasMorePages()).thenReturn(false);
        when(page.fetchNextPage()).thenThrow(new IllegalStateException());
    }
    // Emulate DefaultAsyncResultSet's internals (this is a bit sketchy, maybe it would be better
    // to use real DefaultAsyncResultSet instances)
    Queue<Integer> queue = Lists.newLinkedList(Arrays.asList(data));
    CountingIterator<GraphNode> iterator = new CountingIterator<GraphNode>(queue.size()) {

        @Override
        protected GraphNode computeNext() {
            Integer index = queue.poll();
            return (index == null) ? endOfData() : mockRow(index);
        }
    };
    when(page.currentPage()).thenReturn(() -> iterator);
    when(page.remaining()).thenAnswer(invocation -> iterator.remaining());
    return page;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode)

Example 18 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class ReactiveResultSetSubscriptionTest method should_report_error_on_intermediary_page.

@Test
public void should_report_error_on_intermediary_page() {
    CompletableFuture<AsyncResultSet> future1 = new CompletableFuture<>();
    CompletableFuture<AsyncResultSet> future2 = new CompletableFuture<>();
    MockAsyncResultSet page1 = new MockAsyncResultSet(3, future2);
    TestSubscriber<ReactiveRow> mainSubscriber = new TestSubscriber<>();
    TestSubscriber<ColumnDefinitions> colDefsSubscriber = new TestSubscriber<>();
    TestSubscriber<ExecutionInfo> execInfosSubscriber = new TestSubscriber<>();
    TestSubscriber<Boolean> wasAppliedSubscriber = new TestSubscriber<>();
    ReactiveResultSetSubscription<AsyncResultSet> subscription = new ReactiveResultSetSubscription<>(mainSubscriber, colDefsSubscriber, execInfosSubscriber, wasAppliedSubscriber);
    mainSubscriber.onSubscribe(subscription);
    subscription.start(() -> future1);
    future1.complete(page1);
    future2.completeExceptionally(new UnavailableException(null, null, 0, 0));
    mainSubscriber.awaitTermination();
    assertThat(mainSubscriber.getElements()).extracting("row").isEqualTo(page1.currentPage());
    assertThat(mainSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
    // colDefsSubscriber completed normally when page1 arrived
    assertThat(colDefsSubscriber.getError()).isNull();
    assertThat(colDefsSubscriber.getElements()).hasSize(1).containsExactly(page1.getColumnDefinitions());
    // execInfosSubscriber completed with error, but should have emitted 1 item for page1
    assertThat(execInfosSubscriber.getElements()).hasSize(1).containsExactly(page1.getExecutionInfo());
    assertThat(execInfosSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
    // colDefsSubscriber completed normally when page1 arrived
    assertThat(wasAppliedSubscriber.getElements()).hasSize(1).containsExactly(true);
    assertThat(wasAppliedSubscriber.getError()).isNull();
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) UnavailableException(com.datastax.oss.driver.api.core.servererrors.UnavailableException) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 19 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.

the class ReactiveResultSetSubscriptionTest method should_report_error_on_first_page.

@Test
public void should_report_error_on_first_page() {
    CompletableFuture<AsyncResultSet> future1 = new CompletableFuture<>();
    TestSubscriber<ReactiveRow> mainSubscriber = new TestSubscriber<>();
    TestSubscriber<ColumnDefinitions> colDefsSubscriber = new TestSubscriber<>();
    TestSubscriber<ExecutionInfo> execInfosSubscriber = new TestSubscriber<>();
    TestSubscriber<Boolean> wasAppliedSubscriber = new TestSubscriber<>();
    ReactiveResultSetSubscription<AsyncResultSet> subscription = new ReactiveResultSetSubscription<>(mainSubscriber, colDefsSubscriber, execInfosSubscriber, wasAppliedSubscriber);
    mainSubscriber.onSubscribe(subscription);
    subscription.start(() -> future1);
    future1.completeExceptionally(new UnavailableException(null, null, 0, 0));
    mainSubscriber.awaitTermination();
    assertThat(mainSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
    assertThat(colDefsSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
    assertThat(execInfosSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
    assertThat(wasAppliedSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) UnavailableException(com.datastax.oss.driver.api.core.servererrors.UnavailableException) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CompletableFuture(java.util.concurrent.CompletableFuture) Test(org.junit.Test)

Example 20 with ExecutionInfo

use of com.datastax.oss.driver.api.core.cql.ExecutionInfo 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)

Aggregations

ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)50 Test (org.junit.Test)36 Row (com.datastax.oss.driver.api.core.cql.Row)20 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)13 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)8 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 CompletableFuture (java.util.concurrent.CompletableFuture)6 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)5 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)5 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)5 ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 EmptyColumnDefinitions (com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions)4