Skip to content

Conversation

@emerkle826
Copy link
Contributor

  • Change SessionBuilder so that it can take a custom map of startup options to use when building a DriverContext.
  • Change DefaultDriverContext to build a map of startup options that appends any custom options set on the SessionBuilder to the list of Internal options sent.
  • Change ProtocolInitHandler to use the startup options from the DriverContext when constructing a Startup message. This requires JAVA-1932: Send DRIVER_NAME and DRIVER_VERSION in Startup datastax/native-protocol#24 to be merged.

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.

public SelfT withStartupOptions(@Nullable Map<String, String> options) {
this.startupOptions = options;
return self;
}
Copy link
Contributor

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);
Copy link
Contributor

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 {
Copy link
Contributor

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:

  1. I find the name a bit misleading, because in the rest of the code "startup options" refers to a Map<String, String>. This shows in DefaultDriverContext, where we have a buildStartupOptions method that constructs an InternalStartupOptions, but eventually returns a map.
  2. 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) {
Copy link
Contributor

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();
}

Copy link
Contributor

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 {
Copy link
Contributor

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() {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@emerkle826 emerkle826 force-pushed the java1932 branch 3 times, most recently from 3b804c5 to 34db712 Compare August 29, 2018 20:19
@NonNull
@Override
public Map<String, String> getStartupOptions() {
return startupOptionsBuilderRef.get().build();
Copy link
Contributor

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?

Copy link
Contributor Author

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)}.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants