use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class TypeSafeDriverConfigOverrideDefaultsTest method should_handle_profiles.
@Test
public void should_handle_profiles() {
// Given
TypesafeDriverConfig config = config("datastax-java-driver.profiles.profile1.basic.request.consistency = TWO\n" + "datastax-java-driver.profiles.profile2.basic.request.timeout = 5 seconds");
DriverExecutionProfile profile1 = config.getProfile("profile1");
DriverExecutionProfile profile2 = config.getProfile("profile2");
DriverExecutionProfile derivedProfile21 = profile2.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(10));
DriverExecutionProfile derivedProfile22 = profile2.withString(DefaultDriverOption.REQUEST_CONSISTENCY, "QUORUM");
assertThat(profile1.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("TWO");
assertThat(profile2.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo(// inherited from default profile in reference.conf
"LOCAL_ONE");
assertThat(derivedProfile21.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo(// inherited from default profile in reference.conf
"LOCAL_ONE");
assertThat(derivedProfile22.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo(// overridden programmatically
"QUORUM");
// When
config.overrideDefaults(ImmutableMap.of(DefaultDriverOption.REQUEST_CONSISTENCY, "LOCAL_QUORUM"));
// Then
// Unaffected because it was set manually in application.conf:
assertThat(profile1.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("TWO");
// Affected because it was using the default from reference.conf:
assertThat(profile2.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("LOCAL_QUORUM");
// Same:
assertThat(derivedProfile21.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("LOCAL_QUORUM");
// Unaffected because it was overridden programmatically:
assertThat(derivedProfile22.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("QUORUM");
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class MapBasedDriverConfigLoaderTest method should_fill_default_profile_like_reference_file.
/**
* Checks that, if we ask to pre-fill the default profile, then we get the same set of options as
* the built-in reference.conf.
*/
@Test
public void should_fill_default_profile_like_reference_file() {
OptionsMap optionsMap = OptionsMap.driverDefaults();
DriverExecutionProfile mapBasedConfig = DriverConfigLoader.fromMap(optionsMap).getInitialConfig().getDefaultProfile();
DriverExecutionProfile fileBasedConfig = new DefaultDriverConfigLoader(() -> {
// Only load reference.conf since we are focusing on driver defaults
ConfigFactory.invalidateCaches();
return defaultReference().getConfig(DefaultDriverConfigLoader.DEFAULT_ROOT_PATH);
}).getInitialConfig().getDefaultProfile();
// Make sure we're not missing any options. -1 is for CONFIG_RELOAD_INTERVAL, which is not
// defined by OptionsMap because it is irrelevant for the map-based config.
assertThat(mapBasedConfig.entrySet()).hasSize(fileBasedConfig.entrySet().size() - 1);
for (TypedDriverOption<?> option : TypedDriverOption.builtInValues()) {
if (option.getRawOption() == DefaultDriverOption.CONFIG_RELOAD_INTERVAL) {
continue;
}
Optional<Object> fileBasedValue = get(fileBasedConfig, option);
Optional<Object> mapBasedValue = get(mapBasedConfig, option);
assertThat(mapBasedValue).as("Wrong value for %s in OptionsMap", option.getRawOption()).isEqualTo(fileBasedValue);
}
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class MapBasedDriverConfigTest method should_create_derived_profile_with_new_option.
@Test
public void should_create_derived_profile_with_new_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.INT2, 43);
assertThat(base.isDefined(MockOptions.INT2)).isFalse();
assertThat(derived.isDefined(MockOptions.INT2)).isTrue();
assertThat(derived.getInt(MockOptions.INT2)).isEqualTo(43);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class TypesafeDriverConfigTest method should_create_derived_profile_with_string_map.
@Test
public void should_create_derived_profile_with_string_map() {
TypesafeDriverConfig config = parse("int1 = 42");
Map<String, String> authThingMap = new HashMap<>();
authThingMap.put("auth_thing_one", "one");
authThingMap.put("auth_thing_two", "two");
authThingMap.put("auth_thing_three", "three");
DriverExecutionProfile base = config.getDefaultProfile();
DriverExecutionProfile mapBase = base.withStringMap(MockOptions.AUTH_PROVIDER, authThingMap);
Map<String, String> fetchedMap = mapBase.getStringMap(MockOptions.AUTH_PROVIDER);
assertThat(fetchedMap).isEqualTo(authThingMap);
}
Aggregations