use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.
the class ContinuousCqlRequestHandler method createResultSet.
@NonNull
@Override
protected DefaultContinuousAsyncResultSet createResultSet(@NonNull Statement<?> statement, @NonNull Rows rows, @NonNull ExecutionInfo executionInfo, @NonNull ColumnDefinitions columnDefinitions) {
Queue<List<ByteBuffer>> data = rows.getData();
CountingIterator<Row> iterator = new CountingIterator<Row>(data.size()) {
@Override
protected Row computeNext() {
List<ByteBuffer> rowData = data.poll();
return (rowData == null) ? endOfData() : new DefaultRow(columnDefinitions, rowData, context);
}
};
DseRowsMetadata metadata = (DseRowsMetadata) rows.getMetadata();
return new DefaultContinuousAsyncResultSet(iterator, columnDefinitions, metadata.continuousPageNumber, !metadata.isLastContinuousPage, executionInfo, this);
}
use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.
the class GraphPagingIT method synchronous_paging_with_options_when_auto.
@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void synchronous_paging_with_options_when_auto(Options options) {
// given
DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.AUTO);
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(options.expectedRows);
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());
assertIfMultiPage(result, options.expectedPages);
validateMetrics(SESSION_RULE.session());
}
use of com.datastax.oss.driver.internal.core.util.CountingIterator 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;
}
use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.
the class ResultSetTestBase method mockPage.
/**
* Mocks an async result set where column 0 has type INT, with rows with the provided data.
*/
protected AsyncResultSet mockPage(boolean nextPage, Integer... data) {
AsyncResultSet page = mock(AsyncResultSet.class);
ColumnDefinitions columnDefinitions = mock(ColumnDefinitions.class);
when(page.getColumnDefinitions()).thenReturn(columnDefinitions);
ExecutionInfo executionInfo = mock(ExecutionInfo.class);
when(page.getExecutionInfo()).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<Row> iterator = new CountingIterator<Row>(queue.size()) {
@Override
protected Row 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;
}
use of com.datastax.oss.driver.internal.core.util.CountingIterator in project java-driver by datastax.
the class GraphPagingIT method synchronous_paging_with_options.
@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void synchronous_paging_with_options(Options options) {
// given
DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.ENABLED);
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(options.expectedRows);
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());
assertIfMultiPage(result, options.expectedPages);
validateMetrics(SESSION_RULE.session());
}
Aggregations