@@ -85,7 +85,6 @@ public class DatabaseAdminClientTest {
85
85
private static MockOperationsServiceImpl mockOperations ;
86
86
private static MockDatabaseAdminServiceImpl mockDatabaseAdmin ;
87
87
private static Server server ;
88
- private static InetSocketAddress address ;
89
88
90
89
private static Spanner spanner ;
91
90
private static DatabaseAdminClient client ;
@@ -98,7 +97,7 @@ public static void startStaticServer() throws Exception {
98
97
mockOperations = new MockOperationsServiceImpl ();
99
98
mockDatabaseAdmin = new MockDatabaseAdminServiceImpl (mockOperations );
100
99
// This test uses a NettyServer to properly test network and timeout issues.
101
- address = new InetSocketAddress ("localhost" , 0 );
100
+ InetSocketAddress address = new InetSocketAddress ("localhost" , 0 );
102
101
server =
103
102
NettyServerBuilder .forAddress (address )
104
103
.addService (mockOperations )
@@ -952,14 +951,20 @@ public void testRetriesDisabledForOperationOnAdminMethodQuotaPerMinutePerProject
952
951
Status .RESOURCE_EXHAUSTED .withDescription ("foo" ).asRuntimeException (trailers ));
953
952
mockDatabaseAdmin .clearRequests ();
954
953
955
- Spanner spannerWithoutRetries =
956
- spanner .getOptions ().toBuilder ().disableAdministrativeRequestRetries ().build ().getService ();
957
- AdminRequestsPerMinuteExceededException exception =
958
- assertThrows (
959
- AdminRequestsPerMinuteExceededException .class ,
960
- () -> spannerWithoutRetries .getDatabaseAdminClient ().getDatabase (INSTANCE_ID , DB_ID ));
961
- assertEquals (ErrorCode .RESOURCE_EXHAUSTED , exception .getErrorCode ());
962
- // There should be only one request on the server, as the request was not retried.
963
- assertEquals (1 , mockDatabaseAdmin .countRequestsOfType (GetDatabaseRequest .class ));
954
+ try (Spanner spannerWithoutRetries =
955
+ spanner
956
+ .getOptions ()
957
+ .toBuilder ()
958
+ .disableAdministrativeRequestRetries ()
959
+ .build ()
960
+ .getService ()) {
961
+ AdminRequestsPerMinuteExceededException exception =
962
+ assertThrows (
963
+ AdminRequestsPerMinuteExceededException .class ,
964
+ () -> spannerWithoutRetries .getDatabaseAdminClient ().getDatabase (INSTANCE_ID , DB_ID ));
965
+ assertEquals (ErrorCode .RESOURCE_EXHAUSTED , exception .getErrorCode ());
966
+ // There should be only one request on the server, as the request was not retried.
967
+ assertEquals (1 , mockDatabaseAdmin .countRequestsOfType (GetDatabaseRequest .class ));
968
+ }
964
969
}
965
970
}
0 commit comments