Search in sources :

Example 16 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 17 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_manual_reload.

@Test
public void should_detect_config_change_from_manual_reload() {
    DefaultDriverConfigLoader loader = new DefaultDriverConfigLoader(() -> ConfigFactory.parseString(configSource.get()));
    DriverConfig initialConfig = loader.getInitialConfig();
    assertThat(initialConfig).hasIntOption(MockOptions.INT1, 42);
    loader.onDriverInit(context);
    adminExecutor.waitForNonScheduledTasks();
    configSource.set("int1 = 43");
    CompletionStage<Boolean> reloaded = loader.reload();
    adminExecutor.waitForNonScheduledTasks();
    assertThat(initialConfig).hasIntOption(MockOptions.INT1, 43);
    verify(eventBus).fire(ConfigChangeEvent.INSTANCE);
    assertThatStage(reloaded).isSuccess(changed -> assertThat(changed).isTrue());
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 18 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.

@Test
public void should_override_option() {
    DriverConfigLoader loader = new DefaultProgrammaticDriverConfigLoaderBuilder(() -> ConfigFactory.parseString(FALLBACK_CONFIG), "").withInt(MockOptions.INT1, 2).withInt(MockOptions.INT1, 3).withInt(MockOptions.INT1, 4).withInt(MockOptions.INT2, 3).withInt(MockOptions.INT2, 4).build();
    DriverConfig config = loader.getInitialConfig();
    assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(4);
    assertThat(config.getDefaultProfile().getInt(MockOptions.INT2)).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 19 with DriverConfig

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

the class ExecutionProfilesInfoFinderTest method mockDriverContextWithProfiles.

private InternalDriverContext mockDriverContextWithProfiles(DriverExecutionProfile defaultExecutionProfile, Map<String, DriverExecutionProfile> profiles) {
    InternalDriverContext context = mock(InternalDriverContext.class);
    DriverConfig driverConfig = mock(DriverConfig.class);
    Mockito.<Map<String, ? extends DriverExecutionProfile>>when(driverConfig.getProfiles()).thenReturn(profiles);
    when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile);
    when(context.getConfig()).thenReturn(driverConfig);
    return context;
}
Also used : DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext)

Example 20 with DriverConfig

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

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