Search in sources :

Example 26 with InternalDriverContext

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

the class DropwizardMetricsFactoryTest method should_throw_if_registry_of_wrong_type.

@Test
public void should_throw_if_registry_of_wrong_type() {
    // given
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    DriverConfig config = mock(DriverConfig.class);
    List<String> enabledMetrics = Collections.singletonList(DefaultSessionMetric.CQL_REQUESTS.getPath());
    // when
    when(config.getDefaultProfile()).thenReturn(profile);
    when(context.getConfig()).thenReturn(config);
    when(context.getSessionName()).thenReturn("MockSession");
    // registry object is not a registry type
    when(context.getMetricRegistry()).thenReturn(Integer.MAX_VALUE);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(Duration.ofHours(1));
    when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(enabledMetrics);
    // then
    try {
        new DropwizardMetricsFactory(context);
        fail("MetricsFactory should require correct registry object type: " + MetricRegistry.class.getName());
    } catch (IllegalArgumentException iae) {
        assertThat(iae.getMessage()).isEqualTo("Unexpected Metrics registry object. " + "Expected registry object to be of type '%s', but was '%s'", MetricRegistry.class.getName(), Integer.class.getName());
    }
}
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) Test(org.junit.Test)

Example 27 with InternalDriverContext

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

the class DropwizardNodeMetricUpdaterTest method should_not_log_warning_when_provided_eviction_time_setting_is_acceptable.

@Test
@UseDataProvider(value = "acceptableEvictionTimes")
public void should_not_log_warning_when_provided_eviction_time_setting_is_acceptable(Duration expireAfter) {
    // given
    LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
    Node node = mock(Node.class);
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    DriverConfig config = mock(DriverConfig.class);
    Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
    // when
    when(context.getSessionName()).thenReturn("prefix");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
    DropwizardNodeMetricUpdater updater = new DropwizardNodeMetricUpdater(node, context, enabledMetrics, new MetricRegistry()) {

        @Override
        protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Supplier<Number> supplier) {
        // do nothing
        }

        @Override
        protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }

        @Override
        protected void initializeHdrTimer(NodeMetric metric, DriverExecutionProfile profile, DriverOption highestLatency, DriverOption significantDigits, DriverOption interval) {
        // do nothing
        }
    };
    // then
    assertThat(updater.getExpireAfter()).isEqualTo(expireAfter);
    verify(logger.appender, timeout(500).times(0)).doAppend(logger.loggingEventCaptor.capture());
}
Also used : DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) DriverOption(com.datastax.oss.driver.api.core.config.DriverOption) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricRegistry(com.codahale.metrics.MetricRegistry) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Supplier(java.util.function.Supplier) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 28 with InternalDriverContext

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

the class DropwizardMetricsIT method assertNodeMetricsNotEvicted.

@Override
protected void assertNodeMetricsNotEvicted(CqlSession session, Node node) {
    InternalDriverContext context = (InternalDriverContext) session.getContext();
    MetricRegistry registry = (MetricRegistry) context.getMetricRegistry();
    assertThat(registry).isNotNull();
    for (String id : nodeMetricIds(context, node)) {
        assertThat(registry.getMetrics()).containsKey(id);
    }
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Example 29 with InternalDriverContext

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

the class ReflectionTest method should_build_policies_per_profile.

@Test
public void should_build_policies_per_profile() {
    String configSource = "advanced.speculative-execution-policy {\n" + "  class = ConstantSpeculativeExecutionPolicy\n" + "  max-executions = 3\n" + "  delay = 100 milliseconds\n" + "}\n" + "profiles {\n" + // Inherits from default profile
    "  profile1 {}\n" + // Inherits but changes one option
    "  profile2 { \n" + "    advanced.speculative-execution-policy.max-executions = 2" + "  }\n" + // Same as previous profile, should share the same policy instance
    "  profile3 { \n" + "    advanced.speculative-execution-policy.max-executions = 2" + "  }\n" + // Completely overrides default profile
    "  profile4 { \n" + "    advanced.speculative-execution-policy.class = NoSpeculativeExecutionPolicy\n" + "  }\n" + "}\n";
    InternalDriverContext context = mock(InternalDriverContext.class);
    TypesafeDriverConfig config = new TypesafeDriverConfig(ConfigFactory.parseString(configSource));
    when(context.getConfig()).thenReturn(config);
    Map<String, SpeculativeExecutionPolicy> policies = Reflection.buildFromConfigProfiles(context, DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY, SpeculativeExecutionPolicy.class, "com.datastax.oss.driver.internal.core.specex");
    assertThat(policies).hasSize(5);
    SpeculativeExecutionPolicy defaultPolicy = policies.get(DriverExecutionProfile.DEFAULT_NAME);
    SpeculativeExecutionPolicy policy1 = policies.get("profile1");
    SpeculativeExecutionPolicy policy2 = policies.get("profile2");
    SpeculativeExecutionPolicy policy3 = policies.get("profile3");
    SpeculativeExecutionPolicy policy4 = policies.get("profile4");
    assertThat(defaultPolicy).isInstanceOf(ConstantSpeculativeExecutionPolicy.class).isSameAs(policy1);
    assertThat(policy2).isInstanceOf(ConstantSpeculativeExecutionPolicy.class).isSameAs(policy3);
    assertThat(policy4).isInstanceOf(NoSpeculativeExecutionPolicy.class);
}
Also used : TypesafeDriverConfig(com.datastax.oss.driver.internal.core.config.typesafe.TypesafeDriverConfig) ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) NoSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.NoSpeculativeExecutionPolicy) SpeculativeExecutionPolicy(com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) Test(org.junit.Test)

Example 30 with InternalDriverContext

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

the class MicrometerMetricsIT method assertNodeMetricsNotEvicted.

@Override
protected void assertNodeMetricsNotEvicted(CqlSession session, Node node) {
    InternalDriverContext context = (InternalDriverContext) session.getContext();
    MetricIdGenerator metricIdGenerator = context.getMetricIdGenerator();
    MeterRegistry registry = (MeterRegistry) context.getMetricRegistry();
    assertThat(registry).isNotNull();
    for (DefaultNodeMetric metric : ENABLED_NODE_METRICS) {
        MetricId id = metricIdGenerator.nodeMetricId(node, metric);
        Iterable<Tag> tags = MicrometerTags.toMicrometerTags(id.getTags());
        Meter m = registry.find(id.getName()).tags(tags).meter();
        assertThat(m).isNotNull();
    }
}
Also used : MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) MetricId(com.datastax.oss.driver.internal.core.metrics.MetricId) Meter(io.micrometer.core.instrument.Meter) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) Tag(io.micrometer.core.instrument.Tag) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

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