This repository was archived by the owner on Apr 7, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
main/java/com/google/cloud/spanner/connection
test/java/com/google/cloud/spanner/connection Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 * A mutable {@link Credentials} implementation that delegates authentication behavior to a scoped
2727 * {@link ServiceAccountCredentials} instance.
2828 *
29- * <p>This class is intended for scenarios where an application needs to rotate or replace the
30- * underlying service account credentials for a running Spanner Client.
29+ * <p>This class is intended for scenarios where an application needs to replace the underlying
30+ * service account credentials for a long running Spanner Client.
3131 *
3232 * <p>All operations inherited from {@link Credentials} are forwarded to the current delegate,
3333 * including request metadata retrieval and token refresh. Calling {@link
3636 * constructed.
3737 */
3838public class MutableCredentials extends Credentials {
39- ServiceAccountCredentials delegate ;
40- List <String > scopes ;
39+ private volatile ServiceAccountCredentials delegate ;
40+ private final List <String > scopes ;
4141
4242
4343 public MutableCredentials (ServiceAccountCredentials credentials , List <String > scopes ) {
Original file line number Diff line number Diff line change @@ -92,3 +92,4 @@ public void testMutableCredentialsUpdateAuthorizationForRunningClient() throws I
9292 }
9393 }
9494}
95+
Original file line number Diff line number Diff line change @@ -52,9 +52,8 @@ public class MutableCredentialsTest {
5252 String updatedAuthType = "auth-2" ;
5353
5454 @ Test
55- public void testCreateMutableCredentialsAndUpdate () throws IOException {
55+ public void testCreateMutableCredentials () throws IOException {
5656 setupInitialCredentials ();
57- setupUpdatedCredentials ();
5857
5958 MutableCredentials credentials = new MutableCredentials (initialCredentials , scopes );
6059
@@ -68,6 +67,16 @@ public void testCreateMutableCredentialsAndUpdate() throws IOException {
6867 credentials .refresh ();
6968
7069 verify (initialScopedCredentials , times (1 )).refresh ();
70+ }
71+
72+ @ Test
73+ public void testUpdateMutableCredentials () throws IOException {
74+ setupInitialCredentials ();
75+ setupUpdatedCredentials ();
76+
77+ MutableCredentials credentials = new MutableCredentials (initialCredentials , scopes );
78+
79+ assertEquals (initialAuthType , credentials .getAuthenticationType ());
7180
7281 credentials .updateCredentials (updatedCredentials );
7382
@@ -97,3 +106,4 @@ private void setupUpdatedCredentials() throws IOException {
97106 when (updatedScopedCredentials .hasRequestMetadataOnly ()).thenReturn (false );
98107 }
99108}
109+
You can’t perform that action at this time.
0 commit comments