activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1431700 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubDelayedUnsubscribeTest.java
Date Thu, 10 Jan 2013 22:19:56 GMT
Author: tabish
Date: Thu Jan 10 22:19:56 2013
New Revision: 1431700

URL: http://svn.apache.org/viewvc?rev=1431700&view=rev
Log:
fix for failing test, the check for inactive durables was waiting exactly as long as the housekeeping
thread's sleep interval which could cause it to sometimes miss the very last run of the housekeeper
and falsely detect leftover inactive ones.  Make the test wait for longer than the sleep interval
and also provide a clean shutdown of the house-keeper thread.

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubDelayedUnsubscribeTest.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubDelayedUnsubscribeTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubDelayedUnsubscribeTest.java?rev=1431700&r1=1431699&r2=1431700&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubDelayedUnsubscribeTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/usecases/DurableSubDelayedUnsubscribeTest.java
Thu Jan 10 22:19:56 2013
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Vector;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import javax.jms.Connection;
@@ -96,6 +97,8 @@ public class DurableSubDelayedUnsubscrib
         final BrokerService brokerService = this.broker;
 
         // Wait for all client subscription to be unsubscribed or swept away.
+        // Ensure we sleep longer than the housekeeper's sweep delay otherwise we can
+        // miss the fact that all durables that were abandoned do finally get cleaned up.
 
         assertTrue("should have only one inactiveSubscriber subscribed but was: " + brokerService.getAdminView().getInactiveDurableTopicSubscribers().length,
             Wait.waitFor(new Wait.Condition() {
@@ -104,7 +107,7 @@ public class DurableSubDelayedUnsubscrib
                 public boolean isSatisified() throws Exception {
                     return brokerService.getAdminView().getInactiveDurableTopicSubscribers().length
== 1;
                 }
-            }, TimeUnit.MINUTES.toMillis(3)));
+            }, TimeUnit.MINUTES.toMillis(houseKeeper.SWEEP_DELAY * 2)));
 
         assertTrue("should be no subscribers subscribed but was: " + brokerService.getAdminView().getDurableTopicSubscribers().length,
             Wait.waitFor(new Wait.Condition() {
@@ -138,6 +141,9 @@ public class DurableSubDelayedUnsubscrib
                 }
             }, TimeUnit.MINUTES.toMillis(3)));
 
+        // Be good and cleanup our mess a bit.
+        this.houseKeeper.shutdown();
+
         assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
 
         LOG.info("DONE.");
@@ -575,6 +581,10 @@ public class DurableSubDelayedUnsubscrib
      */
     private final class HouseKeeper extends Thread {
 
+        private final AtomicBoolean done = new AtomicBoolean();
+
+        public final long SWEEP_DELAY = TimeUnit.MINUTES.toMillis(3);
+
         private HouseKeeper() {
             super("HouseKeeper");
             setDaemon(true);
@@ -582,11 +592,26 @@ public class DurableSubDelayedUnsubscrib
 
         public final CopyOnWriteArrayList<String> abandonedSubscriptions = new CopyOnWriteArrayList<String>();
 
+        public void shutdown() throws Exception {
+            done.set(true);
+
+            // In case we are sleeping, abort the sleep.
+            this.interrupt();
+
+            // Wait for run to complete.
+            this.join(TimeUnit.MINUTES.toMillis(SWEEP_DELAY));
+
+            // Ensure all abandoned subscriptions get wiped.
+            if (!abandonedSubscriptions.isEmpty()) {
+                this.sweep();
+            }
+        }
+
         @Override
         public void run() {
-            while (true) {
+            while (!done.get()) {
                 try {
-                    Thread.sleep(3 * 60 * 1000);
+                    Thread.sleep(SWEEP_DELAY);
 
                     processLock.readLock().lock();
                     try {
@@ -679,7 +704,6 @@ public class DurableSubDelayedUnsubscrib
         clientManager = new ClientManager();
         server = new Server();
         houseKeeper = new HouseKeeper();
-
     }
 
     @After



Mime
View raw message