Search in sources :

Example 46 with DriverConfig

use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.

the class MicrometerSessionMetricUpdaterTest method should_create_timer.

@Test
@UseDataProvider(value = "timerMetrics")
public void should_create_timer(SessionMetric metric, DriverOption lowest, DriverOption highest, DriverOption digits, DriverOption sla) {
    // given
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
    DriverConfig config = mock(DriverConfig.class);
    MetricIdGenerator generator = mock(MetricIdGenerator.class);
    Set<SessionMetric> enabledMetrics = Collections.singleton(metric);
    // when
    when(context.getSessionName()).thenReturn("prefix");
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(profile);
    when(context.getMetricIdGenerator()).thenReturn(generator);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(Duration.ofHours(1));
    when(profile.getDuration(lowest)).thenReturn(Duration.ofMillis(10));
    when(profile.getDuration(highest)).thenReturn(Duration.ofSeconds(1));
    when(profile.getInt(digits)).thenReturn(5);
    when(profile.isDefined(sla)).thenReturn(true);
    when(profile.getDurationList(sla)).thenReturn(Arrays.asList(Duration.ofMillis(100), Duration.ofMillis(500)));
    when(generator.sessionMetricId(metric)).thenReturn(METRIC_ID);
    SimpleMeterRegistry registry = spy(new SimpleMeterRegistry());
    MicrometerSessionMetricUpdater updater = new MicrometerSessionMetricUpdater(context, enabledMetrics, registry);
    for (int i = 0; i < 10; i++) {
        updater.updateTimer(metric, null, 100, TimeUnit.MILLISECONDS);
    }
    // then
    Timer timer = registry.find(METRIC_ID.getName()).timer();
    assertThat(timer).isNotNull();
    assertThat(timer.count()).isEqualTo(10);
    HistogramSnapshot snapshot = timer.takeSnapshot();
    assertThat(snapshot.histogramCounts()).hasSize(2);
}
Also used : MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) DseSessionMetric(com.datastax.dse.driver.api.core.metrics.DseSessionMetric) SessionMetric(com.datastax.oss.driver.api.core.metrics.SessionMetric) DefaultSessionMetric(com.datastax.oss.driver.api.core.metrics.DefaultSessionMetric) Timer(io.micrometer.core.instrument.Timer) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) HistogramSnapshot(io.micrometer.core.instrument.distribution.HistogramSnapshot) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)46 Test (org.junit.Test)31 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)22 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)16 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)10 Node (com.datastax.oss.driver.api.core.metadata.Node)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 OptionsMap (com.datastax.oss.driver.api.core.config.OptionsMap)7 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)4 MetricIdGenerator (com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator)4 DseNodeMetric (com.datastax.dse.driver.api.core.metrics.DseNodeMetric)3 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 Duration (java.time.Duration)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)2 DriverOption (com.datastax.oss.driver.api.core.config.DriverOption)2