Skip to content

Commit 5465e5a

Browse files
committed
Fix test after CachedSupplier update
There were some issues after the merge with master related timing because of the CachedSupplier update from #3275.
1 parent 3ad2ec7 commit 5465e5a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

core/aws-core/src/test/java/software/amazon/awssdk/awscore/internal/token/CachedTokenRefresherTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.function.Function;
3030
import java.util.function.Supplier;
3131
import org.junit.jupiter.api.Test;
32-
import org.mockito.Mockito;
3332
import software.amazon.awssdk.auth.token.credentials.SdkToken;
3433
import software.amazon.awssdk.core.exception.SdkClientException;
3534
import software.amazon.awssdk.core.exception.SdkException;
@@ -173,38 +172,38 @@ public void prefetchToken_whenTokenNotStale_and_withinPrefetchTime() throws Inte
173172

174173
CachedTokenRefresher cachedTokenRefresher = CachedTokenRefresher.builder()
175174
.asyncRefreshEnabled(true)
176-
.staleDuration(Duration.ofMillis(3))
175+
.staleDuration(Duration.ofMillis(1000))
177176
.tokenRetriever(mockCache)
178177
.prefetchTime(Duration.ofMillis(1500))
179178
.build();
180179

181180
// Sleep is invoked to make sure executor executes refresh in initializeCachedSupplier() in NonBlocking CachedSupplier.PrefetchStrategy
182-
Thread.sleep(2);
183-
verify(mockCache, times(1)).get();
181+
Thread.sleep(1000);
182+
verify(mockCache, times(0)).get();
184183
SdkToken firstRetrieved = cachedTokenRefresher.refreshIfStaleAndFetch();
185184
assertThat(firstRetrieved).isEqualTo(firstToken);
186185

187-
Thread.sleep(10);
186+
Thread.sleep(1000);
188187
// Sleep to make sure the Async prefetch thread is picked up
189-
verify(mockCache, times(2)).get();
188+
verify(mockCache, times(1)).get();
190189
SdkToken secondRetrieved = cachedTokenRefresher.refreshIfStaleAndFetch();
191190
// Note that since the token has already been prefetched mockCache.get() is not called again thus it is secondToken.
192191
assertThat(secondRetrieved).isEqualTo(secondToken);
193192

194-
Thread.sleep(10);
193+
Thread.sleep(1000);
195194
// Sleep to make sure the Async prefetch thread is picked up
196-
verify(mockCache, times(3)).get();
195+
verify(mockCache, times(2)).get();
197196
SdkToken thirdRetrievedToken = cachedTokenRefresher.refreshIfStaleAndFetch();
198197
assertThat(thirdRetrievedToken).isEqualTo(thirdToken);
199198

200199
// Sleep to make sure the Async prefetch thread is picked up
201-
Thread.sleep(10);
202-
verify(mockCache, times(4)).get();
200+
Thread.sleep(1000);
201+
verify(mockCache, times(3)).get();
203202
SdkToken fourthRetrievedToken = cachedTokenRefresher.refreshIfStaleAndFetch();
204203
assertThat(fourthRetrievedToken).isEqualTo(fourthToken);
205204

206205
// Sleep to make sure the Async prefetch thread is picked up
207-
Thread.sleep(10);
206+
Thread.sleep(1000);
208207
verify(mockCache, times(4)).get();
209208
SdkToken fifthToken = cachedTokenRefresher.refreshIfStaleAndFetch();
210209
// Note that since Fourth token's expiry date is too high the prefetch is no longer done and the last fetch token is used.
@@ -221,11 +220,12 @@ public void refreshEveryTime_when_ExpirationDateDoesNotExist() throws Interrupte
221220
TestToken token2 = TestToken.builder().token("token2").build();
222221
when(supplier.get()).thenReturn(token1).thenReturn(token2);
223222

223+
224224
CachedTokenRefresher tokenRefresher = tokenRefresherBuilder().tokenRetriever(supplier).build();
225225

226226
SdkToken firstRefreshToken = tokenRefresher.refreshIfStaleAndFetch();
227227
assertThat(firstRefreshToken).isEqualTo(token1);
228-
Thread.sleep(50);
228+
Thread.sleep(1000);
229229
SdkToken secondRefreshToken = tokenRefresher.refreshIfStaleAndFetch();
230230
assertThat(secondRefreshToken).isEqualTo(token2);
231231
}
@@ -243,4 +243,4 @@ private TestToken.Builder getTestTokenBuilder() {
243243
return TestToken.builder().token("sampleToken")
244244
.start_url("start_url");
245245
}
246-
}
246+
}

0 commit comments

Comments
 (0)