fanruan-tuco commented on code in PR #18522:
URL: https://github.com/apache/iceberg/pull/18522#discussion_r4399919311


##########
core/src/test/java/org/apache/iceberg/util/TestParallelIterable.java:
##########
@@ -213,6 +218,149 @@ public void noDeadlock() {
     }
   }
 
+  @Test
+  @Timeout(60)
+  void wakesOnDataBeforeTaskCompletes() throws Exception {
+    Semaphore producerGate = new Semaphore(0);
+    Semaphore completionGate = new Semaphore(0);
+    Iterable<Integer> input =
+        () ->
+            new Iterator<>() {
+              private boolean produced;
+
+              @Override
+              public boolean hasNext() {
+                if (produced) {
+                  completionGate.acquireUninterruptibly();
+                  return false;
+                }
+                return true;
+              }
+
+              @Override
+              public Integer next() {
+                producerGate.acquireUninterruptibly();
+                produced = true;
+                return 1;
+              }
+            };
+
+    int result =
+        consumeAfterWakeUp(
+            input,
+            CloseableIterator::next,
+            ignored -> producerGate.release(),
+            producerGate,
+            completionGate);
+    assertThat(result).isEqualTo(1);
+  }
+
+  @Test
+  @Timeout(60)
+  void wakesWhenEmptyTaskCompletes() throws Exception {
+    Semaphore producerGate = new Semaphore(0);
+    Iterable<Integer> input =
+        () -> {
+          producerGate.acquireUninterruptibly();
+          return Collections.emptyIterator();
+        };
+
+    boolean result =
+        consumeAfterWakeUp(
+            input, CloseableIterator::hasNext, ignored -> 
producerGate.release(), producerGate);
+    assertThat(result).isFalse();
+  }
+
+  @Test
+  @Timeout(60)
+  void wakesWhenTaskFails() {
+    Semaphore producerGate = new Semaphore(0);
+    IllegalArgumentException failure = new IllegalArgumentException("Cannot 
read manifest");
+    Iterable<Integer> input =
+        () -> {
+          producerGate.acquireUninterruptibly();
+          throw failure;
+        };
+
+    assertThatThrownBy(
+            () ->
+                consumeAfterWakeUp(
+                    input,
+                    CloseableIterator::hasNext,
+                    ignored -> producerGate.release(),
+                    producerGate))
+        .isInstanceOf(ExecutionException.class)
+        .hasMessage(failure.toString())
+        .hasCause(failure);
+  }
+
+  @Test
+  @Timeout(60)

Review Comment:
   Nice suggestion



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