activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1049521 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/failover/FailoverTransport.java test/java/org/apache/activemq/transport/failover/FailoverTimeoutTest.java
Date Wed, 15 Dec 2010 12:21:44 GMT
Author: gtully
Date: Wed Dec 15 12:21:43 2010
New Revision: 1049521

URL: http://svn.apache.org/viewvc?rev=1049521&view=rev
Log:
resolve: https://issues.apache.org/jira/browse/AMQ-3085 with test

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTimeoutTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java?rev=1049521&r1=1049520&r2=1049521&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java
Wed Dec 15 12:21:43 2010
@@ -609,8 +609,8 @@ public class FailoverTransport implement
     public void add(boolean rebalance, URI u[]) {
         boolean newURI = false;
         for (int i = 0; i < u.length; i++) {
-            if (contains(u[i])==false) {
-                uris.add(i, u[i]);
+            if (!contains(u[i])) {
+                uris.add(u[i]);
                 newURI = true;
             }
         }
@@ -1096,7 +1096,7 @@ public class FailoverTransport implement
     }
     
     private boolean contains(URI newURI) {
-       
+
         boolean result = false;
         try {
         for (URI uri:uris) {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTimeoutTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTimeoutTest.java?rev=1049521&r1=1049520&r2=1049521&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTimeoutTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/failover/FailoverTimeoutTest.java
Wed Dec 15 12:21:43 2010
@@ -17,56 +17,77 @@
 package org.apache.activemq.transport.failover;
 
 import java.net.URI;
-
 import javax.jms.Connection;
 import javax.jms.JMSException;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
-
 import junit.framework.TestCase;
-
+import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;
 
 public class FailoverTimeoutTest extends TestCase {
-	
-	private static final String QUEUE_NAME = "test.failovertimeout";
 
-	public void testTimeout() throws Exception {
-		
-		long timeout = 1000;
-		URI tcpUri = new URI("tcp://localhost:61616");
-		BrokerService bs = new BrokerService();
-		bs.setUseJmx(false);
-		bs.addConnector(tcpUri);
-		bs.start();
-		
-		ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri + ")?timeout="
+ timeout + "&useExponentialBackOff=false");
-		Connection connection = cf.createConnection();
-		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-		MessageProducer producer = session.createProducer(session
-				.createQueue(QUEUE_NAME));
-		TextMessage message = session.createTextMessage("Test message");
-		producer.send(message);
-		
-		bs.stop();
-		
-		try {
-			producer.send(message);
-		} catch (JMSException jmse) {
-			assertEquals("Failover timeout of " + timeout + " ms reached.", jmse.getMessage());
-		}
-		
-		bs = new BrokerService();		
-		bs.setUseJmx(false);
-		bs.addConnector(tcpUri);
-		bs.start();
-		bs.waitUntilStarted();
-		
-		producer.send(message);
-		
-		bs.stop();
-	}
-	
+    private static final String QUEUE_NAME = "test.failovertimeout";
+    BrokerService bs;
+    URI tcpUri;
+
+    public void setUp() throws Exception {
+        bs = new BrokerService();
+        bs.setUseJmx(false);
+        bs.addConnector("tcp://localhost:0");
+        bs.start();
+        tcpUri = bs.getTransportConnectors().get(0).getConnectUri();
+    }
+
+    public void tearDown() throws Exception {
+        if (bs != null) {
+            bs.stop();
+        }
+    }
+
+    public void testTimeout() throws Exception {
+
+        long timeout = 1000;
+        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri
+ ")?timeout=" + timeout + "&useExponentialBackOff=false");
+        Connection connection = cf.createConnection();
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageProducer producer = session.createProducer(session
+                .createQueue(QUEUE_NAME));
+        TextMessage message = session.createTextMessage("Test message");
+        producer.send(message);
+
+        bs.stop();
+
+        try {
+            producer.send(message);
+        } catch (JMSException jmse) {
+            assertEquals("Failover timeout of " + timeout + " ms reached.", jmse.getMessage());
+        }
+
+        bs = new BrokerService();
+        bs.setUseJmx(false);
+        bs.addConnector(tcpUri);
+        bs.start();
+        bs.waitUntilStarted();
+
+        producer.send(message);
+
+        bs.stop();
+    }
+
+    public void testUpdateUris() throws Exception {
+
+        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + tcpUri
+ ")?useExponentialBackOff=false");
+        ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
+        connection.start();
+        FailoverTransport failoverTransport = connection.getTransport().narrow(FailoverTransport.class);
+
+        URI[] bunchOfUnknownAndOneKnown = new URI[]{
+                new URI("tcp://unknownHost:" + tcpUri.getPort()),
+                new URI("tcp://unknownHost2:" + tcpUri.getPort()),
+                new URI("tcp://localhost:2222")};
+        failoverTransport.add(false, bunchOfUnknownAndOneKnown);
+    }
 }



Mime
View raw message