Search in sources :

Example 1 with DriverConfig

use of com.datastax.oss.driver.api.core.config.DriverConfig in project spring-boot by spring-projects.

the class CassandraAutoConfigurationTests method driverConfigLoaderWithConfigCreateProfiles.

@Test
void driverConfigLoaderWithConfigCreateProfiles() {
    String configLocation = "org/springframework/boot/autoconfigure/cassandra/profiles.conf";
    this.contextRunner.withPropertyValues("spring.data.cassandra.config=" + configLocation).run((context) -> {
        assertThat(context).hasSingleBean(DriverConfigLoader.class);
        DriverConfig driverConfig = context.getBean(DriverConfigLoader.class).getInitialConfig();
        assertThat(driverConfig.getProfiles()).containsOnlyKeys("default", "first", "second");
        assertThat(driverConfig.getProfile("first").getDuration(DefaultDriverOption.REQUEST_TIMEOUT)).isEqualTo(Duration.ofMillis(100));
    });
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Test(org.junit.jupiter.api.Test)

Example 2 with DriverConfig

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

the class DefaultDriverConfigLoaderTest method should_not_notify_from_periodic_reload_if_config_has_not_changed.

@Test
public void should_not_notify_from_periodic_reload_if_config_has_not_changed() {
    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();
    // no change to the config source
    task.run();
    verify(eventBus, never()).fire(ConfigChangeEvent.INSTANCE);
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 3 with DriverConfig

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

the class MockedDriverContextFactory method defaultDriverContext.

public static DefaultDriverContext defaultDriverContext(Optional<DriverExecutionProfile> profileOption) {
    /* If the caller provided a profile use that, otherwise make a new one */
    final DriverExecutionProfile profile = profileOption.orElseGet(() -> {
        DriverExecutionProfile blankProfile = mock(DriverExecutionProfile.class);
        when(blankProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")).thenReturn("none");
        when(blankProfile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(Duration.ofMinutes(5));
        when(blankProfile.isDefined(DefaultDriverOption.METRICS_FACTORY_CLASS)).thenReturn(true);
        when(blankProfile.getString(DefaultDriverOption.METRICS_FACTORY_CLASS)).thenReturn("DefaultMetricsFactory");
        return blankProfile;
    });
    /* Setup machinery to connect the input DriverExecutionProfile to the config loader */
    final DriverConfig driverConfig = mock(DriverConfig.class);
    final DriverConfigLoader configLoader = mock(DriverConfigLoader.class);
    when(configLoader.getInitialConfig()).thenReturn(driverConfig);
    when(driverConfig.getDefaultProfile()).thenReturn(profile);
    ProgrammaticArguments args = ProgrammaticArguments.builder().withNodeStateListener(mock(NodeStateListener.class)).withSchemaChangeListener(mock(SchemaChangeListener.class)).withRequestTracker(mock(RequestTracker.class)).withLocalDatacenters(Maps.newHashMap()).withNodeDistanceEvaluators(Maps.newHashMap()).build();
    return new DefaultDriverContext(configLoader, args);
}
Also used : SchemaChangeListener(com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) ProgrammaticArguments(com.datastax.oss.driver.api.core.session.ProgrammaticArguments)

Example 4 with DriverConfig

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

the class MapBasedDriverConfigTest method should_override_option_in_profile.

@Test
public void should_override_option_in_profile() {
    OptionsMap source = new OptionsMap();
    source.put(MockTypedOptions.INT1, 42);
    source.put("profile1", MockTypedOptions.INT1, 43);
    DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
    assertThat(config).hasIntOption(MockOptions.INT1, 42).hasIntOption("profile1", MockOptions.INT1, 43);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 5 with DriverConfig

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

the class MapBasedDriverConfigTest method should_load_minimal_config_with_no_profiles.

@Test
public void should_load_minimal_config_with_no_profiles() {
    OptionsMap source = new OptionsMap();
    source.put(MockTypedOptions.INT1, 42);
    DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
    assertThat(config).hasIntOption(MockOptions.INT1, 42);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Aggregations

DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)45 Test (org.junit.Test)31 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)21 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 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 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)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