Search in sources :

Example 1 with RequestTracker

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);
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Error(com.datastax.oss.protocol.internal.response.Error) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) BootstrappingException(com.datastax.oss.driver.api.core.servererrors.BootstrappingException) Test(org.junit.Test)

Example 2 with 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));
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) Error(com.datastax.oss.protocol.internal.response.Error) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) Test(org.junit.Test)

Example 3 with 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);
    }
}
Also used : LoadBalancingPolicy(com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) ArrayList(java.util.ArrayList) MultiplexingRequestTracker(com.datastax.oss.driver.internal.core.tracker.MultiplexingRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) MultiplexingRequestTracker(com.datastax.oss.driver.internal.core.tracker.MultiplexingRequestTracker)

Example 4 with RequestTracker

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());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with RequestTracker

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);
        });
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Row(com.datastax.oss.driver.api.core.cql.Row) BootstrappingException(com.datastax.oss.driver.api.core.servererrors.BootstrappingException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

RequestTracker (com.datastax.oss.driver.api.core.tracker.RequestTracker)5 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)4 Test (org.junit.Test)4 NoopRequestTracker (com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker)3 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)2 BootstrappingException (com.datastax.oss.driver.api.core.servererrors.BootstrappingException)2 Error (com.datastax.oss.protocol.internal.response.Error)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)1 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)1 GraphResultSet (com.datastax.dse.driver.api.core.graph.GraphResultSet)1 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)1 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)1 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)1 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 LoadBalancingPolicy (com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy)1 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)1 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)1 MultiplexingRequestTracker (com.datastax.oss.driver.internal.core.tracker.MultiplexingRequestTracker)1