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);
}
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());
}
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);
}
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;
}
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);
}
}
Aggregations