ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public void refresh() { if (profilesConfigFile != null) { profilesConfigFile.refresh(); lastRefreshed = System.nanoTime(); } } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); @Override AWSCredentials getCredentials(); @Override void refresh(); long getRefreshIntervalNanos(); void setRefreshIntervalNanos(long refreshIntervalNanos); long getRefreshForceIntervalNanos(); void setRefreshForceIntervalNanos(long refreshForceIntervalNanos);  }
@Test public void testRefresh() throws Exception { ProfilesConfigFile profilesConfigFileBeforeRefresh = new ProfilesConfigFile( ProfileResourceLoader.basicProfile().asFile()); File profilesFile = File.createTempFile("UpdatableProfile", ".tst"); ProfilesConfigFileWriter.dumpToFile(profilesFile, true, profilesConfigFileBeforeRefresh.getAllProfiles() .values().toArray(new Profile[1])); ProfileCredentialsProvider profileCredentialsProvider = new ProfileCredentialsProvider( profilesFile.getPath(), null); Thread.sleep(1000); ProfilesConfigFile profilesConfigFileAfterRefresh = new ProfilesConfigFile( ProfileResourceLoader.basicProfile2().asFile()); ProfilesConfigFileWriter.dumpToFile(profilesFile, true, profilesConfigFileAfterRefresh.getAllProfiles().values() .toArray(new Profile[1])); profileCredentialsProvider.setRefreshIntervalNanos(1l); AWSCredentials credentialsAfterRefresh = profileCredentialsProvider.getCredentials(); Assert.assertEquals("credentialsAfterRefresh AWSAccessKeyId", "accessKey2", credentialsAfterRefresh.getAWSAccessKeyId()); Assert.assertEquals("credentialsAfterRefresh AWSSecretKey", "secretAccessKey2", credentialsAfterRefresh.getAWSSecretKey()); }
@Test public void testRefresh() throws Exception { ProfilesConfigFile profilesConfigFileBeforeRefresh = new ProfilesConfigFile(getLocationForTestFile("BasicProfile.tst")); File profilesFile = File.createTempFile("UpdatableProfile", ".tst"); ProfilesConfigFileWriter.dumpToFile(profilesFile, true, profilesConfigFileBeforeRefresh.getAllProfiles().values().toArray(new Profile[1])); ProfileCredentialsProvider profileCredentialsProvider = new ProfileCredentialsProvider(profilesFile.getPath(), null); Thread.sleep(1000); ProfilesConfigFile profilesConfigFileAfterRefresh = new ProfilesConfigFile(getLocationForTestFile("BasicProfile2.tst")); ProfilesConfigFileWriter.dumpToFile(profilesFile, true, profilesConfigFileAfterRefresh.getAllProfiles().values().toArray(new Profile[1])); profileCredentialsProvider.setRefreshIntervalNanos(1l); AWSCredentials credentialsAfterRefresh = profileCredentialsProvider.getCredentials(); Assert.assertEquals("credentialsAfterRefresh AWSAccessKeyId", "accessKey2", credentialsAfterRefresh.getAWSAccessKeyId()); Assert.assertEquals("credentialsAfterRefresh AWSSecretKey", "secretAccessKey2", credentialsAfterRefresh.getAWSSecretKey()); }