Skip to content

Conversation

@aulme
Copy link
Contributor

@aulme aulme commented May 9, 2025

No description provided.


private final LocalDate targetDate = LocalDate.of(2025, 1, 1);
private final Instant targetDateAsInstant = targetDate.atStartOfDay().toInstant(ZoneOffset.UTC);
private static final LocalDate targetDate = LocalDate.of(2025, 1, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, static final should be all uppercase

i.e. TARGET_DATE, ONE_DAY_EARLIER, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather make them non-static 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With @sophia-chen-ttd 's suggestion no longer need those.

var result1 = saltRotation.rotateSalts(lastSnapshot, minAges, 0.2, targetDate);
assertFalse(result1.hasSnapshot());
final ISaltRotation.Result result2 = saltRotation.rotateSalts(lastSnapshot, minAges, 0.2, targetDate.minusDays(1));
var result2 = saltRotation.rotateSalts(lastSnapshot, minAges, 0.2, targetDate.minusDays(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with some other parts, but you already have the oneDayEarlier variable set so you can just use that directly

Also wondering if we should just parametrize this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one day earlier variable is an Instant, while here we need a LocalDate, converting would be even longer.

Parametrization - probably will be riddled with if statements, maybe an exercise for another day.

.withEntries(3, sixDaysEarlier)
.withEntries(5, fiveDaysEarlier)
.withEntries(2, fourDaysEarlier)
.build(targetDateAsInstant.minus(1, DAYS),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here regarding the day variables you created previously

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one, fixed

}

private long calculateRefreshFrom(long lastUpdated, long nextEffective) {
long thirtyDaysMillis = 2592000000L;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use Duration.ofDays(30).toMillis();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done 1 million times in a loop so I wanted to reduce logic to minimum. Perhaps could move it to class level so it doesn't get recomputed every time.

private static final Instant sixDaysEarlier = targetDateAsInstant.minus(6, DAYS);
private static final Instant tenDaysEarlier = targetDateAsInstant.minus(10, DAYS);
private static final Instant sixDaysLater = targetDateAsInstant.plus(6, DAYS);
private static final Instant sevenDaysLater = targetDateAsInstant.plus(7, DAYS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be worth having a small function where we can put in the days to we want to add / subtract so this can be more flexible? When we start testing for rotations on intervals of 30s, these values will need to change anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we already have those.

@aulme aulme merged commit d5943a5 into main May 9, 2025
4 checks passed
@aulme aulme deleted the aul-UID2-5351-setting-refresh-from-field branch May 9, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants