github-actions[bot] commented on code in PR #40985:
URL: https://github.com/apache/beam/pull/40985#discussion_r4466752755


##########
sdks/java/io/solace/src/test/java/org/apache/beam/sdk/io/solace/write/SolaceAckTimeoutReproTest.java:
##########
@@ -0,0 +1,328 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.solace.write;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import com.solacesystems.jcsmp.DeliveryMode;
+import com.solacesystems.jcsmp.JCSMPFactory;
+import com.solacesystems.jcsmp.JCSMPProperties;
+import com.solacesystems.jcsmp.JCSMPSendMultipleEntry;
+import com.solacesystems.jcsmp.XMLMessage;
+import com.solacesystems.jcsmp.XMLMessageProducer;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.beam.sdk.io.solace.SolaceIO.SubmissionMode;
+import org.apache.beam.sdk.io.solace.broker.MessageProducer;
+import org.apache.beam.sdk.io.solace.broker.MessageReceiver;
+import org.apache.beam.sdk.io.solace.broker.PublishResultHandler;
+import org.apache.beam.sdk.io.solace.broker.SessionService;
+import org.apache.beam.sdk.io.solace.broker.SessionServiceFactory;
+import org.apache.beam.sdk.io.solace.broker.SolaceMessageProducer;
+import org.apache.beam.sdk.io.solace.data.Solace;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.state.ValueState;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.windowing.BoundedWindow;
+import org.apache.beam.sdk.util.SerializableUtils;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.TupleTag;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.joda.time.Instant;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Real Beam writers, producer wrapper and ACK handler; only the JCSMP 
transport is faked. */
+@RunWith(JUnit4.class)
+public class SolaceAckTimeoutReproTest {
+  @Test(timeout = 30000)
+  public void acknowledgedMessagesMustNotTimeOutWhenBundlesShareASession() 
throws Exception {
+    UnboundedBatchedSolaceWriter a =
+        new UnboundedBatchedSolaceWriter(
+            r -> JCSMPFactory.onlyInstance().createTopic("test/ack-routing"),
+            new TestFactory(),
+            DeliveryMode.PERSISTENT,
+            SubmissionMode.HIGHER_THROUGHPUT,
+            6,
+            false);
+    UnboundedBatchedSolaceWriter b = SerializableUtils.clone(a);
+    a.startBundle();
+    // Advance the worker-local round-robin index. Bundle B reuses A's 
producer slot.
+    for (int i = 0; i < 5; i++) {
+      SerializableUtils.clone(a).startBundle();
+    }
+    b.startBundle();
+    TestSession session = (TestSession) a.solaceSessionServiceWithProducer();
+    assertSame(session, b.solaceSessionServiceWithProducer());
+    a.addToCurrentBundle(record("A"));
+    b.addToCurrentBundle(record("B"));
+    List<String> resultsA = new ArrayList<>();
+    List<String> resultsB = new ArrayList<>();
+    ExecutorService executor = Executors.newSingleThreadExecutor();
+    Future<?> finishingB =
+        executor.submit(
+            () -> {
+              try {
+                b.finishBundle(context(b, resultsB));
+              } catch (Exception e) {
+                throw new RuntimeException(e);
+              }
+            });
+    try {
+      assertTrue("B's ACK must arrive first", session.bAcked.await(5, 
TimeUnit.SECONDS));
+      a.finishBundle(context(a, resultsA));
+      session.aFinished.countDown();
+      finishingB.get(15, TimeUnit.SECONDS);
+      assertEquals(Collections.singletonList("A"), resultsA);
+      assertEquals(Collections.singletonList("B"), resultsB);
+    } finally {
+      session.aFinished.countDown();
+      finishingB.cancel(true);
+      executor.shutdownNow();
+      assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));

Review Comment:
   **🟢 Low**: Calling `assertTrue(executor.awaitTermination(...))` inside the 
`finally` block before `a.teardown()` and `b.teardown()` means that if 
`awaitTermination` fails or throws, the sessions in the static 
`SolaceWriteSessionsHandler.sessionsMap` will not be cleaned up and could leak 
into subsequent tests. Consider moving `a.teardown()` and `b.teardown()` before 
the assertion (or into a separate `@After` / `try-finally` block), here and in 
`streamingWriterMustNotTimeOutWhenBundlesShareASession` on line 156.



##########
sdks/java/io/solace/src/main/java/org/apache/beam/sdk/io/solace/broker/PublishResultHandler.java:
##########
@@ -41,12 +40,31 @@
 public final class PublishResultHandler implements 
JCSMPStreamingPublishCorrelatingEventHandler {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(PublishResultHandler.class);
-  private final BlockingQueue<PublishResult> publishResultsQueue;
   private final Counter batchesRejectedByBroker =
       Metrics.counter(UnboundedSolaceWriter.class, "batches_rejected");
 
-  public PublishResultHandler(BlockingQueue<PublishResult> 
publishResultsQueue) {
-    this.publishResultsQueue = publishResultsQueue;
+  public PublishResultHandler() {}
+
+  public static Object correlationKey(
+      String messageId,
+      @Nullable Long publishMonotonicNanos,

Review Comment:
   **🟡 Medium**: `Solace.Record#getMessageId()` can be `@Nullable` (for 
example, when mapped from a JCSMP message without an application message ID or 
constructed without one), and `processKey` on line 88 already guards against 
`correlationKey.messageId != null`. Annotating `messageId` as `@Nullable` in 
`correlationKey()` and `PublishCorrelationKey` will align the type signatures 
with the runtime null check and prevent Checker Framework nullness warnings if 
a nullable message ID is passed.
   
   ```suggestion
         @Nullable String messageId,
   ```



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