Skip to content

11243::RLS cleanups #12081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion rls/src/main/java/io/grpc/rls/LinkedHashLruCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public final List<V> values() {
protected final boolean fitToLimit() {
boolean removedAnyUnexpired = false;
if (estimatedSizeBytes <= estimatedMaxSizeBytes) {
// new size is larger no need to do cleanup
// there is space available so no need to do cleanup
return false;
}
// cleanup expired entries
Expand Down Expand Up @@ -337,4 +337,19 @@ public String toString() {
.toString();
}
}

/**
* setting the estimatedMaxSizeBytes
*/
public final void setEstimatedMaxSizeBytes(long newSizeBytes) {
this.estimatedMaxSizeBytes = newSizeBytes;
}

/**
* setting the estimatedSizeBytes
*/
public final void setEstimatedSizeBytes(long newSizeBytes) {
//testing email link
this.estimatedSizeBytes = newSizeBytes;
}
}
38 changes: 38 additions & 0 deletions rls/src/test/java/io/grpc/rls/LinkedHashLruCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,42 @@ public int hashCode() {
return Objects.hash(value, expireTime);
}
}

@Test
public void testFitToLimitWithEstimatedMaxSizeBytes() {

Entry entry1 = new Entry("Entry1", ticker.read() + 10,4);
Entry entry2 = new Entry("Entry2", ticker.read() + 20,2);
Entry entry3 = new Entry("Entry3", ticker.read() + 30,1);

cache.cache(1, entry1);
cache.cache(2, entry2);
cache.cache(3, entry3);

assertThat(cache.estimatedSize()).isEqualTo(2);
cache.setEstimatedMaxSizeBytes(2);

assertThat(cache.estimatedMaxSizeBytes()).isEqualTo(2);
assertThat(cache.fitToLimit()).isEqualTo(true);
assertThat(cache.estimatedSizeBytes()).isEqualTo(1);
}

@Test
public void testFitToLimitWithEstimatedSizeBytes() {

Entry entry1 = new Entry("Entry1", ticker.read() + 10,4);
Entry entry2 = new Entry("Entry2", ticker.read() + 20,2);
Entry entry3 = new Entry("Entry3", ticker.read() + 30,1);

cache.cache(1, entry1);
cache.cache(2, entry2);
cache.cache(3, entry3);

assertThat(cache.estimatedSize()).isEqualTo(2);
cache.setEstimatedSizeBytes(7);

assertThat(cache.estimatedMaxSizeBytes()).isEqualTo(5);
assertThat(cache.fitToLimit()).isEqualTo(true);
assertThat(cache.estimatedSizeBytes()).isEqualTo(5);
}
}