CloudStore { boolean removeExpiredCredentials() { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Checking for expired cached credentials in {} entries", awsCredsCache.size()); } long now = System.currentTimeMillis(); return awsCredsCache.entrySet().removeIf(entry -> entry.getValue().getExpiration().millis() < now); } CloudStore(); void close(); void setHttpClient(HttpClient client); boolean isAwsEnabled(); AmazonS3 getS3Client(); AWSTemporaryCredentials assumeAWSRole(String account, String roleName, String principal,
                                                 Integer durationSeconds, String externalId); String getCloudAccount(String domainName);  }
@Test public void testRemoveExpiredCredentials() { CloudStore cloudStore = new CloudStore(); AWSTemporaryCredentials creds = new AWSTemporaryCredentials(); creds.setAccessKeyId("keyid"); creds.setSecretAccessKey("accesskey"); creds.setSessionToken("token"); creds.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + 3600*1000)); cloudStore.putCacheCreds("account:role:user::", creds); assertFalse(cloudStore.removeExpiredCredentials()); AWSTemporaryCredentials creds2 = new AWSTemporaryCredentials(); creds2.setAccessKeyId("keyid"); creds2.setSecretAccessKey("accesskey"); creds2.setSessionToken("token"); creds2.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() - 1000)); cloudStore.putCacheCreds("account:role:user2::", creds2); assertTrue(cloudStore.removeExpiredCredentials()); cloudStore.close(); }