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 GraphExecutionInfoConverterTest method should_convert_from_graph_execution_info.
@Test
public void should_convert_from_graph_execution_info() {
// given
com.datastax.dse.driver.api.core.graph.GraphExecutionInfo graphExecutionInfo = mock(com.datastax.dse.driver.api.core.graph.GraphExecutionInfo.class);
when(graphExecutionInfo.getStatement()).thenAnswer(args -> request);
when(graphExecutionInfo.getCoordinator()).thenReturn(node);
when(graphExecutionInfo.getSpeculativeExecutionCount()).thenReturn(42);
when(graphExecutionInfo.getSuccessfulExecutionIndex()).thenReturn(10);
when(graphExecutionInfo.getErrors()).thenReturn(errors);
when(graphExecutionInfo.getWarnings()).thenReturn(warnings);
when(graphExecutionInfo.getIncomingPayload()).thenReturn(payload);
// when
ExecutionInfo executionInfo = GraphExecutionInfoConverter.convert(graphExecutionInfo);
// then
assertThat(executionInfo.getRequest()).isSameAs(request);
assertThatThrownBy(executionInfo::getStatement).isInstanceOf(ClassCastException.class);
assertThat(executionInfo.getCoordinator()).isSameAs(node);
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(42);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(10);
assertThat(executionInfo.getErrors()).isEqualTo(errors);
assertThat(executionInfo.getWarnings()).isEqualTo(warnings);
assertThat(executionInfo.getIncomingPayload()).isEqualTo(payload);
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.isSchemaInAgreement()).isTrue();
assertThat(executionInfo.getQueryTraceAsync()).isCompletedExceptionally();
assertThatThrownBy(executionInfo::getQueryTrace).isInstanceOf(IllegalStateException.class).hasMessage("Tracing was disabled for this request");
assertThat(executionInfo.getResponseSizeInBytes()).isEqualTo(-1L);
assertThat(executionInfo.getCompressedResponseSizeInBytes()).isEqualTo(-1L);
}
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 ContinuousCqlRequestReactiveProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
List<ReactiveRow> rows = Flowable.fromPublisher(publisher).toList().blockingGet();
assertThat(rows).hasSize(1);
ReactiveRow row = rows.get(0);
assertThat(row.getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = row.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(executionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(row.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(row.wasApplied());
}
}
Aggregations