@@ -68,6 +68,7 @@ private static void repeat(int number, IntConsumer c) {
68
68
public void exceptionSecretCacheTest () {
69
69
SecretCache sc = new SecretCache ();
70
70
sc .getSecretString ("" );
71
+ sc .close ();
71
72
}
72
73
73
74
@ Test (expectedExceptions = {SdkClientException .class })
@@ -87,9 +88,11 @@ public void secretCacheConstructorTest() {
87
88
SecretCache sc2 = null ;
88
89
try {
89
90
sc1 = new SecretCache ((SecretCacheConfiguration )null );
91
+ sc1 .close ();
90
92
} catch (Exception e ) {}
91
93
try {
92
94
sc2 = new SecretCache ((AWSSecretsManagerClientBuilder )null );
95
+ sc2 .close ();
93
96
} catch (Exception e ) {}
94
97
}
95
98
@@ -150,6 +153,7 @@ public Object get(final Object o) {
150
153
repeat (10 , n -> Assert .assertEquals (sc .getSecretBinary ("" ),
151
154
ByteBuffer .wrap (secret .getBytes ())));
152
155
Assert .assertEquals (hook .getCount (), 2 );
156
+ sc .close ();
153
157
}
154
158
155
159
@ Test
@@ -172,6 +176,7 @@ public void secretCacheNullStagesTest() {
172
176
173
177
repeat (10 , n -> Assert .assertEquals (sc .getSecretBinary ("" ),
174
178
ByteBuffer .wrap (secret .getBytes ())));
179
+ sc .close ();
175
180
}
176
181
177
182
@ Test
@@ -198,6 +203,7 @@ public void basicSecretCacheRefreshNowTest() throws Throwable {
198
203
repeat (10 , n -> Assert .assertEquals (sc .getSecretString ("" ), secret ));
199
204
Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
200
205
Mockito .verify (asm , Mockito .times (1 )).getSecretValue (Mockito .any ());
206
+ sc .close ();
201
207
}
202
208
203
209
@ Test
@@ -221,6 +227,7 @@ public void basicSecretCacheByteBufferTest() {
221
227
222
228
repeat (10 , n -> Assert .assertEquals (sc .getSecretBinary ("" ),
223
229
ByteBuffer .wrap (secret .getBytes ())));
230
+ sc .close ();
224
231
}
225
232
226
233
@ Test
@@ -242,6 +249,7 @@ public void basicSecretCacheMultipleTest() {
242
249
// Verify that multiple requests did not call the API
243
250
Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
244
251
Mockito .verify (asm , Mockito .times (2 )).getSecretValue (Mockito .any ());
252
+ sc .close ();
245
253
}
246
254
247
255
@ Test
@@ -312,30 +320,30 @@ public void basicSecretCacheTestNoVersions() {
312
320
// Verify that multiple requests did not call the API
313
321
Mockito .verify (asm , Mockito .times (1 )).describeSecret (Mockito .any ());
314
322
Mockito .verify (asm , Mockito .times (0 )).getSecretValue (Mockito .any ());
323
+ sc .close ();
315
324
}
316
325
317
326
@ Test (expectedExceptions = {RuntimeException .class })
318
327
public void basicSecretCacheExceptionTest () {
319
- final String secret = "basicSecretCacheExceptionTest" ;
320
328
Mockito .when (asm .describeSecret (Mockito .any ())).thenThrow (new RuntimeException ());
321
329
SecretCache sc = new SecretCache (asm );
322
330
sc .getSecretString ("" );
331
+ sc .close ();
323
332
}
324
333
325
334
@ Test
326
335
public void basicSecretCacheExceptionRefreshNowTest () throws Throwable {
327
- final String secret = "basicSecretCacheExceptionTest" ;
328
336
Mockito .when (asm .describeSecret (Mockito .any ())).thenThrow (new RuntimeException ());
329
337
SecretCache sc = new SecretCache (asm );
330
338
Assert .assertFalse (sc .refreshNow ("" ));
331
339
Mockito .verify (asm , Mockito .times (1 )).describeSecret (Mockito .any ());
332
340
Assert .assertFalse (sc .refreshNow ("" ));
333
341
Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
342
+ sc .close ();
334
343
}
335
344
336
345
@ Test
337
346
public void basicSecretCacheExceptionRetryTest () throws Throwable {
338
- final String secret = "basicSecretCacheExceptionTest" ;
339
347
final int retryCount = 10 ;
340
348
Mockito .when (asm .describeSecret (Mockito .any ())).thenThrow (new RuntimeException ());
341
349
SecretCache sc = new SecretCache (asm );
@@ -357,22 +365,23 @@ public void basicSecretCacheExceptionRetryTest() throws Throwable {
357
365
} catch (RuntimeException ex ) {}
358
366
// The api call should have been retried after the delay.
359
367
Mockito .verify (asm , Mockito .times (2 )).describeSecret (Mockito .any ());
368
+ sc .close ();
360
369
}
361
370
362
371
@ Test
363
372
public void basicSecretCacheNullTest () {
364
- final String secret = "basicSecretCacheNullTest" ;
365
373
Mockito .when (asm .describeSecret (Mockito .any ())).thenReturn (null );
366
374
SecretCache sc = new SecretCache (asm );
367
375
Assert .assertNull (sc .getSecretString ("" ));
376
+ sc .close ();
368
377
}
369
378
370
379
@ Test
371
380
public void basicSecretCacheNullStagesTest () {
372
- final String secret = "basicSecretCacheNullStagesTest" ;
373
381
Mockito .when (describeSecretResult .getVersionIdsToStages ()).thenReturn (null );
374
382
SecretCache sc = new SecretCache (asm );
375
383
Assert .assertNull (sc .getSecretString ("" ));
384
+ sc .close ();
376
385
}
377
386
378
387
@ Test
@@ -390,6 +399,7 @@ public void basicSecretCacheVersionWithNullStageTest() {
390
399
// Verify that multiple requests did not call the API
391
400
Mockito .verify (asm , Mockito .times (1 )).describeSecret (Mockito .any ());
392
401
Mockito .verify (asm , Mockito .times (0 )).getSecretValue (Mockito .any ());
402
+ sc .close ();
393
403
}
394
404
395
405
}
0 commit comments