mirror of https://github.com/apache/activemq.git
resolve: https://issues.apache.org/jira/browse/AMQ-3085 with test
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1049521 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c75ff7f163
commit
738e9a19ea
|
@ -609,8 +609,8 @@ public class FailoverTransport implements CompositeTransport {
|
|||
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 implements CompositeTransport {
|
|||
}
|
||||
|
||||
private boolean contains(URI newURI) {
|
||||
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
for (URI uri:uris) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue