@Test
    public void getCredentials_onlyCallsImdsOnceEvenWithExpiredCredentials() {
        mockServer.setResponseContent(responseWithExpiration(DateTime.now().minusHours(1)));
        mockServer.setAvailableSecurityCredentials("test-credentials");

        InstanceProfileCredentialsProvider credentialsProvider = InstanceProfileCredentialsProvider.getInstance();

        credentialsProvider.getCredentials();

        int requestCountAfterOneRefresh = mockServer.getRequestCount();

        credentialsProvider.getCredentials();
        credentialsProvider.getCredentials();

        int requestCountAfterThreeRefreshes = mockServer.getRequestCount();

        assertEquals(requestCountAfterOneRefresh, requestCountAfterThreeRefreshes);
    }
Tests by initiating a refresh thread in parallel which refreshes the
credentials. Next call to credentials provider will result in refreshing
and getting new credentials.
aws-java-sdk-core/src/test/java/com/amazonaws/auth/InstanceProfileCredentialsProviderIntegrationTest.java