activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1440672 - /activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/NioQueueSubscriptionTest.java
Date Wed, 30 Jan 2013 21:12:59 GMT
Author: tabish
Date: Wed Jan 30 21:12:59 2013
New Revision: 1440672

URL: http://svn.apache.org/viewvc?rev=1440672&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-4286

Cleans up test case and adds logging to help figure out what's failing. 

Modified:
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/NioQueueSubscriptionTest.java

Modified: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/NioQueueSubscriptionTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/NioQueueSubscriptionTest.java?rev=1440672&r1=1440671&r2=1440672&view=diff
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/NioQueueSubscriptionTest.java
(original)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/broker/NioQueueSubscriptionTest.java
Wed Jan 30 21:12:59 2013
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jms.ConnectionFactory;
 import javax.jms.ExceptionListener;
@@ -37,27 +38,27 @@ import org.apache.activemq.broker.region
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+public class NioQueueSubscriptionTest extends QueueSubscriptionTest {
 
-@SuppressWarnings("unchecked")
-public class NioQueueSubscriptionTest extends QueueSubscriptionTest implements ExceptionListener
{
-    
     protected static final Logger LOG = LoggerFactory.getLogger(NioQueueSubscriptionTest.class);
-    
-    private Map<Thread, Throwable> exceptions = Collections.synchronizedMap(new HashMap<Thread,
Throwable>());
-    
+
+    private final Map<Thread, Throwable> exceptions = Collections.synchronizedMap(new
HashMap<Thread, Throwable>());
+
     @Override
     protected ConnectionFactory createConnectionFactory() throws Exception {
         return new ActiveMQConnectionFactory("tcp://localhost:62621?trace=false");
     }
-    
+
+    @Override
     protected void setUp() throws Exception {
-        //setMaxTestTime(20*60*1000);
+        // setMaxTestTime(20*60*1000);
         super.setUp();
     }
-    
+
     @Override
     protected BrokerService createBroker() throws Exception {
-        BrokerService answer = BrokerFactory.createBroker(new URI("broker://nio://localhost:62621?useQueueForAccept=false&persistent=false&wiewformat.maxInactivityDuration=0"));
+        BrokerService answer = BrokerFactory.createBroker(new URI(
+            "broker://nio://localhost:62621?useQueueForAccept=false&persistent=false&wiewformat.maxInactivityDuration=0"));
         answer.getManagementContext().setCreateConnector(false);
         answer.setUseJmx(false);
         answer.setDeleteAllMessagesOnStartup(true);
@@ -72,40 +73,57 @@ public class NioQueueSubscriptionTest ex
         answer.setDestinationPolicy(policyMap);
         return answer;
     }
-    
+
     public void testLotsOfConcurrentConnections() throws Exception {
-        ExecutorService executor = Executors.newCachedThreadPool(); 
+        ExecutorService executor = Executors.newCachedThreadPool();
         final ConnectionFactory factory = createConnectionFactory();
-        final ExceptionListener listener = this;
         int connectionCount = 400;
-        for (int i=0;i<connectionCount ;i++) {
+        final AtomicInteger threadId = new AtomicInteger(0);
+        for (int i = 0; i < connectionCount; i++) {
             executor.execute(new Runnable() {
+                @Override
                 public void run() {
+                    final int innerId = threadId.incrementAndGet();
                     try {
+                        ExceptionListener listener = new NioQueueSubscriptionTestListener(innerId,
exceptions, LOG);
                         ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
                         connection.setExceptionListener(listener);
                         connection.start();
                         assertNotNull(connection.getBrokerName());
                         connections.add(connection);
                     } catch (Exception e) {
+                        LOG.error(">>>> Exception in run() on thread " + innerId,
e);
                         exceptions.put(Thread.currentThread(), e);
                     }
                 }
             });
         }
-        
+
         executor.shutdown();
         executor.awaitTermination(30, TimeUnit.SECONDS);
 
         if (!exceptions.isEmpty()) {
-          LOG.error("" + exceptions.size() + " exceptions like", exceptions.values().iterator().next());
-          fail("unexpected exceptions in worker threads: " + exceptions.values().iterator().next());
+            LOG.error(">>>> " + exceptions.size() + " exceptions like", exceptions.values().iterator().next());
+            fail("unexpected exceptions in worker threads: " + exceptions.values().iterator().next());
         }
-        LOG.info("created " + connectionCount + " connecitons");
+        LOG.info("created " + connectionCount + " connections");
     }
+}
 
+class NioQueueSubscriptionTestListener implements ExceptionListener {
+    private int id = 0;
+    protected Logger LOG;
+    private final Map<Thread, Throwable> exceptions;
+
+    public NioQueueSubscriptionTestListener(int id, Map<Thread, Throwable> exceptions,
Logger log) {
+        this.id = id;
+        this.exceptions = exceptions;
+        this.LOG = log;
+    }
+
+    @Override
     public void onException(JMSException exception) {
-        LOG.error("Exception on conneciton", exception);
+        LOG.error(">>>> Exception in onException() on thread " + id, exception);
         exceptions.put(Thread.currentThread(), exception);
     }
 }



Mime
View raw message