Search in sources :

Example 31 with DriverConfig

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

the class MapBasedDriverConfigTest method should_create_derived_profile_unsetting_option.

@Test
public void should_create_derived_profile_unsetting_option() {
    OptionsMap source = new OptionsMap();
    source.put(MockTypedOptions.INT1, 42);
    source.put(MockTypedOptions.INT2, 43);
    DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
    DriverExecutionProfile base = config.getDefaultProfile();
    DriverExecutionProfile derived = base.without(MockOptions.INT2);
    assertThat(base.getInt(MockOptions.INT2)).isEqualTo(43);
    assertThat(derived.isDefined(MockOptions.INT2)).isFalse();
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 32 with DriverConfig

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

the class MapBasedDriverConfigTest method should_create_derived_profile_overriding_option.

@Test
public void should_create_derived_profile_overriding_option() {
    OptionsMap source = new OptionsMap();
    source.put(MockTypedOptions.INT1, 42);
    DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
    DriverExecutionProfile base = config.getDefaultProfile();
    DriverExecutionProfile derived = base.withInt(MockOptions.INT1, 43);
    assertThat(base.getInt(MockOptions.INT1)).isEqualTo(42);
    assertThat(derived.getInt(MockOptions.INT1)).isEqualTo(43);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 33 with DriverConfig

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

the class DefaultDriverConfigLoaderTest method should_detect_config_change_from_periodic_reload.

@Test
public void should_detect_config_change_from_periodic_reload() {
    DefaultDriverConfigLoader loader = new DefaultDriverConfigLoader(() -> ConfigFactory.parseString(configSource.get()));
    DriverConfig initialConfig = loader.getInitialConfig();
    assertThat(initialConfig).hasIntOption(MockOptions.INT1, 42);
    loader.onDriverInit(context);
    adminExecutor.waitForNonScheduledTasks();
    CapturedTask<?> task = adminExecutor.nextTask();
    configSource.set("int1 = 43");
    task.run();
    assertThat(initialConfig).hasIntOption(MockOptions.INT1, 43);
    verify(eventBus).fire(ConfigChangeEvent.INSTANCE);
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 34 with DriverConfig

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

the class DefaultProgrammaticDriverConfigLoaderBuilderTest method should_go_back_to_default_profile_when_profile_ends.

@Test
public void should_go_back_to_default_profile_when_profile_ends() {
    DriverConfigLoader loader = new DefaultProgrammaticDriverConfigLoaderBuilder(() -> ConfigFactory.parseString(FALLBACK_CONFIG), "").startProfile("profile2").withInt(MockOptions.INT1, 3).endProfile().withInt(MockOptions.INT1, 4).build();
    DriverConfig config = loader.getInitialConfig();
    assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(4);
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Test(org.junit.Test)

Example 35 with DriverConfig

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

the class DefaultProgrammaticDriverConfigLoaderBuilderTest method should_override_option_in_new_profile.

@Test
public void should_override_option_in_new_profile() {
    DriverConfigLoader loader = new DefaultProgrammaticDriverConfigLoaderBuilder(() -> ConfigFactory.parseString(FALLBACK_CONFIG), "").startProfile("profile2").withInt(MockOptions.INT1, 3).build();
    DriverConfig config = loader.getInitialConfig();
    assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(1);
    assertThat(config.getProfile("profile1").getInt(MockOptions.INT1)).isEqualTo(11);
    assertThat(config.getProfile("profile2").getInt(MockOptions.INT1)).isEqualTo(3);
    assertThat(config.getProfile("profile2").getInt(MockOptions.INT2)).isEqualTo(2);
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Test(org.junit.Test)

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