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();
}
}
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());
}
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;
}
Aggregations