lukecwik commented on code in PR #22932:
URL: https://github.com/apache/beam/pull/22932#discussion_r996025383


##########
sdks/java/io/jms/src/test/java/org/apache/beam/sdk/io/jms/JmsIOTest.java:
##########
@@ -555,6 +557,101 @@ public void testCustomAutoscaler() throws IOException {
     verify(autoScaler, times(1)).stop();
   }
 
+  @Test
+  public void testCloseWithTimeout()
+      throws IOException, NoSuchFieldException, IllegalAccessException {
+
+    Duration closeTimeout = Duration.millis(2000L);
+    JmsIO.Read spec =
+        JmsIO.read()
+            .withConnectionFactory(connectionFactory)
+            .withUsername(USERNAME)
+            .withPassword(PASSWORD)
+            .withQueue(QUEUE)
+            .withCloseTimeout(closeTimeout);
+
+    JmsIO.UnboundedJmsSource source = new JmsIO.UnboundedJmsSource(spec);
+    JmsIO.UnboundedJmsReader reader = source.createReader(null, null);
+
+    reader.start();
+    reader.close();
+
+    boolean discarded = getDiscardedValue(reader);
+    assertFalse(discarded);
+    try {
+      Thread.sleep(closeTimeout.getMillis() + 1000);
+    } catch (InterruptedException ignored) {
+    }
+    discarded = getDiscardedValue(reader);
+    assertTrue(discarded);
+  }
+
+  @Test
+  public void testDiscardCheckpointMark() throws Exception {
+

Review Comment:
   ```suggestion
   ```



##########
sdks/java/io/jms/src/main/java/org/apache/beam/sdk/io/jms/JmsIO.java:
##########
@@ -582,29 +594,83 @@ public long getTotalBacklogBytes() {
     }
 
     @Override
-    public void close() throws IOException {
+    public void close() {
+      doClose();
+    }
+
+    @SuppressWarnings("FutureReturnValueIgnored")
+    private void doClose() {
+
       try {
-        if (consumer != null) {
-          consumer.close();
-          consumer = null;
+        closeAutoscaler();
+        closeConsumer();
+        ScheduledExecutorService executorService = 
Executors.newSingleThreadScheduledExecutor();

Review Comment:
   `pipelineOptions.as(ExecutorOptions.class).getScheduledExecutorService()`, 
the key part being the 
[as(...)](https://beam.apache.org/releases/javadoc/2.41.0/org/apache/beam/sdk/options/PipelineOptionsFactory.html#as-java.lang.Class-)
 method



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