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