-
Notifications
You must be signed in to change notification settings - Fork 888
JAVA-1932: Send DRIVER_NAME and DRIVER_VERSION in Startup #1087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| public SelfT withStartupOptions(@Nullable Map<String, String> options) { | ||
| this.startupOptions = options; | ||
| return self; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should call this with[Additional|Extra|Custom]StartupOptions to emphasize the fact that CQL version and compression are not required (in fact for compression it is probably even recommended to not mess with it manually, and instead let the driver inspect the configured compressor).
This method also needs javadocs to explain all this.
Nit: could we also move it after withClassLoader? I know that ultimately method order does not matter, but it's convenient to have all the boilerplate withXxx together, and then the more interesting methods.
| NullAllowingImmutableMap.Builder<String, String> builder = NullAllowingImmutableMap.builder(); | ||
| builder.putAll(new InternalStartupOptions(this).getOptions()); | ||
| if (options != null) { | ||
| builder.putAll(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAIM.builder() does not support duplicate entries. Won't that be a problem if the client passes CQL_VERSION or COMPRESSION in their map?
We should either prevent that, or check the map to allow the user to override those fields (although the use case is dubious).
| import net.jcip.annotations.Immutable; | ||
|
|
||
| @Immutable | ||
| public class InternalStartupOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to use a separate utility class, this makes tests easier. But:
- I find the name a bit misleading, because in the rest of the code "startup options" refers to a
Map<String, String>. This shows inDefaultDriverContext, where we have abuildStartupOptionsmethod that constructs anInternalStartupOptions, but eventually returns a map. - currently the caller still has to merge the additional options manually, why not make this part of the utility class as well?
I'm thinking of turning it into a builder:
Map<String, String> options =
new StartupOptionsBuilder(context)
.withAdditionalOptions(additionalOptions)
.build();build() would contain the logic of the current buildOptions(), while also avoiding duplicates if they were already provided in additionalOptions.
| * Builds a map of options to use when sending a Startup message. The options argument passed in | ||
| * will append to, or overwrite, the Internal default options sent by the driver. | ||
| */ | ||
| protected Map<String, String> buildStartupOptions(Map<String, String> options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to make this protected.
| writeInboundFrame(readOutboundFrame(), TestResponses.clusterNameResponse("someClusterName")); | ||
| assertThat(connectFuture).isSuccess(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 that makes sense, the only thing this was testing was the options map, and since it's now built outside of the handler, covering it here wouldn't be very useful.
| import org.mockito.Mockito; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
| public class DefaultDriverContextTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called InternalStartupOptionsTest (or the corresponding test name if we rename that class).
| } | ||
|
|
||
| @Test | ||
| public void test_default_startup_options() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could you use the should_ convention for consistency with the rest of the codebase? For example:
should_build_minimal_startup_options
should_build_startup_options_with_compression
should_build_startup_options_with_custom_options
And I would also cover the cases where the custom options contain one of the default ones or the compression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I forgot about this from my last PR. I need to break my old habit of test method names.
3b804c5 to
34db712
Compare
| @NonNull | ||
| @Override | ||
| public Map<String, String> getStartupOptions() { | ||
| return startupOptionsBuilderRef.get().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options are now rebuilt on every call. Did you want to leave the door open in case we ever need an option that would change for every new connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that wasn't the intent. I imagine the options won't change over the course of normal operation.
| * constructor will add {@link | ||
| * com.datastax.oss.protocol.internal.request.Startup#CQL_VERSION_KEY}. | ||
| * | ||
| * <p>Additional options can be set via {@link #withAdditionalOptions(java.util.Map)}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now outdated.
withAdditionalOptions is referenced in two other comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
The end result here is for the DriverContext to allow for custom startup options to be added to the map of options we are already sending in a Startup message.