ebyhr commented on code in PR #18910:
URL: https://github.com/apache/iceberg/pull/18910#discussion_r4594901591


##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
@@ -542,30 +545,48 @@ public Pair<Integer, TimeUnit> refresh(RESTClient client) 
{
       return null;
     }
 
-    private OAuthTokenResponse refreshCurrentToken(RESTClient client) {
+    /** A token response together with the time its request was sent. */
+    private record TimedTokenResponse(long requestStartMillis, 
OAuthTokenResponse response) {
+      /** Returns null for a null response, so that a failed request stays "no 
result". */
+      static TimedTokenResponse of(long requestStartMillis, OAuthTokenResponse 
response) {
+        if (response == null) {
+          return null;
+        }
+        return new TimedTokenResponse(requestStartMillis, response);

Review Comment:
   https://iceberg.apache.org/contribute/#block-spacing
   > To improve readability and maintain consistency, always place a newline 
after control blocks (if, for, while, switch, etc.). 
   
   Same for `expiresAtMillis` method.



##########
core/src/main/java/org/apache/iceberg/rest/auth/OAuth2Util.java:
##########
@@ -542,30 +545,48 @@ public Pair<Integer, TimeUnit> refresh(RESTClient client) 
{
       return null;
     }
 
-    private OAuthTokenResponse refreshCurrentToken(RESTClient client) {
+    /** A token response together with the time its request was sent. */

Review Comment:
   Could the Javadoc on `TimedTokenResponse` and its factory be dropped, since 
they restate the code?



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -2110,9 +2110,10 @@ public void 
testCatalogTokenRefreshFailsAndUsesCredentialForRefresh(String oauth
                       any(),
                       any());
 
-              // verify the first token exchange - since an exception is 
thrown, we're performing
-              // retries
-              Mockito.verify(adapter, times(2))
+              // verify the token exchange with the catalog token was 
attempted and failed. How
+              // many times depends on whether the retry runs before or after 
the 1s token expires:
+              // once expired, the session switches to the credential flow 
instead of retrying
+              Mockito.verify(adapter, atLeastOnce())

Review Comment:
   `atLeastOnce()` makes this assertion much weaker than `times(2)`, and the 
outcome now depends on timing: the retry crosses the 1s expiry, so the second 
attempt goes to the credential flow. Could the test pin the sequence instead, 
e.g. assert exactly one failed exchange with `catalogHeaders` followed by the 
`basicHeaders` call, so a regression that skips the exchange attempt is still 
caught?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to