You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2016/05/10 14:05:31 UTC

[1/2] activemq git commit: https://issues.apache.org/jira/browse/AMQ-5621

Repository: activemq
Updated Branches:
  refs/heads/master d3ea5c4f9 -> 3da9b0720


https://issues.apache.org/jira/browse/AMQ-5621

Clean up, remove sleep and some unused code.

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/809d5b9b
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/809d5b9b
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/809d5b9b

Branch: refs/heads/master
Commit: 809d5b9bc86a838aff65f7ca4650da3894bc9c67
Parents: d3ea5c4
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue May 10 09:56:19 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue May 10 09:56:19 2016 -0400

----------------------------------------------------------------------
 .../org/apache/activemq/bugs/AMQ2616Test.java   | 66 ++++++++++++--------
 1 file changed, 39 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/809d5b9b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2616Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2616Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2616Test.java
index 4f6f168..a97859c 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2616Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2616Test.java
@@ -16,15 +16,17 @@
  */
 package org.apache.activemq.bugs;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.io.File;
-import java.util.ArrayList;
-import java.util.concurrent.atomic.AtomicBoolean;
+
 import javax.jms.BytesMessage;
 import javax.jms.Connection;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
-import junit.framework.TestCase;
+
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.region.policy.FilePendingQueueMessageStoragePolicy;
@@ -33,17 +35,26 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
 import org.apache.activemq.util.IOHelper;
