Search in sources :

Example 31 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class MicroProfileMetricsIT method assertMetricsPresent.

@Override
protected void assertMetricsPresent(CqlSession session) {
    MetricRegistry registry = (MetricRegistry) ((InternalDriverContext) session.getContext()).getMetricRegistry();
    assertThat(registry).isNotNull();
    assertThat(registry.getMetrics()).hasSize(ENABLED_SESSION_METRICS.size() + ENABLED_NODE_METRICS.size() * 3);
    MetricIdGenerator metricIdGenerator = ((InternalDriverContext) session.getContext()).getMetricIdGenerator();
    for (DefaultSessionMetric metric : ENABLED_SESSION_METRICS) {
        MetricId metricId = metricIdGenerator.sessionMetricId(metric);
        Tag[] tags = MicroProfileTags.toMicroProfileTags(metricId.getTags());
        MetricID id = new MetricID(metricId.getName(), tags);
        Metric m = registry.getMetrics().get(id);
        assertThat(m).isNotNull();
        switch(metric) {
            case CONNECTED_NODES:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Integer) ((Gauge<?>) m).getValue()).isEqualTo(3);
                break;
            case CQL_REQUESTS:
                assertThat(m).isInstanceOf(Timer.class);
                await().untilAsserted(() -> assertThat(((Timer) m).getCount()).isEqualTo(30));
                break;
            case CQL_PREPARED_CACHE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Long) ((Gauge<?>) m).getValue()).isOne();
                break;
            case BYTES_SENT:
            case BYTES_RECEIVED:
                assertThat(m).isInstanceOf(Meter.class);
                assertThat(((Meter) m).getCount()).isGreaterThan(0);
                break;
            case CQL_CLIENT_TIMEOUTS:
            case THROTTLING_ERRORS:
                assertThat(m).isInstanceOf(Counter.class);
                assertThat(((Counter) m).getCount()).isZero();
                break;
            case THROTTLING_DELAY:
                assertThat(m).isInstanceOf(Timer.class);
                assertThat(((Timer) m).getCount()).isZero();
                break;
            case THROTTLING_QUEUE_SIZE:
                assertThat(m).isInstanceOf(Gauge.class);
                assertThat((Integer) ((Gauge<?>) m).getValue()).isZero();
                break;
        }
    }
    for (Node node : session.getMetadata().getNodes().values()) {
        for (DefaultNodeMetric metric : ENABLED_NODE_METRICS) {
            MetricId description = metricIdGenerator.nodeMetricId(node, metric);
            Tag[] tags = MicroProfileTags.toMicroProfileTags(description.getTags());
            MetricID id = new MetricID(description.getName(), tags);
            Metric m = registry.getMetrics().get(id);
            assertThat(m).isNotNull();
            switch(metric) {
                case OPEN_CONNECTIONS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    // control node has 2 connections
                    assertThat((Integer) ((Gauge<?>) m).getValue()).isBetween(1, 2);
                    break;
                case CQL_MESSAGES:
                    assertThat(m).isInstanceOf(Timer.class);
                    await().untilAsserted(() -> assertThat(((Timer) m).getCount()).isEqualTo(10));
                    break;
                case READ_TIMEOUTS:
                case WRITE_TIMEOUTS:
                case UNAVAILABLES:
                case OTHER_ERRORS:
                case ABORTED_REQUESTS:
                case UNSENT_REQUESTS:
                case RETRIES:
                case IGNORES:
                case RETRIES_ON_READ_TIMEOUT:
                case RETRIES_ON_WRITE_TIMEOUT:
                case RETRIES_ON_UNAVAILABLE:
                case RETRIES_ON_OTHER_ERROR:
                case RETRIES_ON_ABORTED:
                case IGNORES_ON_READ_TIMEOUT:
                case IGNORES_ON_WRITE_TIMEOUT:
                case IGNORES_ON_UNAVAILABLE:
                case IGNORES_ON_OTHER_ERROR:
                case IGNORES_ON_ABORTED:
                case SPECULATIVE_EXECUTIONS:
                case CONNECTION_INIT_ERRORS:
                case AUTHENTICATION_ERRORS:
                    assertThat(m).isInstanceOf(Counter.class);
                    assertThat(((Counter) m).getCount()).isZero();
                    break;
                case BYTES_SENT:
                case BYTES_RECEIVED:
                    assertThat(m).isInstanceOf(Meter.class);
                    assertThat(((Meter) m).getCount()).isGreaterThan(0L);
                    break;
                case AVAILABLE_STREAMS:
                case IN_FLIGHT:
                case ORPHANED_STREAMS:
                    assertThat(m).isInstanceOf(Gauge.class);
                    break;
            }
        }
    }
}
Also used : DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Meter(org.eclipse.microprofile.metrics.Meter) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) MetricId(com.datastax.oss.driver.internal.core.metrics.MetricId) MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Timer(org.eclipse.microprofile.metrics.Timer) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) Metric(org.eclipse.microprofile.metrics.Metric) DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Tag(org.eclipse.microprofile.metrics.Tag) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Example 32 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class GraphSupportCheckerTest method protocolWithPagingSupport.

