Search in sources :

Example 26 with DriverConfig

use of com.datastax.oss.driver.api.core.config.DriverConfig 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 27 with DriverConfig

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

the class PerProfileLoadBalancingPolicyIT method setup.

@BeforeClass
public static void setup() {
    // sanity checks
    DriverContext context = SESSION_RULE.session().getContext();
    DriverConfig config = context.getConfig();
    assertThat(config.getProfiles()).containsKeys("profile1", "profile2");
    assertThat(context.getLoadBalancingPolicies()).hasSize(3).containsKeys(DriverExecutionProfile.DEFAULT_NAME, "profile1", "profile2");
    LoadBalancingPolicy defaultPolicy = context.getLoadBalancingPolicy(DriverExecutionProfile.DEFAULT_NAME);
    LoadBalancingPolicy policy1 = context.getLoadBalancingPolicy("profile1");
    LoadBalancingPolicy policy2 = context.getLoadBalancingPolicy("profile2");
    assertThat(defaultPolicy).isSameAs(policy2).isNotSameAs(policy1);
    for (Node node : SESSION_RULE.session().getMetadata().getNodes().values()) {
        // if node is in dc2 it should be ignored, otherwise (dc1, dc3) it should be local.
        NodeDistance expectedDistance = Objects.equals(node.getDatacenter(), "dc2") ? NodeDistance.IGNORED : NodeDistance.LOCAL;
        assertThat(node.getDistance()).isEqualTo(expectedDistance);
    }
}
Also used : DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) NodeDistance(com.datastax.oss.driver.api.core.loadbalancing.NodeDistance) LoadBalancingPolicy(com.datastax.oss.driver.api.core.loadbalancing.LoadBalancingPolicy) Node(com.datastax.oss.driver.api.core.metadata.Node) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) BeforeClass(org.junit.BeforeClass)

Example 28 with DriverConfig

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

the class PerProfileRetryPolicyIT method setup.

@BeforeClass
public static void setup() {
    // node 0 will return an unavailable to query.
    SIMULACRON_RULE.cluster().node(0).prime(when(QUERY_STRING).then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ONE, 1, 0)));
    // node 1 will return a valid empty rows response.
    SIMULACRON_RULE.cluster().node(1).prime(when(QUERY_STRING).then(noRows()));
    // sanity checks
    DriverContext context = SESSION_RULE.session().getContext();
    DriverConfig config = context.getConfig();
    assertThat(config.getProfiles()).containsKeys("profile1", "profile2");
    assertThat(context.getRetryPolicies()).hasSize(3).containsKeys(DriverExecutionProfile.DEFAULT_NAME, "profile1", "profile2");
    RetryPolicy defaultPolicy = context.getRetryPolicy(DriverExecutionProfile.DEFAULT_NAME);
    RetryPolicy policy1 = context.getRetryPolicy("profile1");
    RetryPolicy policy2 = context.getRetryPolicy("profile2");
    assertThat(defaultPolicy).isInstanceOf(DefaultRetryPolicy.class).isSameAs(policy2).isNotSameAs(policy1);
    assertThat(policy1).isInstanceOf(NoRetryPolicy.class);
}
Also used : DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) RetryPolicy(com.datastax.oss.driver.api.core.retry.RetryPolicy) DefaultRetryPolicy(com.datastax.oss.driver.internal.core.retry.DefaultRetryPolicy) BeforeClass(org.junit.BeforeClass)

Example 29 with DriverConfig

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

the class SpeculativeExecutionIT method buildSessionWithProfile.

