@@ -68,6 +68,7 @@ private static void repeat(int number, IntConsumer c) {
6868 public void exceptionSecretCacheTest () {
6969 SecretCache sc = new SecretCache ();
7070 sc .getSecretString ("" );
71+ sc .close ();
7172 }
7273
7374 @ Test (expectedExceptions = {SdkClientException .class })
@@ -87,9 +88,11 @@ public void secretCacheConstructorTest() {
8788 SecretCache sc2 = null ;
8889 try {
8990 sc1 = new SecretCache ((SecretCacheConfiguration )null );
91+ sc1 .close ();
9092 } catch (Exception e ) {}
9193 try {
9294 sc2 = new SecretCache ((AWSSecretsManagerClientBuilder )null );
95+ sc2 .close ();
9396 } catch (Exception e ) {}
9497 }
9598
@@ -150,6 +153,7 @@ public Object get(final Object o) {
150153 repeat (10 , n -> Assert .assertEquals (sc .getSecretBinary ("" ),
151154 ByteBuffer .wrap (secret .getBytes ())));
152155 Assert .assertEquals (hook .getCount (), 2 );
156+ sc .close ();
153157 }
154158
155159 @ Test
@@ -172,6 +176,7 @@ public void secretCacheNullStagesTest() {
172176
173177 repeat (10 , n -> Assert .assertEquals (sc .getSecretBinary ("" ),
174178 ByteBuffer .wrap (secret .getBytes ())));
179+ sc .close ();
175180 }
176181
177182 @ Test
@@ -198,6 +203,7 @@ public void basicSecretCacheRefreshNowTest() throws Throwable {
198203 repeat (10 , n -> Assert .assertEquals (sc .getSecretString ("" ), secret ));
199204 Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
200205 Mockito .verify (asm , Mockito .times (1 )).getSecretValue (Mockito .any ());
206+ sc .close ();
201207 }
202208
203209 @ Test
@@ -221,6 +227,7 @@ public void basicSecretCacheByteBufferTest() {
221227
222228 repeat (10 , n -> Assert .assertEquals (sc .getSecretBinary ("" ),
223229 ByteBuffer .wrap (secret .getBytes ())));
230+ sc .close ();
224231 }
225232
226233 @ Test
@@ -242,6 +249,7 @@ public void basicSecretCacheMultipleTest() {
242249 // Verify that multiple requests did not call the API
243250 Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
244251 Mockito .verify (asm , Mockito .times (2 )).getSecretValue (Mockito .any ());
252+ sc .close ();
245253 }
246254
247255 @ Test
@@ -312,30 +320,30 @@ public void basicSecretCacheTestNoVersions() {
312320 // Verify that multiple requests did not call the API
313321 Mockito .verify (asm , Mockito .times (1 )).describeSecret (Mockito .any ());
314322 Mockito .verify (asm , Mockito .times (0 )).getSecretValue (Mockito .any ());
323+ sc .close ();
315324 }
316325
317326 @ Test (expectedExceptions = {RuntimeException .class })
318327 public void basicSecretCacheExceptionTest () {
319- final String secret = "basicSecretCacheExceptionTest" ;
320328 Mockito .when (asm .describeSecret (Mockito .any ())).thenThrow (new RuntimeException ());
321329 SecretCache sc = new SecretCache (asm );
322330 sc .getSecretString ("" );
331+ sc .close ();
323332 }
324333
325334 @ Test
326335 public void basicSecretCacheExceptionRefreshNowTest () throws Throwable {
327- final String secret = "basicSecretCacheExceptionTest" ;
328336 Mockito .when (asm .describeSecret (Mockito .any ())).thenThrow (new RuntimeException ());
329337 SecretCache sc = new SecretCache (asm );
330338 Assert .assertFalse (sc .refreshNow ("" ));
331339 Mockito .verify (asm , Mockito .times (1 )).describeSecret (Mockito .any ());
332340 Assert .assertFalse (sc .refreshNow ("" ));
333341 Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
342+ sc .close ();
334343 }
335344
336345 @ Test
337346 public void basicSecretCacheExceptionRetryTest () throws Throwable {
338- final String secret = "basicSecretCacheExceptionTest" ;
339347 final int retryCount = 10 ;
340348 Mockito .when (asm .describeSecret (Mockito .any ())).thenThrow (new RuntimeException ());
341349 SecretCache sc = new SecretCache (asm );
@@ -357,22 +365,23 @@ public void basicSecretCacheExceptionRetryTest() throws Throwable {
357365 } catch (RuntimeException ex ) {}
358366 // The api call should have been retried after the delay.
359367 Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
368+ sc .close ();
360369 }
361370
362371 @ Test
363372 public void basicSecretCacheNullTest () {
364- final String secret = "basicSecretCacheNullTest" ;
365373 Mockito .when (asm .describeSecret (Mockito .any ())).thenReturn (null );
366374 SecretCache sc = new SecretCache (asm );
367375 Assert .assertNull (sc .getSecretString ("" ));
376+ sc .close ();
368377 }
369378
370379 @ Test
371380 public void basicSecretCacheNullStagesTest () {
372- final String secret = "basicSecretCacheNullStagesTest" ;
373381 Mockito .when (describeSecretResult .getVersionIdsToStages ()).thenReturn (null );
374382 SecretCache sc = new SecretCache (asm );
375383 Assert .assertNull (sc .getSecretString ("" ));
384+ sc .close ();
376385 }
377386
378387 @ Test
@@ -390,6 +399,7 @@ public void basicSecretCacheVersionWithNullStageTest() {
390399 // Verify that multiple requests did not call the API
391400 Mockito .verify (asm , Mockito .times (1 )).describeSecret (Mockito .any ());
392401 Mockito .verify (asm , Mockito .times (0 )).getSecretValue (Mockito .any ());
402+ sc .close ();
393403 }
394404
395405}
0 commit comments