smolnar82 commented on code in PR #1456:
URL: https://github.com/apache/knox/pull/1456#discussion_r4347229212


##########
gateway-server/src/test/java/org/apache/knox/gateway/services/knoxidf/trustedoidcissuer/JdbcTrustedOidcIssuerServiceTest.java:
##########
@@ -493,10 +497,274 @@ public void testConcurrentInitDoesNotReinitialize() 
throws Exception {
         sentinel, FieldUtils.readField(service, "database", true));
   }
 
+  // ------------------------------------------------------------------
+  // Registry snapshot TTL (HA eventual consistency)
+  // ------------------------------------------------------------------
+  // Direct JDBC writes stand in for another Knox node writing to the shared 
table. With a TTL of
+  // 10s the effective (jittered) TTL is in [9s, 10s] and the background 
refresh is due after at
+  // most 5s, so +6s means "refresh due, not expired" and +11s means "expired".
+
+  private static final int TTL_SECS = 10;
+
+  @Test
+  public void testRemoteRegistrationVisibleAfterBackgroundRefresh() throws 
Exception {
+    final AtomicLong now = new AtomicLong();
+    final JdbcTrustedOidcIssuerService ttlService = ttlService(TTL_SECS, now);
+    insertRow("https://remote.example.com";, false, Instant.now());
+
+    assertFalse("A fresh snapshot is served without hitting the DB",
+        ttlService.isTrusted("https://remote.example.com";));
+
+    advance(now, 6);
+    ttlService.isTrusted("https://remote.example.com";); // triggers the 
background refresh, served stale

Review Comment:
   No race: the tests pass `Runnable::run` as Caffeine's executor, so the 
reload runs inside the triggering `isTrusted` call and completes before it 
returns. Production uses the common pool, so it's truly async there.
   
   Agreed on the assert: the triggering read returns the stale snapshot 
(false). I'll do it in the next patchset soon.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to