Search in sources :

Example 31 with ExecutionInfo

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

the class ReactiveGraphRequestProcessorTest method should_complete_single_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
    when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
    when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
    GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (GraphRequestHandlerTestHarness harness = builder.build()) {
        DefaultSession session = harness.getSession();
        DefaultDriverContext context = harness.getContext();
        GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("g.V()");
        GraphBinaryModule graphBinaryModule = createGraphBinaryModule(context);
        when(asyncProcessor.getGraphBinaryModule()).thenReturn(graphBinaryModule);
        ReactiveGraphResultSet publisher = new ReactiveGraphRequestProcessor(asyncProcessor).process(graphStatement, session, context, "test");
        Flowable<ReactiveGraphNode> rowsPublisher = Flowable.fromPublisher(publisher).cache();
        rowsPublisher.subscribe();
        // emulate single page
        node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, true)));
        List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
        assertThat(rows).hasSize(10);
        checkResultSet(rows);
        Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
        assertThat(execInfosFlowable.toList().blockingGet()).hasSize(1).containsExactly(rows.get(0).getExecutionInfo());
    }
}
Also used : GraphRequestHandlerTestHarness(com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ReactiveGraphNode(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) ReactiveGraphResultSet(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphResultSet) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 32 with ExecutionInfo

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

the class AsyncPagingIterableWrapperTest method mockExecutionInfo.

private ExecutionInfo mockExecutionInfo() {
    ExecutionInfo executionInfo = mock(ExecutionInfo.class);
    when(executionInfo.getRequest()).thenAnswer(invocation -> statement);
    return executionInfo;
}
Also used : ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo)

Example 33 with ExecutionInfo

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

the class AsyncPagingIterableWrapperTest method should_wrap_result_set.

@Test
public void should_wrap_result_set() throws Exception {
    // Given
    // two pages of data:
    ExecutionInfo executionInfo1 = mockExecutionInfo();
    DefaultAsyncResultSet resultSet1 = new DefaultAsyncResultSet(columnDefinitions, executionInfo1, mockData(0, 5), session, context);
    DefaultAsyncResultSet resultSet2 = new DefaultAsyncResultSet(columnDefinitions, mockExecutionInfo(), mockData(5, 10), session, context);
    // chain them together:
    ByteBuffer mockPagingState = ByteBuffer.allocate(0);
    when(executionInfo1.getPagingState()).thenReturn(mockPagingState);
    Statement<?> mockNextStatement = mock(Statement.class);
    when(((Statement) statement).copy(mockPagingState)).thenReturn(mockNextStatement);
    when(session.executeAsync(mockNextStatement)).thenAnswer(invocation -> CompletableFuture.completedFuture(resultSet2));
    // When
    MappedAsyncPagingIterable<Integer> iterable1 = resultSet1.map(row -> row.getInt("i"));
    // Then
    for (int i = 0; i < 5; i++) {
        assertThat(iterable1.one()).isEqualTo(i);
        assertThat(iterable1.remaining()).isEqualTo(resultSet1.remaining()).isEqualTo(4 - i);
    }
    assertThat(iterable1.hasMorePages()).isTrue();
    MappedAsyncPagingIterable<Integer> iterable2 = iterable1.fetchNextPage().toCompletableFuture().get();
    for (int i = 5; i < 10; i++) {
        assertThat(iterable2.one()).isEqualTo(i);
        assertThat(iterable2.remaining()).isEqualTo(resultSet2.remaining()).isEqualTo(9 - i);
    }
    assertThat(iterable2.hasMorePages()).isFalse();
}
Also used : DefaultAsyncResultSet(com.datastax.oss.driver.internal.core.cql.DefaultAsyncResultSet) Statement(com.datastax.oss.driver.api.core.cql.Statement) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 34 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 35 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)

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