+import org.apache.activemq.util.Wait;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class AMQ2616Test {
+
+    @Rule
+    public TestName test = new TestName();
 
-public class AMQ2616Test extends TestCase {
     private static final int NUMBER = 2000;
     private BrokerService brokerService;
-    private final ArrayList<Thread> threads = new ArrayList<Thread>();
     private final String ACTIVEMQ_BROKER_BIND = "tcp://0.0.0.0:0";
-    private final AtomicBoolean shutdown = new AtomicBoolean();
 
     private String connectionUri;
 
-    public void testQueueResourcesReleased() throws Exception{
+    @Test(timeout = 90000)
+    public void testQueueResourcesReleased() throws Exception {
         ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(connectionUri);
         Connection tempConnection = fac.createConnection();
         tempConnection.start();
@@ -51,26 +62,32 @@ public class AMQ2616Test extends TestCase {
         Queue tempQueue = tempSession.createTemporaryQueue();
 
         Connection testConnection = fac.createConnection();
-        long startUsage = brokerService.getSystemUsage().getMemoryUsage().getUsage();
+        final long startUsage = brokerService.getSystemUsage().getMemoryUsage().getUsage();
         Session testSession = testConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageProducer testProducer = testSession.createProducer(tempQueue);
-        byte[] payload = new byte[1024*4];
-        for (int i = 0; i < NUMBER; i++ ) {
+        byte[] payload = new byte[1024 * 4];
+
+        for (int i = 0; i < NUMBER; i++) {
             BytesMessage msg = testSession.createBytesMessage();
             msg.writeBytes(payload);
             testProducer.send(msg);
         }
+
         long endUsage = brokerService.getSystemUsage().getMemoryUsage().getUsage();
-        assertFalse(startUsage==endUsage);
+        assertFalse(startUsage == endUsage);
         tempConnection.close();
-        Thread.sleep(1000);
-        endUsage = brokerService.getSystemUsage().getMemoryUsage().getUsage();
-        assertEquals(startUsage,endUsage);
-    }
 
+        assertTrue("Usage should return to original", Wait.waitFor(new Wait.Condition() {
+
+            @Override
+            public boolean isSatisified() throws Exception {
+                return brokerService.getSystemUsage().getMemoryUsage().getUsage() == startUsage;
+            }
+        }));
+    }
 
-    @Override
-    protected void setUp() throws Exception {
+    @Before
+    public void setUp() throws Exception {
         // Start an embedded broker up.
         brokerService = new BrokerService();
 
@@ -90,6 +107,7 @@ public class AMQ2616Test extends TestCase {
         pe.setExpireMessagesPeriod(1000);
         pe.setPendingQueuePolicy(new FilePendingQueueMessageStoragePolicy());
         policyMap.put(new ActiveMQQueue(">"), pe);
+
         brokerService.setDestinationPolicy(policyMap);
         brokerService.getSystemUsage().getMemoryUsage().setLimit(20 * 1024 * 1024);
         brokerService.getSystemUsage().getTempUsage().setLimit(200 * 1024 * 1024);
@@ -99,18 +117,12 @@ public class AMQ2616Test extends TestCase {
 
         connectionUri = brokerService.getTransportConnectors().get(0).getPublishableConnectString();
 
-        new ActiveMQQueue(getName());
+        new ActiveMQQueue(test.getMethodName());
     }
 
-    @Override
-    protected void tearDown() throws Exception {
-        // Stop any running threads.
-        shutdown.set(true);
-        for (Thread t : threads) {
-            t.interrupt();
-            t.join();
-        }
+    @After
+    public void tearDown() throws Exception {
         brokerService.stop();
+        brokerService = null;
     }
-
 }


[2/2] activemq git commit: https://issues.apache.org/jira/browse/AMQ-5621

Posted by ta...@apache.org.
https://issues.apache.org/jira/browse/AMQ-5621

Remove hard coded port as the bridge brokers method doesn't need the
port to be fixed.  Turn off JMX since the test doesn't use it.  

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/3da9b072
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/3da9b072
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/3da9b072

Branch: refs/heads/master
Commit: 3da9b0720efa4f8c55b8d04d3b584637a25ac1da
Parents: 809d5b9
Author: Timothy Bish <ta...@gmail.com>
Authored: Tue May 10 10:05:05 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Tue May 10 10:05:05 2016 -0400

----------------------------------------------------------------------
 .../org/apache/activemq/bugs/AMQ4147Test.java     | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/3da9b072/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4147Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4147Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4147Test.java
index cf7ca45..7e5e14e 100644
--- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4147Test.java
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ4147Test.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.activemq.bugs;
 
 import java.net.URI;
@@ -37,6 +36,7 @@ import org.apache.activemq.util.Wait;
  * manipulated by the remote broker.
  */
 public class AMQ4147Test extends JmsMultipleBrokersTestSupport {
+
     /**
      * This test demonstrates the bug: namely, when a message is bridged over
      * the VMTransport, its memory usage continues to refer to the originating
@@ -46,10 +46,10 @@ public class AMQ4147Test extends JmsMultipleBrokersTestSupport {
      */
     public void testVMTransportRemoteMemoryUsage() throws Exception {
         BrokerService broker1 = createBroker(new URI(
-                "broker:(vm://broker1)/broker1?persistent=false"));
+                "broker:(vm://broker1)/broker1?persistent=false&useJmx=false"));
 
         BrokerService broker2 = createBroker(new URI(
-                "broker:(vm://broker2)/broker2?persistent=false"));
+                "broker:(vm://broker2)/broker2?persistent=false&useJmx=false"));
 
         startAllBrokers();
 
@@ -106,8 +106,7 @@ public class AMQ4147Test extends JmsMultipleBrokersTestSupport {
             }));
             assertTrue(broker2TestQueue.getMemoryUsage().getUsage() > 0);
         } finally {
-            // Consume the message and verify that there is no more memory
-            // usage.
+            // Consume the message and verify that there is no more memory usage.
             consumerProceed.release();
         }
 
@@ -131,10 +130,10 @@ public class AMQ4147Test extends JmsMultipleBrokersTestSupport {
      */
     public void testTcpTransportRemoteMemoryUsage() throws Exception {
         BrokerService broker1 = createBroker(new URI(
-                "broker:(vm://broker1)/broker1?persistent=false"));
+                "broker:(vm://broker1)/broker1?persistent=false&useJmx=false"));
 
         BrokerService broker2 = createBroker(new URI(
-                "broker:(tcp://localhost:61616)/broker2?persistent=false"));
+                "broker:(tcp://localhost:0)/broker2?persistent=false&useJmx=false"));
 
         startAllBrokers();
 
@@ -189,8 +188,7 @@ public class AMQ4147Test extends JmsMultipleBrokersTestSupport {
             }));
             assertTrue(broker2TestQueue.getMemoryUsage().getUsage() > 0);
         } finally {
-            // Consume the message and verify that there is no more memory
-            // usage.
+            // Consume the message and verify that there is no more memory usage.
             consumerProceed.release();
         }