gemini-code-assist[bot] commented on code in PR #38971:
URL: https://github.com/apache/beam/pull/38971#discussion_r3415923638


##########
sdks/java/io/amazon-web-services2/src/test/java/org/apache/beam/sdk/io/aws2/sqs/SqsIOWriteBatchesTest.java:
##########
@@ -285,11 +295,16 @@ public void testWriteBatchesWithStrictTimeout() {
 
     p.run().waitUntilFinish();
 
-    SendMessageBatchRequestEntry[] entries = entries(range(0, 5));
-    // using strict timeouts batches, batches are timed out by a separate 
thread
-    verify(sqs).sendMessageBatch(request("queue", entries[0], entries[1]));
-    verify(sqs).sendMessageBatch(request("queue", entries[2], entries[3]));
-    verify(sqs).sendMessageBatch(request("queue", entries[4]));
+    // Nominally the separate timeout thread flushes [0,1], [2,3], [4]. The 
exact grouping
+    // depends on wall clock time and is unreliable on loaded machines 
(#38946), so verify
+    // timing-independent invariants instead. Expired batches are also flushed 
on append
+    // (independently of the timeout thread), so no batch can exceed 3 entries 
and 5 messages
+    // require at least 2 batches.
+    Map<String, List<SendMessageBatchRequest>> requests = 
captureBatchRequests(atLeast(2));
+    assertThat(requests.keySet()).containsExactly("queue");
+    assertMessageBodies(requests.get("queue"), range(0, 5));
+    assertThat(requests.get("queue"))
+        .allSatisfy(req -> 
assertThat(req.entries().size()).isLessThanOrEqualTo(3));

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   To satisfy the Checker Framework's nullness analysis, avoid passing the 
nullable result of `requests.get("queue")` directly to `assertMessageBodies` 
and `assertThat`. Wrapping it with `checkNotNull` ensures null safety and 
avoids duplicate map lookups.
   
   ```java
       List<SendMessageBatchRequest> queueRequests = 
checkNotNull(requests.get("queue"));
       assertMessageBodies(queueRequests, range(0, 5));
       assertThat(queueRequests)
           .allSatisfy(req -> 
assertThat(req.entries().size()).isLessThanOrEqualTo(3));
   ```



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