-
Notifications
You must be signed in to change notification settings - Fork 118
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
feat(spanner): add support for external hosts #3474
base: main
Are you sure you want to change the base?
Conversation
🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use -- conventional-commit-lint bot |
a09b78b
to
f1b5719
Compare
@@ -49,10 +51,16 @@ private SessionId(DatabaseId db, String name) { | |||
static SessionId of(String name) { | |||
Preconditions.checkNotNull(name); | |||
Map<String, String> parts = NAME_TEMPLATE.match(name); | |||
if (parts == null) { | |||
parts = EXTERNAL_HOST_NAME_TEMPLATE.match(name); |
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.
Can you add unit tests to cover this pattern and ensure the functionality works as intended?
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.
Added unit test to cover existing pattern (for regression) as well as new pattern
@@ -94,6 +94,11 @@ public static DatabaseId of(String project, String instance, String database) { | |||
return new DatabaseId(new InstanceId(project, instance), database); | |||
} | |||
|
|||
/** Creates a {@code DatabaseId} given instance and database IDs. */ | |||
public static DatabaseId of(String instance, String database) { | |||
return new DatabaseId(new InstanceId("default", instance), database); |
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.
I think we should document to users that this method assumes instance Id to be "default".
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 not instance Id, but rather project Id?
@@ -94,6 +94,11 @@ public static DatabaseId of(String project, String instance, String database) { | |||
return new DatabaseId(new InstanceId(project, instance), database); | |||
} | |||
|
|||
/** Creates a {@code DatabaseId} with "default" project, given instance and database IDs. */ |
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 nit pick: "default" as project id.
try { | ||
SessionId.of(host); | ||
SessionId.of(externalHost); | ||
// If no exceptions are thrown, the test will pass |
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.
Is it possible to add assertEquas here to validate all the attributes instanceid, projectid and databaseid as set in both the scenarios?
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.
added assert for session name.
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.
LGTM, with a couple of tiny nits.
@@ -94,6 +94,15 @@ public static DatabaseId of(String project, String instance, String database) { | |||
return new DatabaseId(new InstanceId(project, instance), database); | |||
} | |||
|
|||
/** Creates a {@code DatabaseId} with "default" as project id, given instance and database IDs. */ |
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.
/** Creates a {@code DatabaseId} with "default" as project id, given instance and database IDs. */ | |
/** Creates a {@code DatabaseId} with the default project ID of this environment and the given instance and database IDs. The project ID is set to "default" if no project ID could be found for this environment. */ |
/** Creates a {@code DatabaseId} with "default" as project id, given instance and database IDs. */ | ||
public static DatabaseId of(String instance, String database) { | ||
String projectId = SpannerOptions.getDefaultProjectId(); | ||
if (projectId == null) { |
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: maybe use Strings.isNullOrEmpty(String)
instead. That prevents an empty string from being used as the project ID.
SessionId externalHostSession = SessionId.of(externalHost); | ||
assertEquals("abcd1234", externalHostSession.getName()); | ||
// If no exceptions are thrown, the test will pass | ||
} catch (IllegalArgumentException e) { |
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: you can remove the entire try-catch block. If a (runtime) exception occurs during a test, then this test will be marked as failed with the error message. I.e. you will get the exact same behavior as you have now with the try-catch block, but with a bit less code and indentation.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️
If you write sample code, please follow the samples format.