Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetmircik committed May 3, 2021
1 parent dd9ce71 commit 303b56f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Expand Up @@ -125,20 +125,25 @@ public EvictionPolicyComparator getComparator() {
= new ArrayList<EvictionCandidate<Integer, CacheObjectRecord>>();

long baseTime = System.currentTimeMillis();

long minCreationTime = -1;
for (int i = 0; i < recordCount; i++) {
long creationTime = baseTime + (i * 100);
minCreationTime = minCreationTime == -1 ? creationTime : Math.min(creationTime, minCreationTime);

CacheObjectRecord record = new CacheObjectRecord(i, creationTime, Long.MAX_VALUE);
if (i == expectedEvictedRecordValue) {
// The record in the middle will be minimum access time.
// So, it will be selected for eviction
record.setLastAccessTime(baseTime - 1000);
// The record in the middle will be minimum access
// time. So, it will be selected for eviction
// (set creation-time also to keep this condition
// true --> creation-time <= last-access-time)
record.setCreationTime(minCreationTime);
record.setLastAccessTime(minCreationTime + 1);
} else if (i == expectedExpiredRecordValue) {
record.setExpirationTime(System.currentTimeMillis());
} else {
record.setLastAccessTime(creationTime + 1000);
}
records.add(new SimpleEvictionCandidate<Integer, CacheObjectRecord>(i, record));
records.add(new SimpleEvictionCandidate<>(i, record));
}

sleepAtLeastMillis(1);
Expand Down
Expand Up @@ -63,7 +63,7 @@ public void lru_comparator_does_not_prematurely_select_newly_created_entries() {
assertEquals(descOrderByIdleTimes, givenEntries);
}

private static long idleTime(TestEntryView entryView) {
private static long idleTime(EvictableEntryView entryView) {
return NOW - Math.max(entryView.getCreationTime(), entryView.getLastAccessTime());
}

Expand Down

0 comments on commit 303b56f

Please sign in to comment.