Search in sources :

Example 21 with InternalDriverContext

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

the class ExecutionProfilesInfoFinderTest method should_include_info_about_default_profile.

@Test
public void should_include_info_about_default_profile() {
    // given
    DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
    Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile);
    InternalDriverContext context = mockDriverContextWithProfiles(defaultExecutionProfile, profiles);
    // when
    Map<String, SpecificExecutionProfile> executionProfilesInfo = new ExecutionProfilesInfoFinder().getExecutionProfilesInfo(context);
    // then
    assertThat(executionProfilesInfo).isEqualTo(ImmutableMap.of("default", new SpecificExecutionProfile(100, new LoadBalancingInfo("LoadBalancingPolicyImpl", ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), DEFAULT_LOAD_BALANCING_PACKAGE), new SpeculativeExecutionInfo("SpeculativeExecutionImpl", ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), "LOCAL_ONE", "SERIAL", ImmutableMap.of("source", "src-graph"))));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) LoadBalancingInfo(com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo) SpecificExecutionProfile(com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo) ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo) Test(org.junit.Test)

Example 22 with InternalDriverContext

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

the class MicroProfileMetricsFactoryTest method should_throw_if_wrong_or_missing_registry_type.

@Test
@UseDataProvider(value = "invalidRegistryTypes")
public void should_throw_if_wrong_or_missing_registry_type(Object registryObj, String expectedMsg) {
    // 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(registryObj);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
    when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(enabledMetrics);
    // then
    try {
        new MicroProfileMetricsFactory(context);
        fail("MetricsFactory should require correct registry object type: " + MetricRegistry.class.getName());
    } catch (IllegalArgumentException iae) {
        assertThat(iae.getMessage()).isEqualTo(expectedMsg);
    }
}
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) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 23 with InternalDriverContext

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

the class MicroProfileNodeMetricsUpdaterTest method should_log_warning_when_provided_eviction_time_setting_is_too_low.

@Test
public void should_log_warning_when_provided_eviction_time_setting_is_too_low() {
    // 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);
    Duration expireAfter = AbstractMetricUpdater.MIN_EXPIRE_AFTER.minusMinutes(1);
    // 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);
    MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {

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

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

        @Override
        protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
        // do nothing
        }
    };
    // then
    assertThat(updater.getExpireAfter()).isEqualTo(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
    verify(logger.appender, timeout(500).times(1)).doAppend(logger.loggingEventCaptor.capture());
    assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
    assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains(String.format("[prefix] Value too low for %s: %s. Forcing to %s instead.", DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER.getPath(), expireAfter, AbstractMetricUpdater.MIN_EXPIRE_AFTER));
}
Also used : DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricsRegistryImpl(io.smallrye.metrics.MetricsRegistryImpl) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Duration(java.time.Duration) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Gauge(org.eclipse.microprofile.metrics.Gauge) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test)

Example 24 with InternalDriverContext

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

the class MicroProfileNodeMetricsUpdaterTest 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);
    MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {

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

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

        @Override
        protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
        // 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) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) MetricsRegistryImpl(io.smallrye.metrics.MetricsRegistryImpl) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Gauge(org.eclipse.microprofile.metrics.Gauge) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 25 with InternalDriverContext

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

the class MicrometerNodeMetricUpdaterTest 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);
    MetricIdGenerator generator = mock(MetricIdGenerator.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(context.getMetricIdGenerator()).thenReturn(generator);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
    when(generator.nodeMetricId(node, DefaultNodeMetric.CQL_MESSAGES)).thenReturn(METRIC_ID);
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_HIGHEST)).thenReturn(Duration.ofSeconds(10));
    when(profile.getDuration(DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_LOWEST)).thenReturn(Duration.ofMillis(1));
    when(profile.getInt(DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_DIGITS)).thenReturn(5);
    MicrometerNodeMetricUpdater updater = new MicrometerNodeMetricUpdater(node, context, enabledMetrics, new SimpleMeterRegistry());
    // then
    assertThat(updater.getExpireAfter()).isEqualTo(expireAfter);
    verify(logger.appender, timeout(500).times(0)).doAppend(logger.loggingEventCaptor.capture());
}
Also used : MetricIdGenerator(com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator) DefaultNodeMetric(com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric) DseNodeMetric(com.datastax.dse.driver.api.core.metrics.DseNodeMetric) NodeMetric(com.datastax.oss.driver.api.core.metrics.NodeMetric) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Node(com.datastax.oss.driver.api.core.metadata.Node) 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) 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)

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