Search in sources :

Example 6 with CountingIterator

use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.

the class GraphPagingIT method should_cancel_result_set.

@Test
public void should_cancel_result_set() {
    // given
    DriverExecutionProfile profile = enableGraphPaging().withInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES, 1).withInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE, 10);
    // when
    GraphStatement statement = ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile);
    MultiPageGraphResultSet results = (MultiPageGraphResultSet) SESSION_RULE.session().execute(statement);
    assertThat(((MultiPageGraphResultSet.RowIterator) results.iterator()).isCancelled()).isFalse();
    assertThat(((CountingIterator) results.iterator()).remaining()).isEqualTo(10);
    results.cancel();
    assertThat(((MultiPageGraphResultSet.RowIterator) results.iterator()).isCancelled()).isTrue();
    assertThat(((CountingIterator) results.iterator()).remaining()).isEqualTo(10);
    for (int i = 0; i < 10; i++) {
        results.one();
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) MultiPageGraphResultSet(com.datastax.dse.driver.internal.core.graph.MultiPageGraphResultSet) CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) Test(org.junit.Test)

Example 7 with CountingIterator

use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.

the class GraphPagingIT method synchronous_options_with_paging_disabled_should_fallback_to_single_page.

@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void synchronous_options_with_paging_disabled_should_fallback_to_single_page(Options options) {
    // given
    DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.DISABLED);
    if (options.sizeInBytes) {
        // Page sizes in bytes are not supported with graph queries
        return;
    }
    // when
    GraphResultSet result = SESSION_RULE.session().execute(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
    // then
    List<GraphNode> nodes = result.all();
    assertThat(((CountingIterator) result.iterator()).remaining()).isZero();
    assertThat(nodes).hasSize(100);
    for (int i = 1; i <= nodes.size(); i++) {
        GraphNode node = nodes.get(i - 1);
        assertThat(node.asString()).isEqualTo("user" + i);
    }
    assertThat(result.getRequestExecutionInfo()).isNotNull();
    assertThat(result.getRequestExecutionInfo().getCoordinator().getEndPoint().resolve()).isEqualTo(firstCcmNode());
    validateMetrics(SESSION_RULE.session());
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) MultiPageGraphResultSet(com.datastax.dse.driver.internal.core.graph.MultiPageGraphResultSet) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 8 with CountingIterator

use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.

the class DefaultContinuousResultSetTest method mockPage.

private static ContinuousAsyncResultSet mockPage(boolean nextPage, Integer... data) {
    ContinuousAsyncResultSet page = Mockito.mock(ContinuousAsyncResultSet.class);
    ColumnDefinitions columnDefinitions = Mockito.mock(ColumnDefinitions.class);
    Mockito.when(page.getColumnDefinitions()).thenReturn(columnDefinitions);
    ExecutionInfo executionInfo = Mockito.mock(ExecutionInfo.class);
    Mockito.when(page.getExecutionInfo()).thenReturn(executionInfo);
    if (nextPage) {
        Mockito.when(page.hasMorePages()).thenReturn(true);
        Mockito.when(page.fetchNextPage()).thenReturn(Mockito.spy(new CompletableFuture<>()));
    } else {
        Mockito.when(page.hasMorePages()).thenReturn(false);
        Mockito.when(page.fetchNextPage()).thenThrow(new IllegalStateException());
    }
    Iterator<Integer> rows = Arrays.asList(data).iterator();
    CountingIterator<Row> iterator = new CountingIterator<Row>(data.length) {

        @Override
        protected Row computeNext() {
            return rows.hasNext() ? mockRow(rows.next()) : endOfData();
        }
    };
    Mockito.when(page.currentPage()).thenReturn(() -> iterator);
    Mockito.when(page.remaining()).thenAnswer(invocation -> iterator.remaining());
    return page;
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) CompletableFuture(java.util.concurrent.CompletableFuture) CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) 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)

Aggregations

CountingIterator (com.datastax.oss.driver.internal.core.util.CountingIterator)8 MultiPageGraphResultSet (com.datastax.dse.driver.internal.core.graph.MultiPageGraphResultSet)4 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)4 Test (org.junit.Test)4 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)3 Row (com.datastax.oss.driver.api.core.cql.Row)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)2 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)1 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)1 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1 DseRowsMetadata (com.datastax.dse.protocol.internal.response.result.DseRowsMetadata)1 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)1 DefaultRow (com.datastax.oss.driver.internal.core.cql.DefaultRow)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1