use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ContinuousCqlRequestHandlerRetryTest method should_try_next_node_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_try_next_node_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement, DseProtocolVersion version) {
RequestHandlerTestHarness.Builder harnessBuilder = continuousHarnessBuilder().withProtocolVersion(version).withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
harnessBuilder.withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow()));
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.RETRY_NEXT);
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = handler.handle();
assertThat(handler.getState()).isEqualTo(-1);
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows.next().getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node2);
assertThat(executionInfo.getErrors()).hasSize(1);
assertThat(executionInfo.getErrors().get(0).getKey()).isEqualTo(node1);
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.errorMetric), anyString());
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(DefaultNodeMetric.RETRIES), anyString());
Mockito.verify(nodeMetricUpdater1).incrementCounter(eq(failureScenario.retryMetric), anyString());
Mockito.verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), anyString(), anyLong(), eq(TimeUnit.NANOSECONDS));
Mockito.verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_return_paged_results.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_return_paged_results(GraphProtocol graphProtocol) throws IOException {
String profileName = "test-graph";
when(nodeMetricUpdater1.isEnabled(DseNodeMetric.GRAPH_MESSAGES, profileName)).thenReturn(true);
GraphBinaryModule module = createGraphBinaryModule(mockContext);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol);
PoolBehavior node1Behavior = builder.customBehavior(node);
try (RequestHandlerTestHarness harness = builder.build()) {
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName(profileName);
ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", module, new GraphSupportChecker());
// send the initial request
CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, module, 1, false)));
assertThatStage(page1Future).isSuccess(page1 -> {
assertThat(page1.hasMorePages()).isTrue();
assertThat(page1.currentPage()).hasSize(10).allMatch(GraphNode::isVertex);
ExecutionInfo executionInfo = page1.getRequestExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
AsyncGraphResultSet page1 = CompletableFutures.getCompleted(page1Future);
CompletionStage<AsyncGraphResultSet> page2Future = page1.fetchNextPage();
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, module, 2, true)));
assertThatStage(page2Future).isSuccess(page2 -> {
assertThat(page2.hasMorePages()).isFalse();
assertThat(page2.currentPage()).hasSize(10).allMatch(GraphNode::isVertex);
ExecutionInfo executionInfo = page2.getRequestExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
validateMetrics(profileName, harness);
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class QueryTraceFetcherTest method multiPageEventRows2.
private CompletionStage<AsyncResultSet> multiPageEventRows2() {
AsyncResultSet rs = mock(AsyncResultSet.class);
ImmutableList<Row> rows = ImmutableList.of(eventRow(1));
when(rs.currentPage()).thenReturn(rows);
ExecutionInfo executionInfo = mock(ExecutionInfo.class);
when(executionInfo.getPagingState()).thenReturn(null);
when(rs.getExecutionInfo()).thenReturn(executionInfo);
return CompletableFuture.completedFuture(rs);
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class QueryTraceFetcherTest method multiPageEventRows1.
private CompletionStage<AsyncResultSet> multiPageEventRows1() {
AsyncResultSet rs = mock(AsyncResultSet.class);
ImmutableList<Row> rows = ImmutableList.of(eventRow(0));
when(rs.currentPage()).thenReturn(rows);
ExecutionInfo executionInfo = mock(ExecutionInfo.class);
when(executionInfo.getPagingState()).thenReturn(PAGING_STATE);
when(rs.getExecutionInfo()).thenReturn(executionInfo);
return CompletableFuture.completedFuture(rs);
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo 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;
}
Aggregations