You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ha...@apache.org on 2014/12/16 00:21:53 UTC

[08/17] activemq git commit: Convert the JUnit 4 test so that the ignore is honoered.

Convert the JUnit 4 test so that the ignore is honoered.


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

Branch: refs/heads/activemq-5.10.x
Commit: 13db036fab2f13dbe834c03a2588b74ae910794a
Parents: 23f6169
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Jun 9 10:24:58 2014 -0400
Committer: Hadrian Zbarcea <ha...@apache.org>
Committed: Mon Dec 15 16:44:47 2014 -0500

----------------------------------------------------------------------
 .../jms/pool/PooledConnectionFactoryTest.java   | 56 +++++++++-----------
 1 file changed, 24 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/13db036f/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java
index 0ae2e4a..99b0ca8 100644
--- a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java
+++ b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryTest.java
@@ -16,6 +16,12 @@
  */
 package org.apache.activemq.jms.pool;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
@@ -28,10 +34,6 @@ import javax.jms.Connection;
 import javax.jms.JMSException;
 import javax.jms.Session;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
@@ -39,6 +41,7 @@ import org.apache.activemq.command.ConnectionId;
 import org.apache.activemq.util.Wait;
 import org.apache.log4j.Logger;
 import org.junit.Ignore;
+import org.junit.Test;
 
 /**
  * Checks the behavior of the PooledConnectionFactory when the maximum amount of
@@ -49,27 +52,11 @@ import org.junit.Ignore;
  * don't block. This test succeeds if an exception is returned and fails if the
  * call to getSession() blocks.
  */
-public class PooledConnectionFactoryTest extends TestCase {
+public class PooledConnectionFactoryTest {
 
     public final static Logger LOG = Logger.getLogger(PooledConnectionFactoryTest.class);
 
-    /**
-     * Create the test case
-     *
-     * @param testName
-     *            name of the test case
-     */
-    public PooledConnectionFactoryTest(String testName) {
-        super(testName);
-    }
-
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite() {
-        return new TestSuite(PooledConnectionFactoryTest.class);
-    }
-
+    @Test
     public void testClearAllConnections() throws Exception {
 
         ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
@@ -100,6 +87,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         assertNotSame(conn2.getConnection(), conn3.getConnection());
     }
 
+    @Test
     public void testMaxConnectionsAreCreated() throws Exception {
 
         ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
@@ -118,6 +106,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         assertEquals(3, cf.getNumConnections());
     }
 
+    @Test
     public void testConnectionsAreRotated() throws Exception {
 
         ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
@@ -139,6 +128,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         }
     }
 
+    @Test
     public void testConnectionsArePooled() throws Exception {
 
         ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
@@ -157,6 +147,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         assertEquals(1, cf.getNumConnections());
     }
 
+    @Test
     public void testConnectionsArePooledAsyncCreate() throws Exception {
 
         final ActiveMQConnectionFactory amq = new ActiveMQConnectionFactory("vm://broker1?marshal=false&broker.persistent=false");
@@ -193,7 +184,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         executor.shutdown();
         assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
 
-        for(PooledConnection connection : connections) {
+        for (PooledConnection connection : connections) {
             assertSame(primary.getConnection(), connection.getConnection());
         }
 
@@ -201,11 +192,13 @@ public class PooledConnectionFactoryTest extends TestCase {
         cf.stop();
     }
 
+    @Test
     public void testConcurrentCreateGetsUniqueConnectionCreateOnDemand() throws Exception {
         doTestConcurrentCreateGetsUniqueConnection(false);
     }
 
     @Ignore("something up - don't know why the start call to createConnection does not cause close - but that does not fix it either!")
+    @Test
     public void testConcurrentCreateGetsUniqueConnectionCreateOnStart() throws Exception {
         doTestConcurrentCreateGetsUniqueConnection(true);
     }
@@ -216,6 +209,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         brokerService.setPersistent(false);
         brokerService.addConnector("tcp://localhost:0");
         brokerService.start();
+        brokerService.waitUntilStarted();
 
         try {
             final int numConnections = 2;
@@ -227,8 +221,7 @@ public class PooledConnectionFactoryTest extends TestCase {
             cf.setCreateConnectionOnStartup(createOnStart);
             cf.start();
 
-            final ConcurrentHashMap<ConnectionId, Connection> connections =
-                    new ConcurrentHashMap<ConnectionId, Connection>();
+            final ConcurrentHashMap<ConnectionId, Connection> connections = new ConcurrentHashMap<ConnectionId, Connection>();
             final ExecutorService executor = Executors.newFixedThreadPool(numConnections);
 
             for (int i = 0; i < numConnections; ++i) {
@@ -247,7 +240,7 @@ public class PooledConnectionFactoryTest extends TestCase {
             }
 
             executor.shutdown();
-            assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
+            assertTrue(executor.awaitTermination(30, TimeUnit.SECONDS));
 
             assertEquals("Should have all unique connections", numConnections, connections.size());
 
@@ -277,9 +270,7 @@ public class PooledConnectionFactoryTest extends TestCase {
         if (!result.isDone() || !result.get().booleanValue()) {
             PooledConnectionFactoryTest.LOG.error("2nd call to createSession() " +
                                                   "is blocking but should have returned an error instead.");
-
             executor.shutdownNow();
-
             fail("SessionPool inside PooledConnectionFactory is blocking if " +
                  "limit is exceeded but should return an exception instead.");
         }
@@ -312,8 +303,7 @@ public class PooledConnectionFactoryTest extends TestCase {
 
                 Session two = null;
                 try {
-                    // this should raise an exception as we called
-                    // setMaximumActive(1)
+                    // this should raise an exception as we called setMaximumActive(1)
                     two = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
                     two.close();
 
@@ -331,10 +321,12 @@ public class PooledConnectionFactoryTest extends TestCase {
                         return new Boolean(false);
                     }
                 } finally {
-                    if (one != null)
+                    if (one != null) {
                         one.close();
-                    if (conn != null)
+                    }
+                    if (conn != null) {
                         conn.close();
+                    }
                 }
             } catch (Exception ex) {
                 LOG.error(ex.getMessage());