use of com.datastax.oss.driver.api.core.config.OptionsMap in project java-driver by datastax.
the class MapBasedConfigLoaderIT method should_create_policies_per_profile.
/**
* Checks that profiles that have specific policy options will get their own policy instance.
*/
@Test
public void should_create_policies_per_profile() {
// Given
// a query that throws UNAVAILABLE
String mockQuery = "mock query";
SIMULACRON_RULE.cluster().prime(when(mockQuery).then(unavailable(QUORUM, 3, 2)));
// a default profile that uses the default retry policy, and an alternate profile that uses a
// policy that ignores all errors
OptionsMap optionsMap = OptionsMap.driverDefaults();
String alternateProfile = "profile1";
optionsMap.put(alternateProfile, TypedDriverOption.RETRY_POLICY_CLASS, IgnoreAllPolicy.class.getName());
try (CqlSession session = CqlSession.builder().addContactEndPoints(SIMULACRON_RULE.getContactPoints()).withLocalDatacenter("dc1").withConfigLoader(DriverConfigLoader.fromMap(optionsMap)).build()) {
// When
// executing the query for the default profile
SimpleStatement defaultProfileStatement = SimpleStatement.newInstance(mockQuery);
assertThatThrownBy(() -> session.execute(defaultProfileStatement)).satisfies(t -> {
// Then
// the UNAVAILABLE error is surfaced
assertThat(t).isInstanceOf(AllNodesFailedException.class);
AllNodesFailedException anfe = (AllNodesFailedException) t;
assertThat(anfe.getAllErrors()).hasSize(1);
List<Throwable> nodeErrors = anfe.getAllErrors().values().iterator().next();
assertThat(nodeErrors).hasSize(1);
assertThat(nodeErrors.get(0)).isInstanceOf(UnavailableException.class);
});
// When
// executing the query for the alternate profile
SimpleStatement alternateProfileStatement = SimpleStatement.newInstance(mockQuery).setExecutionProfileName(alternateProfile);
ResultSet rs = session.execute(alternateProfileStatement);
// Then
// the error is ignored
assertThat(rs.one()).isNull();
}
}
use of com.datastax.oss.driver.api.core.config.OptionsMap 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);
}
use of com.datastax.oss.driver.api.core.config.OptionsMap 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);
}
use of com.datastax.oss.driver.api.core.config.OptionsMap in project java-driver by datastax.
the class MapBasedDriverConfigTest method should_inherit_option_in_profile.
@Test
public void should_inherit_option_in_profile() {
OptionsMap source = new OptionsMap();
source.put(MockTypedOptions.INT1, 42);
// need to add an unrelated option to create the profile
source.put("profile1", MockTypedOptions.INT2, 1);
DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
assertThat(config).hasIntOption(MockOptions.INT1, 42).hasIntOption("profile1", MockOptions.INT1, 42);
}
use of com.datastax.oss.driver.api.core.config.OptionsMap 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);
}
}
Aggregations