Skip to content

Commit

Permalink
Rename DriverConfig.getNamedProfile to getProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t committed May 29, 2018
1 parent 28af144 commit 44aa835
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 23 deletions.
Expand Up @@ -32,18 +32,18 @@ public interface DriverConfig {
* DriverConfigProfile#DEFAULT_NAME} and always present.
*/
default DriverConfigProfile getDefaultProfile() {
return getNamedProfile(DriverConfigProfile.DEFAULT_NAME);
return getProfile(DriverConfigProfile.DEFAULT_NAME);
}

/** @throws IllegalArgumentException if there is no profile with this name. */
DriverConfigProfile getNamedProfile(String profileName);
DriverConfigProfile getProfile(String profileName);

/**
* Returns an <b>immutable</b> view of all named profiles (including the default profile).
*
* <p>Implementations typically return a defensive copy of their internal state; therefore this
* should not be used in performance-sensitive parts of the code, see {@link
* #getNamedProfile(String)} instead.
* should not be used in performance-sensitive parts of the code, see {@link #getProfile(String)}
* instead.
*/
Map<String, DriverConfigProfile> getNamedProfiles();
Map<String, DriverConfigProfile> getProfiles();
}
Expand Up @@ -130,7 +130,7 @@ private Map<String, Config> extractProfiles(Config sourceConfig) {
}

