You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2019/06/28 11:47:22 UTC

[qpid-jms] 01/02: NO-JIRA: shut down the executors created in some tests, and check for task error

This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-jms.git

commit 9552e177e0aa396f17234812db1fa19ec946aefa
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Fri Jun 28 10:50:45 2019 +0100

    NO-JIRA: shut down the executors created in some tests, and check for task error
---
 .../integration/ZeroPrefetchIntegrationTest.java   | 53 ++++++++++++----------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
index d902fdc..93df727 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/ZeroPrefetchIntegrationTest.java
@@ -29,7 +29,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
 
 import javax.jms.Connection;
 import javax.jms.Message;
@@ -242,37 +242,42 @@ public class ZeroPrefetchIntegrationTest extends QpidJmsTestCase {
                 testPeer.expectLinkFlow(false, false, equalTo(UnsignedInteger.ONE));
             }
 
-            final AtomicBoolean error = new AtomicBoolean(false);
+            final AtomicReference<Throwable> error = new AtomicReference<>();
             final CountDownLatch done = new CountDownLatch(1);
 
             ExecutorService executor = Executors.newSingleThreadExecutor();
-            executor.execute(new Runnable() {
-
-                @Override
-                public void run() {
-                    try {
-                        if (timeout < 0) {
-                            consumer.receiveNoWait();
-                        } else if (timeout == 0) {
-                            consumer.receive();
-                        } else {
-                            consumer.receive(10000);
+            try {
+                executor.execute(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            if (timeout < 0) {
+                                consumer.receiveNoWait();
+                            } else if (timeout == 0) {
+                                consumer.receive();
+                            } else {
+                                consumer.receive(10000);
+                            }
+                        } catch (Throwable t) {
+                            error.set(t);
+                        } finally {
+                            done.countDown();
                         }
-                    } catch (Exception ex) {
-                        error.set(true);
-                    } finally {
-                        done.countDown();
                     }
-                }
-            });
+                });
 
-            testPeer.waitForAllHandlersToComplete(3000);
-            testPeer.expectEnd();
-            testPeer.expectClose();
+                testPeer.waitForAllHandlersToComplete(3000);
+                testPeer.expectEnd();
+
+                session.close();
 
-            session.close();
+                assertTrue("Consumer did not unblock", done.await(10, TimeUnit.SECONDS));
+                assertNull("Consumer receive errored", error.get());
+            } finally {
+                executor.shutdownNow();
+            }
 
-            assertTrue("Consumer did not unblock", done.await(10, TimeUnit.SECONDS));
+            testPeer.expectClose();
 
             connection.close();
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org