vladislav-sidorovich commented on code in PR #16848:
URL: https://github.com/apache/iceberg/pull/16848#discussion_r3434316114


##########
gcp/src/test/java/org/apache/iceberg/gcp/auth/TestGoogleAuthManager.java:
##########
@@ -221,6 +227,42 @@ public void initializationOccursOnlyOnce() {
     mockedStaticCredentials.verify(GoogleCredentials::getApplicationDefault, 
times(1));
   }
 
+  @Test
+  public void concurrentInitialization() throws Exception {
+    int numThreads = 10;
+    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
+    CountDownLatch startLatch = new CountDownLatch(1);
+    CountDownLatch finishLatch = new CountDownLatch(numThreads);
+
+    GoogleAuthManager spyManager = spy(authManager);
+    doReturn(credentials)
+        .when(spyManager)
+        .loadCredentials(anyBoolean(), any(), anyBoolean(), any(), any());
+
+    AtomicInteger successfulInitializations = new AtomicInteger(0);
+    for (int i = 0; i < numThreads; i++) {
+      executorService.submit(
+          () -> {
+            try {
+              startLatch.await();
+              spyManager.catalogSession(restClient, Collections.emptyMap());
+              successfulInitializations.incrementAndGet();
+            } catch (Exception e) {
+              // ignore
+            } finally {
+              finishLatch.countDown();
+            }
+          });
+    }
+
+    startLatch.countDown();
+    finishLatch.await(10, TimeUnit.SECONDS);

Review Comment:
   I'm not 100% sure about it, let's discuss. 
   
   Java doc:
   ```
   Returns:
   true if the count reached zero and false if the waiting time elapsed before 
the count reached zero
   ```
   
   So, in my opinion the test should fail on the `verify(spyManager, times(1))` 
but not on the fact that the wait time > 10 seconds. 
   
   What do you think? 
   
   Note: actually in other tests in Iceberg it works without `isTrue`.



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