use of com.datastax.oss.driver.api.core.tracker.RequestTracker in project java-driver by datastax.
the class CqlRequestHandlerTrackerTest method should_invoke_request_tracker.
@Test
public void should_invoke_request_tracker() {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(true).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
RequestTracker requestTracker = mock(RequestTracker.class);
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
verify(requestTracker).onNodeError(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), any(BootstrappingException.class), anyLong(), any(DriverExecutionProfile.class), eq(node1), any(String.class));
verify(requestTracker).onNodeSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), any(String.class));
verify(requestTracker).onSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), any(String.class));
verifyNoMoreInteractions(requestTracker);
});
}
}
use of com.datastax.oss.driver.api.core.tracker.RequestTracker in project java-driver by datastax.
the class CqlRequestHandlerTrackerTest method should_not_invoke_noop_request_tracker.
@Test
public void should_not_invoke_noop_request_tracker() {
try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(true).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
RequestTracker requestTracker = spy(new NoopRequestTracker(harness.getContext()));
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> verifyNoMoreInteractions(requestTracker));
}
}
use of com.datastax.oss.driver.api.core.tracker.RequestTracker in project java-driver by datastax.
the class DefaultDriverContext method buildRequestTracker.
protected RequestTracker buildRequestTracker(RequestTracker requestTrackerFromBuilder) {
List<RequestTracker> trackers = new ArrayList<>();
if (requestTrackerFromBuilder != null) {
trackers.add(requestTrackerFromBuilder);
}
for (LoadBalancingPolicy lbp : this.getLoadBalancingPolicies().values()) {
lbp.getRequestTracker().ifPresent(trackers::add);
}
DefaultDriverOption newOption = DefaultDriverOption.REQUEST_TRACKER_CLASSES;
@SuppressWarnings("deprecation") DefaultDriverOption legacyOption = DefaultDriverOption.REQUEST_TRACKER_CLASS;
DriverExecutionProfile profile = config.getDefaultProfile();
if (profile.isDefined(newOption)) {
trackers.addAll(Reflection.buildFromConfigList(this, newOption, RequestTracker.class, "com.datastax.oss.driver.internal.core.tracker"));
}
if (profile.isDefined(legacyOption)) {
LOG.warn("Option {} has been deprecated and will be removed in a future release; please use option {} instead.", legacyOption, newOption);
Reflection.buildFromConfig(this, legacyOption, RequestTracker.class, "com.datastax.oss.driver.internal.core.tracker").ifPresent(trackers::add);
}
if (trackers.isEmpty()) {
return new NoopRequestTracker(this);
} else if (trackers.size() == 1) {
return trackers.get(0);
} else {
return new MultiplexingRequestTracker(trackers);
}
}
use of com.datastax.oss.driver.api.core.tracker.RequestTracker in project java-driver by datastax.
the class GraphRequestHandlerTest method should_invoke_request_tracker_and_update_metrics.
@Test
@UseDataProvider("dseVersionsWithDefaultGraphProtocol")
public void should_invoke_request_tracker_and_update_metrics(GraphProtocol graphProtocol, Version dseVersion) throws IOException {
when(nodeMetricUpdater1.isEnabled(DseNodeMetric.GRAPH_MESSAGES, DriverExecutionProfile.DEFAULT_NAME)).thenReturn(true);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol).withDseVersionInMetadata(dseVersion);
PoolBehavior node1Behavior = builder.customBehavior(node);
GraphRequestHandlerTestHarness harness = builder.build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
GraphSupportChecker graphSupportChecker = mock(GraphSupportChecker.class);
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
GraphRequestAsyncProcessor p = Mockito.spy(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker));
when(p.getGraphBinaryModule()).thenReturn(module);
RequestTracker requestTracker = mock(RequestTracker.class);
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery");
node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
GraphResultSet grs = new GraphRequestSyncProcessor(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker)).process(graphStatement, harness.getSession(), harness.getContext(), "test-graph");
List<GraphNode> nodes = grs.all();
assertThat(nodes.size()).isEqualTo(1);
GraphNode graphNode = nodes.get(0);
assertThat(graphNode.isVertex()).isTrue();
Vertex actual = graphNode.asVertex();
assertThat(actual.label()).isEqualTo("person");
assertThat(actual.id()).isEqualTo(1);
if (!graphProtocol.isGraphBinary()) {
// GraphBinary does not encode properties regardless of whether they are present in the
// parent element or not :/
assertThat(actual.property("name").id()).isEqualTo(11);
assertThat(actual.property("name").value()).isEqualTo("marko");
}
verify(requestTracker).onSuccess(eq(graphStatement), anyLong(), any(DriverExecutionProfile.class), eq(node), matches(LOG_PREFIX_PER_REQUEST));
verify(requestTracker).onNodeSuccess(eq(graphStatement), anyLong(), any(DriverExecutionProfile.class), eq(node), matches(LOG_PREFIX_PER_REQUEST));
verifyNoMoreInteractions(requestTracker);
verify(nodeMetricUpdater1).isEnabled(DseNodeMetric.GRAPH_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).updateTimer(eq(DseNodeMetric.GRAPH_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(nodeMetricUpdater1);
verify(harness.getSession().getMetricUpdater()).isEnabled(DseSessionMetric.GRAPH_REQUESTS, DriverExecutionProfile.DEFAULT_NAME);
verify(harness.getSession().getMetricUpdater()).updateTimer(eq(DseSessionMetric.GRAPH_REQUESTS), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(harness.getSession().getMetricUpdater());
}
use of com.datastax.oss.driver.api.core.tracker.RequestTracker in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_invoke_request_tracker.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_invoke_request_tracker(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(new com.datastax.oss.protocol.internal.response.Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
RequestTracker requestTracker = mock(RequestTracker.class);
when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
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()).isNotEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
verify(requestTracker).onNodeError(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), any(BootstrappingException.class), anyLong(), any(DriverExecutionProfile.class), eq(node1), matches(LOG_PREFIX_PER_REQUEST));
verify(requestTracker).onNodeSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), matches(LOG_PREFIX_PER_REQUEST));
verify(requestTracker).onSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), matches(LOG_PREFIX_PER_REQUEST));
verifyNoMoreInteractions(requestTracker);
});
}
}
Aggregations