smengcl commented on code in PR #11496:
URL: https://github.com/apache/ozone/pull/11496#discussion_r4252436621


##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/util/TestBackgroundService.java:
##########
@@ -25,6 +26,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;

Review Comment:
   Changed the test to throw a generic `RuntimeException` so it matches the 
production catch.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/util/TestBackgroundService.java:
##########
@@ -164,4 +166,27 @@ public void testSingleWorkerThread() throws 
InterruptedException, TimeoutExcepti
     assertEquals(expFinalValues, IntStream.range(0, 
nTasks).boxed().map(map::get).collect(Collectors.toList()));
     assertTrue(queue.isEmpty());
   }
+
+  @Test
+  public void testServiceKeepsRunningAfterGetTasksThrows() throws 
InterruptedException, TimeoutException {
+    int interval = 100;
+    int serviceTimeout = 3000;
+    AtomicInteger getTasksCalls = new AtomicInteger();
+    Map<Integer, Integer> map = new HashMap<>();
+    queue.add(new TestTask(0, map, new HashMap<>()));
+    backgroundService = new BackgroundService("testGetTasksThrows", interval, 
TimeUnit.MILLISECONDS, 1,
+        serviceTimeout) {
+      @Override
+      public BackgroundTaskQueue getTasks() {
+        if (getTasksCalls.incrementAndGet() == 1) {
+          throw new NoSuchElementException("simulated failure");
+        }
+        return queue;
+      }
+    };
+    backgroundService.start();
+    // The first run throws, the periodic task must not be cancelled and the 
task runs in a later interval.
+    GenericTestUtils.waitFor(() -> map.get(0) == 1, interval / 5, 
serviceTimeout);

Review Comment:
   No change: `TestTask`'s constructor seeds `map.put(index, 0)` before the 
service starts, so `map.get(0)` is never null and cannot throw when unboxed.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_



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