-
Notifications
You must be signed in to change notification settings - Fork 136
chore: add getter for database role in DatabaseClient and BatchClient #2029
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
… for beam unit tests
| * determines the access permissions that a connection has. This can for example be used to create | ||
| * connections that are only permitted to access certain tables. | ||
| */ | ||
| String getDatabaseRole(); |
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.
| String getDatabaseRole(); | |
| default String getDatabaseRole() { | |
| throw new UnsupportedOperationException("method should be overwritten"); | |
| } |
I think we should provide a default implementation for this method in the interface, so that it isn't a breaking change.
|
|
||
| private final SessionPoolOptions options; | ||
| private final SettableFuture<Dialect> dialect = SettableFuture.create(); | ||
|
|
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: remove extra newline.
| Clock clock) { | ||
| return createPool( | ||
| poolOptions, | ||
| "", |
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.
Should we pass in null here?
| "", | |
| null, |
| } | ||
| } | ||
|
|
||
| String getDatabaseRole() { |
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.
| String getDatabaseRole() { | |
| public String getDatabaseRole() { |
| Clock clock, MetricRegistry metricRegistry, List<LabelValue> labelValues) { | ||
| return SessionPool.createPool( | ||
| 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.
| "", | |
| null, |
| try (ResultSet rs = | ||
| dbClient.singleUse().executeQuery(Statement.of("SELECT COUNT(*) as cnt FROM T"))) { | ||
| assertTrue(rs.next()); | ||
| assertThat(dbClient.getDatabaseRole()).isEqualTo(dbRoleParent); |
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.
| assertThat(dbClient.getDatabaseRole()).isEqualTo(dbRoleParent); | |
| assertEquals(dbClient.getDatabaseRole(), dbRoleParent); |
nit: change to assertEquals.
|
@rahul2393 : Can we do the following as well?
|
cc008d9 to
c3c9e81
Compare
| import static com.google.cloud.spanner.MetricRegistryConstants.NUM_WRITE_SESSIONS; | ||
| import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS; | ||
| import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS_WITH_TYPE; | ||
| import static com.google.cloud.spanner.MetricRegistryConstants.*; |
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.
| import static com.google.cloud.spanner.MetricRegistryConstants.*; | |
| import static com.google.cloud.spanner.MetricRegistryConstants.NUM_IN_USE_SESSIONS; | |
| import static com.google.cloud.spanner.MetricRegistryConstants.NUM_READ_SESSIONS; | |
| import static com.google.cloud.spanner.MetricRegistryConstants.NUM_SESSIONS_BEING_PREPARED; | |
| import static com.google.cloud.spanner.MetricRegistryConstants.NUM_WRITE_SESSIONS; | |
| import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS; | |
| import static com.google.cloud.spanner.MetricRegistryConstants.SPANNER_LABEL_KEYS_WITH_TYPE; |
Google style requires us to never use wildcard imports: https://google.github.io/styleguide/javaguide.html
| } | ||
|
|
||
| @Test | ||
| public void testDatabaseRole() throws Exception { |
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.
| public void testDatabaseRole() throws Exception { | |
| public void testGetDatabaseRole() throws Exception { |
26e1438 to
ee9b14b
Compare
google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchClientImplTest.java
Outdated
Show resolved
Hide resolved
…tchClientImplTest.java
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.
@olavloite: Can you please take a look at this PR once? Thanks!
olavloite
left a comment
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 tiny nit on the Javadoc)
| BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batchTransactionId); | ||
|
|
||
| /** | ||
| * Returns the {@link DatabaseRole} used by the client connection. The database role that is used |
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: replace the {@link DatabaseRole} with just database role. DatabaseRole is not a valid class name, so it cannot be linked.
| } | ||
|
|
||
| /** | ||
| * Returns the {@link DatabaseRole} used by the client connection. The database role that is used |
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.
Same as above
No description provided.