private CqlSession buildSessionWithProfile(int defaultMaxSpeculativeExecutions, long defaultSpeculativeDelayMs, int profile1MaxSpeculativeExecutions, long profile1SpeculativeDelayMs) {
    ProgrammaticDriverConfigLoaderBuilder builder = SessionUtils.configLoaderBuilder().withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(SPECULATIVE_DELAY * 10)).withBoolean(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE, true).withClass(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, SortingLoadBalancingPolicy.class);
    if (defaultMaxSpeculativeExecutions != -1 || defaultSpeculativeDelayMs != -1) {
        builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, ConstantSpeculativeExecutionPolicy.class);
        if (defaultMaxSpeculativeExecutions != -1) {
            builder = builder.withInt(DefaultDriverOption.SPECULATIVE_EXECUTION_MAX, defaultMaxSpeculativeExecutions);
        }
        if (defaultSpeculativeDelayMs != -1) {
            builder = builder.withDuration(DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY, Duration.ofMillis(defaultSpeculativeDelayMs));
        }
    } else {
        builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, NoSpeculativeExecutionPolicy.class);
    }
    builder = builder.startProfile("profile1");
    if (profile1MaxSpeculativeExecutions != -1 || profile1SpeculativeDelayMs != -1) {
        builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, ConstantSpeculativeExecutionPolicy.class);
        if (profile1MaxSpeculativeExecutions != -1) {
            builder = builder.withInt(DefaultDriverOption.SPECULATIVE_EXECUTION_MAX, profile1MaxSpeculativeExecutions);
        }
        if (profile1SpeculativeDelayMs != -1) {
            builder = builder.withDuration(DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY, Duration.ofMillis(profile1SpeculativeDelayMs));
        }
    } else {
        builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, NoSpeculativeExecutionPolicy.class);
    }
    builder = builder.startProfile("profile2").withString(DefaultDriverOption.REQUEST_CONSISTENCY, "ONE");
    CqlSession session = SessionUtils.newSession(SIMULACRON_RULE, builder.build());
    // validate profile data
    DriverContext context = session.getContext();
    DriverConfig driverConfig = context.getConfig();
    assertThat(driverConfig.getProfiles()).containsKeys("profile1", "profile2");
    assertThat(context.getSpeculativeExecutionPolicies()).hasSize(3).containsKeys(DriverExecutionProfile.DEFAULT_NAME, "profile1", "profile2");
    SpeculativeExecutionPolicy defaultPolicy = context.getSpeculativeExecutionPolicy(DriverExecutionProfile.DEFAULT_NAME);
    SpeculativeExecutionPolicy policy1 = context.getSpeculativeExecutionPolicy("profile1");
    SpeculativeExecutionPolicy policy2 = context.getSpeculativeExecutionPolicy("profile2");
    Class<? extends SpeculativeExecutionPolicy> expectedDefaultPolicyClass = defaultMaxSpeculativeExecutions != -1 || defaultSpeculativeDelayMs != -1 ? ConstantSpeculativeExecutionPolicy.class : NoSpeculativeExecutionPolicy.class;
    assertThat(defaultPolicy).isInstanceOf(expectedDefaultPolicyClass).isSameAs(policy2);
    // If configuration was same, same policy instance should be used.
    if (defaultMaxSpeculativeExecutions == profile1MaxSpeculativeExecutions && defaultSpeculativeDelayMs == profile1SpeculativeDelayMs) {
        assertThat(defaultPolicy).isSameAs(policy1);
    } else {
        assertThat(defaultPolicy).isNotSameAs(policy1);
    }
    Class<? extends SpeculativeExecutionPolicy> expectedProfile1PolicyClass = profile1MaxSpeculativeExecutions != -1 || profile1SpeculativeDelayMs != -1 ? ConstantSpeculativeExecutionPolicy.class : NoSpeculativeExecutionPolicy.class;
    assertThat(policy1).isInstanceOf(expectedProfile1PolicyClass);
    return session;
}
Also used : DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) ProgrammaticDriverConfigLoaderBuilder(com.datastax.oss.driver.api.core.config.ProgrammaticDriverConfigLoaderBuilder) 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) NoSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.NoSpeculativeExecutionPolicy) ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) CqlSession(com.datastax.oss.driver.api.core.CqlSession)

Example 30 with DriverConfig

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

the class CompositeDriverConfigLoader method getInitialConfig.

@NonNull
@Override
public DriverConfig getInitialConfig() {
    DriverConfig primaryConfig = primaryConfigLoader.getInitialConfig();
    DriverConfig fallbackConfig = fallbackConfigLoader.getInitialConfig();
    return new CompositeDriverConfig(primaryConfig, fallbackConfig);
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

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