Skip to content

Commit 7506ff6

Browse files
committed
[fixup] prevent rebuilding startup options for each connection, clean up javadocs
1 parent b5ea3d4 commit 7506ff6

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ public class DefaultDriverContext implements InternalDriverContext {
181181
private final LazyReference<NodeStateListener> nodeStateListenerRef;
182182
private final LazyReference<SchemaChangeListener> schemaChangeListenerRef;
183183
private final LazyReference<RequestTracker> requestTrackerRef;
184-
private final LazyReference<StartupOptionsBuilder> startupOptionsBuilderRef =
185-
new LazyReference<>("startupOptionsBuilder", this::buildStartupOptions, cycleDetector);
186184

187185
private final DriverConfig config;
188186
private final DriverConfigLoader configLoader;
@@ -194,6 +192,7 @@ public class DefaultDriverContext implements InternalDriverContext {
194192
private final RequestTracker requestTrackerFromBuilder;
195193
private final Map<String, Predicate<Node>> nodeFiltersFromBuilder;
196194
private final ClassLoader classLoader;
195+
private final Map<String, String> startupOptions;
197196

198197
public DefaultDriverContext(
199198
DriverConfigLoader configLoader,
@@ -230,6 +229,7 @@ public DefaultDriverContext(
230229
"requestTracker", () -> buildRequestTracker(requestTrackerFromBuilder), cycleDetector);
231230
this.nodeFiltersFromBuilder = nodeFilters;
232231
this.classLoader = classLoader;
232+
this.startupOptions = buildStartupOptions().build();
233233
}
234234

235235
/**
@@ -748,6 +748,6 @@ public ProtocolVersion getProtocolVersion() {
748748
@NonNull
749749
@Override
750750
public Map<String, String> getStartupOptions() {
751-
return startupOptionsBuilderRef.get().build();
751+
return startupOptions;
752752
}
753753
}

core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public StartupOptionsBuilder(InternalDriverContext context) {
4848
* constructor will add {@link
4949
* com.datastax.oss.protocol.internal.request.Startup#CQL_VERSION_KEY}.
5050
*
51-
* <p>Additional options can be set via {@link #withAdditionalOptions(java.util.Map)}.
52-
*
5351
* @return Map of Startup Options.
5452
*/
5553
public Map<String, String> build() {
@@ -70,9 +68,6 @@ public Map<String, String> build() {
7068
*
7169
* <p>By default, this method will pull from the bundled Driver.properties file. Subclasses should
7270
* override this method if they need to report a different Driver name on Startup.
73-
*
74-
* <p><b>NOTE:</b> The Driver name can not be set via {@link
75-
* #withAdditionalOptions(java.util.Map)}
7671
*/
7772
protected String getDriverName() {
7873
return MAVEN_COORDINATES.getName();
@@ -83,9 +78,6 @@ protected String getDriverName() {
8378
*
8479
* <p>By default, this method will pull from the bundled Driver.properties file. Subclasses should
8580
* override this method if they need to report a different Driver version on Startup.
86-
*
87-
* <p><b>NOTE:</b> The Driver version can not be set via {@link
88-
* #withAdditionalOptions(java.util.Map)}
8981
*/
9082
protected String getDriverVersion() {
9183
return MAVEN_COORDINATES.getVersion().toString();

core/src/test/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilderTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public void before() {
6666
MockitoAnnotations.initMocks(this);
6767
Mockito.when(configLoader.getInitialConfig()).thenReturn(driverConfig);
6868
Mockito.when(driverConfig.getDefaultProfile()).thenReturn(defaultProfile);
69+
}
70+
71+
private void buildDriverContext() {
6972
defaultDriverContext =
7073
new DefaultDriverContext(
7174
configLoader,
@@ -88,6 +91,7 @@ private void assertDefaultStartupOptions(Startup startup) {
8891

8992
@Test
9093
public void should_build_minimal_startup_options() {
94+
buildDriverContext();
9195
Startup startup = new Startup(defaultDriverContext.getStartupOptions());
9296
assertThat(startup.options).doesNotContainKey(Startup.COMPRESSION_KEY);
9397
assertDefaultStartupOptions(startup);
@@ -99,6 +103,7 @@ public void should_build_startup_options_with_compression() {
99103
.thenReturn(Boolean.TRUE);
100104
Mockito.when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION))
101105
.thenReturn("lz4");
106+
buildDriverContext();
102107
Startup startup = new Startup(defaultDriverContext.getStartupOptions());
103108
// assert the compression option is present
104109
assertThat(startup.options).containsEntry(Startup.COMPRESSION_KEY, "lz4");

0 commit comments

Comments
 (0)