private InternalDriverContext protocolWithPagingSupport(boolean pagingSupport) {
    InternalDriverContext context = mock(InternalDriverContext.class);
    when(context.getProtocolVersion()).thenReturn(DseProtocolVersion.DSE_V2);
    ProtocolVersionRegistry protocolVersionRegistry = mock(ProtocolVersionRegistry.class);
    when(protocolVersionRegistry.supports(DseProtocolVersion.DSE_V2, DseProtocolFeature.CONTINUOUS_PAGING)).thenReturn(pagingSupport);
    when(context.getProtocolVersionRegistry()).thenReturn(protocolVersionRegistry);
    return context;
}
Also used : InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) ProtocolVersionRegistry(com.datastax.oss.driver.internal.core.ProtocolVersionRegistry)

Example 33 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class GraphSupportCheckerTest method should_support_paging_when_statement_profile_not_present_but_context_profile_has_paging_enabled.

@Test
public void should_support_paging_when_statement_profile_not_present_but_context_profile_has_paging_enabled() {
    // given
    GraphStatement graphStatement = mock(GraphStatement.class);
    InternalDriverContext context = protocolWithPagingSupport(true);
    contextGraphPagingEnabled(context, ENABLED);
    addNodeWithDseVersion(context, Collections.singletonList(Version.parse("6.8.0")));
    // when
    boolean pagingEnabled = new GraphSupportChecker().isPagingEnabled(graphStatement, context);
    // then
    assertThat(pagingEnabled).isEqualTo(true);
}
Also used : GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) Test(org.junit.Test)

Example 34 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class GraphSupportCheckerTest method should_check_if_paging_is_supported.

@UseDataProvider("graphPagingEnabledAndDseVersions")
@Test
public void should_check_if_paging_is_supported(boolean protocolWithPagingSupport, PagingEnabledOptions statementGraphPagingEnabled, PagingEnabledOptions contextGraphPagingEnabled, List<Version> nodeDseVersions, boolean expected) {
    // given
    GraphStatement graphStatement = mock(GraphStatement.class);
    InternalDriverContext context = protocolWithPagingSupport(protocolWithPagingSupport);
    statementGraphPagingEnabled(graphStatement, statementGraphPagingEnabled);
    contextGraphPagingEnabled(context, contextGraphPagingEnabled);
    addNodeWithDseVersion(context, nodeDseVersions);
    // when
    boolean pagingEnabled = new GraphSupportChecker().isPagingEnabled(graphStatement, context);
    // then
    assertThat(pagingEnabled).isEqualTo(expected);
}
Also used : GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 35 with InternalDriverContext

use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.

the class ConfigAntiPatternsFinderTest method mockDefaultProfile.

private InternalDriverContext mockDefaultProfile(boolean sslEngineFactoryClassDefined, boolean hostnameValidation) {
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverConfig driverConfig = mock(DriverConfig.class);
    when(context.getConfig()).thenReturn(driverConfig);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    when(profile.isDefined(SSL_ENGINE_FACTORY_CLASS)).thenReturn(sslEngineFactoryClassDefined);
    when(profile.getBoolean(SSL_HOSTNAME_VALIDATION, false)).thenReturn(hostnameValidation);
    when(driverConfig.getDefaultProfile()).thenReturn(profile);
    return context;
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Aggregations

InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)45 Test (org.junit.Test)29 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)16 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)15 Node (com.datastax.oss.driver.api.core.metadata.Node)13 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)12 MetricIdGenerator (com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 MetricRegistry (com.codahale.metrics.MetricRegistry)5 CqlSession (com.datastax.oss.driver.api.core.CqlSession)5 MetricId (com.datastax.oss.driver.internal.core.metrics.MetricId)5 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)4 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)4 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)4 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)4 DefaultSessionMetric (com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric)4 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)4