Skip to content

Commit 2700ce7

Browse files
committed
feat Enabled read/write lock for GitHubSanityCachedValue [2172](hub4j#2172)
1 parent fe3f123 commit 2700ce7

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/test/java/org/kohsuke/github/GitHubSanityCachedValueTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ private static void alignToStartOfSecond() {
2121
}
2222
}
2323

24+
/**
25+
* Tests that the cache returns the same value without querying again when accessed multiple times within the same
26+
* second.
27+
*
28+
* @throws Exception
29+
* if the test fails
30+
*/
2431
@Test
2532
public void cachesWithinSameSecond() throws Exception {
2633
alignToStartOfSecond();
@@ -41,6 +48,13 @@ public void cachesWithinSameSecond() throws Exception {
4148
assertThat(calls.get(), equalTo(1));
4249
}
4350

51+
/**
52+
* Tests that multiple concurrent callers only trigger a single refresh of the cached value, preventing redundant
53+
* queries.
54+
*
55+
* @throws Exception
56+
* if the test fails
57+
*/
4458
@Test
4559
public void concurrentCallersOnlyRefreshOnce() throws Exception {
4660
alignToStartOfSecond();
@@ -82,6 +96,13 @@ public void concurrentCallersOnlyRefreshOnce() throws Exception {
8296
}
8397
}
8498

99+
/**
100+
* Tests that the cache is refreshed after one second has elapsed, triggering a new query to retrieve the updated
101+
* value.
102+
*
103+
* @throws Exception
104+
* if the test fails
105+
*/
85106
@Test
86107
public void refreshesAfterOneSecond() throws Exception {
87108
GitHubSanityCachedValue<String> cachedValue = new GitHubSanityCachedValue<>();

0 commit comments

Comments
 (0)