@Override
public DriverConfigProfile getNamedProfile(String profileName) {
public DriverConfigProfile getProfile(String profileName) {
Preconditions.checkArgument(
profiles.containsKey(profileName),
"Unknown profile '%s'. Check your configuration.",
Expand All @@ -139,7 +139,7 @@ public DriverConfigProfile getNamedProfile(String profileName) {
}

@Override
public Map<String, DriverConfigProfile> getNamedProfiles() {
public Map<String, DriverConfigProfile> getProfiles() {
return ImmutableMap.copyOf(profiles);
}

Expand Down
Expand Up @@ -124,7 +124,7 @@ protected CqlPrepareHandlerBase(
this.configProfile =
(profileName == null || profileName.isEmpty())
? config.getDefaultProfile()
: config.getNamedProfile(profileName);
: config.getProfile(profileName);
}
this.queryPlan =
context
Expand Down
Expand Up @@ -149,7 +149,7 @@ protected CqlRequestHandlerBase(
this.configProfile =
(profileName == null || profileName.isEmpty())
? config.getDefaultProfile()
: config.getNamedProfile(profileName);
: config.getProfile(profileName);
}
this.queryPlan =
context
Expand Down
Expand Up @@ -283,7 +283,7 @@ public void close() {
}

private static String getLocalDcFromConfig(DriverContext context, String profileName) {
DriverConfigProfile config = context.config().getNamedProfile(profileName);
DriverConfigProfile config = context.config().getProfile(profileName);
return (config.isDefined(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER))
? config.getString(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER)
: null;
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class ConstantSpeculativeExecutionPolicy implements SpeculativeExecutionP
private final long constantDelayMillis;

public ConstantSpeculativeExecutionPolicy(DriverContext context, String profileName) {
DriverConfigProfile config = context.config().getNamedProfile(profileName);
DriverConfigProfile config = context.config().getProfile(profileName);
this.maxExecutions = config.getInt(DefaultDriverOption.SPECULATIVE_EXECUTION_MAX);
if (this.maxExecutions < 1) {
throw new IllegalArgumentException("Max must be at least 1");
Expand Down
Expand Up @@ -124,7 +124,7 @@ public static <T> Map<String, T> buildFromConfigProfiles(
// Find out how many distinct configurations we have
ListMultimap<Object, String> profilesByConfig =
MultimapBuilder.hashKeys().arrayListValues().build();
for (DriverConfigProfile profile : context.config().getNamedProfiles().values()) {
for (DriverConfigProfile profile : context.config().getProfiles().values()) {
profilesByConfig.put(profile.getComparisonKey(rootOption), profile.getName());
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public static <T> Optional<T> buildFromConfig(
DriverConfigProfile config =
(profileName == null)
? context.config().getDefaultProfile()
: context.config().getNamedProfile(profileName);
: context.config().getProfile(profileName);

String configPath = classNameOption.getPath();
LOG.debug("Creating a {} from config option {}", expectedSuperType.getSimpleName(), configPath);
Expand Down
Expand Up @@ -41,8 +41,7 @@ public class ConstantSpeculativeExecutionPolicyTest {
@Before
public void setup() {
Mockito.when(context.config()).thenReturn(config);
Mockito.when(config.getNamedProfile(DriverConfigProfile.DEFAULT_NAME))
.thenReturn(defaultProfile);
Mockito.when(config.getProfile(DriverConfigProfile.DEFAULT_NAME)).thenReturn(defaultProfile);
}

private void mockOptions(int maxExecutions, long constantDelayMillis) {
Expand Down
Expand Up @@ -32,7 +32,7 @@ public DriverConfigAssert hasIntOption(DriverOption option, int expected) {
}

public DriverConfigAssert hasIntOption(String profileName, DriverOption option, int expected) {
assertThat(actual.getNamedProfile(profileName).getInt(option)).isEqualTo(expected);
assertThat(actual.getProfile(profileName).getInt(option)).isEqualTo(expected);
return this;
}
}
Expand Up @@ -150,7 +150,7 @@ public void should_update_derived_profiles_after_reloading() {
DriverConfigProfile derivedFromDefault =
config.getDefaultProfile().withInt(MockOptions.OPTIONAL_INT, 50);
DriverConfigProfile derivedFromProfile1 =
config.getNamedProfile("profile1").withInt(MockOptions.OPTIONAL_INT, 51);
config.getProfile("profile1").withInt(MockOptions.OPTIONAL_INT, 51);

config.reload(
ConfigFactory.parseString(
Expand Down Expand Up @@ -178,7 +178,7 @@ public void should_enumerate_options() {
entry("auth_provider.auth_thing_two", "two"),
entry("required_int", 42));

assertThat(config.getNamedProfile("profile1").entrySet())
assertThat(config.getProfile("profile1").entrySet())
.containsExactly(
entry("auth_provider.auth_thing_one", "one"),
entry("auth_provider.auth_thing_three", "three"),
Expand Down
Expand Up @@ -65,7 +65,7 @@ public static void setup() {
// sanity checks
DriverContext context = sessionRule.session().getContext();
DriverConfig config = context.config();
assertThat(config.getNamedProfiles()).containsKeys("profile1", "profile2");
assertThat(config.getProfiles()).containsKeys("profile1", "profile2");

assertThat(context.loadBalancingPolicies())
.hasSize(3)
Expand Down
Expand Up @@ -86,7 +86,7 @@ public static void setup() {
// sanity checks
DriverContext context = sessionRule.session().getContext();
DriverConfig config = context.config();
assertThat(config.getNamedProfiles()).containsKeys("profile1", "profile2");
assertThat(config.getProfiles()).containsKeys("profile1", "profile2");

assertThat(context.retryPolicies())
.hasSize(3)
Expand Down
Expand Up @@ -394,7 +394,7 @@ private CqlSession buildSessionWithProfile(
// validate profile data
DriverContext context = session.getContext();
DriverConfig driverConfig = context.config();
assertThat(driverConfig.getNamedProfiles()).containsKeys("profile1", "profile2");
assertThat(driverConfig.getProfiles()).containsKeys("profile1", "profile2");

assertThat(context.speculativeExecutionPolicies())
.hasSize(3)
Expand Down
4 changes: 2 additions & 2 deletions manual/core/configuration/README.md
Expand Up @@ -134,10 +134,10 @@ The driver's context exposes a [DriverConfig] instance:
```java
DriverConfig config = session.getContext().config();
DriverConfigProfile defaultProfile = config.getDefaultProfile();
DriverConfigProfile olapProfile = config.getNamedProfile("olap");
DriverConfigProfile olapProfile = config.getProfile("olap");

// This method creates a defensive copy of the map, do not use in performance-sensitive code:
config.getNamedProfiles().forEach((name, profile) -> ...);
config.getProfiles().forEach((name, profile) -> ...);
```

[DriverConfigProfile] has typed option getters:
Expand Down

0 comments on commit 44aa835

Please sign in to comment.