chore: add getter for database role in DatabaseClient and BatchClient#2029
chore: add getter for database role in DatabaseClient and BatchClient#2029ansh0l merged 11 commits intogoogleapis:mainfrom
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.
| 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.
nit: remove extra newline.
| Clock clock) { | ||
| return createPool( | ||
| poolOptions, | ||
| "", |
There was a problem hiding this comment.
Should we pass in null here?
| "", | |
| null, |
| } | ||
| } | ||
|
|
||
| String getDatabaseRole() { |
There was a problem hiding this comment.
| String getDatabaseRole() { | |
| public String getDatabaseRole() { |
| Clock clock, MetricRegistry metricRegistry, List<LabelValue> labelValues) { | ||
| return SessionPool.createPool( | ||
| options, | ||
| "", |
There was a problem hiding this comment.
| "", | |
| 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.
| 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.
| 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.
| 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.
LGTM.
@olavloite: Can you please take a look at this PR once? Thanks!
olavloite
left a comment
There was a problem hiding this comment.
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.
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 |
No description provided.