@@ -433,8 +433,9 @@ void aggregate_duplicateOptionsGivenFixedProfileFirst_preservesPrecedence() {
433
433
}
434
434
435
435
@ Test
436
- void aggregate_duplicateOptionsGivenReloadingProfileFirst_preservesPrecedence () {
437
- AdjustableClock clock = new AdjustableClock ();
436
+ void aggregate_duplicateOptionsGivenReloadingProfileFirst_preservesPrecedence () throws IOException {
437
+ Instant startTime = Instant .now ();
438
+ AdjustableClock clock = new AdjustableClock (startTime );
438
439
439
440
ProfileFile configFile1 = configFile ("profile default" , Pair .of ("aws_access_key_id" , "config-key" ));
440
441
Path credentialsFilePath = generateTestCredentialsFile ("defaultAccessKey" , "defaultSecretAccessKey" );
@@ -452,7 +453,14 @@ void aggregate_duplicateOptionsGivenReloadingProfileFirst_preservesPrecedence()
452
453
453
454
generateTestCredentialsFile ("defaultAccessKey2" , "defaultSecretAccessKey2" );
454
455
455
- clock .tickForward (Duration .ofMillis (1_000 ));
456
+ Duration tick = Duration .ofMillis (1_000 );
457
+
458
+ // The refresh logic uses the last modified attribute of the profile file to determine if it's changed and should be
459
+ // reloaded; unfortunately that means that if things happen quickly enough, the last modified time of the first version
460
+ // of the file, and the new version will be the same. Ensure that there is a change in the last modified time for the
461
+ // test file.
462
+ Files .setLastModifiedTime (getTestCredentialsFilePath (), FileTime .from (startTime .plus (tick )));
463
+ clock .tickForward (tick );
456
464
457
465
profileFile = supplier .get ();
458
466
accessKeyId = profileFile .profile ("default" ).get ().property ("aws_access_key_id" ).get ();
@@ -505,10 +513,10 @@ void get_givenOnLoadAction_callsActionOncePerNewProfileFile() {
505
513
assertThat (blockCount .get ()).isEqualTo (actualProfilesCount );
506
514
}
507
515
508
- private Path generateTestFile (String contents , String filename ) {
516
+ private Path writeTestFile (String contents , Path path ) {
509
517
try {
510
518
Files .createDirectories (testDirectory );
511
- return Files .write (testDirectory . resolve ( filename ) , contents .getBytes (StandardCharsets .UTF_8 ));
519
+ return Files .write (path , contents .getBytes (StandardCharsets .UTF_8 ));
512
520
} catch (IOException e ) {
513
521
throw new RuntimeException (e );
514
522
}
@@ -517,7 +525,11 @@ private Path generateTestFile(String contents, String filename) {
517
525
private Path generateTestCredentialsFile (String accessKeyId , String secretAccessKey ) {
518
526
String contents = String .format ("[default]\n aws_access_key_id = %s\n aws_secret_access_key = %s\n " ,
519
527
accessKeyId , secretAccessKey );
520
- return generateTestFile (contents , "credentials.txt" );
528
+ return writeTestFile (contents , getTestCredentialsFilePath ());
529
+ }
530
+
531
+ private Path getTestCredentialsFilePath () {
532
+ return testDirectory .resolve ("credentials.txt" );
521
533
}
522
534
523
535
private Path generateTestConfigFile (Pair <Object , Object >... pairs ) {
@@ -526,7 +538,7 @@ private Path generateTestConfigFile(Pair<Object, Object>... pairs) {
526
538
.collect (Collectors .joining (System .lineSeparator ()));
527
539
String contents = String .format ("[default]\n %s" , values );
528
540
529
- return generateTestFile (contents , "config.txt" );
541
+ return writeTestFile (contents , testDirectory . resolve ( "config.txt" ) );
530
542
}
531
543
532
544
private void updateModificationTime (Path path , Instant instant ) {
@@ -597,6 +609,10 @@ private AdjustableClock() {
597
609
this .time = Instant .now ();
598
610
}
599
611
612
+ private AdjustableClock (Instant time ) {
613
+ this .time = time ;
614
+ }
615
+
600
616
@ Override
601
617
public ZoneId getZone () {
602
618
return ZoneOffset .UTC ;
0 commit comments