Update the tests so that they're not dependent on port 61616

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1084797 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-03-23 22:58:18 +00:00
parent 5cf486c975
commit 883eed0e38
4 changed files with 180 additions and 156 deletions

View File

@ -56,14 +56,11 @@ public class FailoverConsumerOutstandingCommitTest {
private static final Logger LOG = LoggerFactory.getLogger(FailoverConsumerOutstandingCommitTest.class);
private static final String QUEUE_NAME = "FailoverWithOutstandingCommit";
private static final String MESSAGE_TEXT = "Test message ";
private String url = "tcp://localhost:61616";
private static final String TRANSPORT_URI = "tcp://localhost:0";
private String url;
final int prefetch = 10;
BrokerService broker;
public void startCleanBroker() throws Exception {
startBroker(true);
}
@After
public void stopBroker() throws Exception {
if (broker != null) {
@ -77,8 +74,12 @@ public class FailoverConsumerOutstandingCommitTest {
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup) throws Exception {
return createBroker(deleteAllMessagesOnStartup, TRANSPORT_URI);
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup, String bindAddress) throws Exception {
broker = new BrokerService();
broker.addConnector(url);
broker.addConnector(bindAddress);
broker.setDeleteAllMessagesOnStartup(deleteAllMessagesOnStartup);
PolicyMap policyMap = new PolicyMap();
PolicyEntry defaultEntry = new PolicyEntry();
@ -89,6 +90,8 @@ public class FailoverConsumerOutstandingCommitTest {
policyMap.setDefaultEntry(defaultEntry);
broker.setDestinationPolicy(policyMap);
url = broker.getTransportConnectors().get(0).getConnectUri().toString();
return broker;
}
@ -174,7 +177,7 @@ public class FailoverConsumerOutstandingCommitTest {
// will be stopped by the plugin
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
assertTrue("consumer added through failover", commitDoneLatch.await(20, TimeUnit.SECONDS));
@ -280,7 +283,7 @@ public class FailoverConsumerOutstandingCommitTest {
// will be stopped by the plugin
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
assertTrue("commit done through failover", commitDoneLatch.await(20, TimeUnit.SECONDS));
@ -323,7 +326,7 @@ public class FailoverConsumerOutstandingCommitTest {
// restart with outstanding delivered message
broker.stop();
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
consumerSession.rollback();

View File

@ -54,14 +54,11 @@ public class FailoverConsumerUnconsumedTest {
private static final Logger LOG = LoggerFactory.getLogger(FailoverConsumerUnconsumedTest.class);
private static final String QUEUE_NAME = "FailoverWithUnconsumed";
private String url = "tcp://localhost:61616";
private static final String TRANSPORT_URI = "tcp://localhost:0";
private String url;
final int prefetch = 10;
BrokerService broker;
public void startCleanBroker() throws Exception {
startBroker(true);
}
@After
public void stopBroker() throws Exception {
if (broker != null) {
@ -75,9 +72,16 @@ public class FailoverConsumerUnconsumedTest {
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup) throws Exception {
return createBroker(deleteAllMessagesOnStartup, TRANSPORT_URI);
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup, String bindAddress) throws Exception {
broker = new BrokerService();
broker.addConnector(url);
broker.addConnector(bindAddress);
broker.setDeleteAllMessagesOnStartup(deleteAllMessagesOnStartup);
this.url = broker.getTransportConnectors().get(0).getConnectUri().toString();
return broker;
}
@ -182,7 +186,7 @@ public class FailoverConsumerUnconsumedTest {
}
}));
broker = createBroker(false);
broker = createBroker(false, this.url);
broker.start();
assertTrue("consumer added through failover", commitDoneLatch.await(30, TimeUnit.SECONDS));

View File

@ -48,14 +48,11 @@ public class FailoverPrefetchZeroTest {
private static final Logger LOG = LoggerFactory.getLogger(FailoverPrefetchZeroTest.class);
private static final String QUEUE_NAME = "FailoverPrefetchZero";
private String url = "tcp://localhost:61616";
private static final String TRANSPORT_URI = "tcp://localhost:0";
private String url;
final int prefetch = 0;
BrokerService broker;
public void startCleanBroker() throws Exception {
startBroker(true);
}
@After
public void stopBroker() throws Exception {
if (broker != null) {
@ -69,9 +66,16 @@ public class FailoverPrefetchZeroTest {
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup) throws Exception {
return createBroker(deleteAllMessagesOnStartup, TRANSPORT_URI);
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup, String bindAddress) throws Exception {
broker = new BrokerService();
broker.addConnector(url);
broker.addConnector(bindAddress);
broker.setDeleteAllMessagesOnStartup(deleteAllMessagesOnStartup);
url = broker.getTransportConnectors().get(0).getConnectUri().toString();
return broker;
}
@ -135,7 +139,7 @@ public class FailoverPrefetchZeroTest {
// will be stopped by the plugin
assertTrue("pull completed on broker", pullDone.await(30, TimeUnit.SECONDS));
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
assertTrue("receive completed through failover", receiveDone.await(30, TimeUnit.SECONDS));

View File

@ -60,17 +60,14 @@ public class FailoverTransactionTest extends TestSupport {
private static final Logger LOG = LoggerFactory.getLogger(FailoverTransactionTest.class);
private static final String QUEUE_NAME = "FailoverWithTx";
private String url = "tcp://localhost:61616";
private static final String TRANSPORT_URI = "tcp://localhost:0";
private String url;
BrokerService broker;
public static Test suite() {
return suite(FailoverTransactionTest.class);
}
public void startCleanBroker() throws Exception {
startBroker(true);
}
public void setUp() throws Exception {
super.setMaxTestTime(20 * 60 * 1000); // some boxes can be real slow
super.setAutoFail(true);
@ -87,17 +84,33 @@ public class FailoverTransactionTest extends TestSupport {
}
}
private void startCleanBroker() throws Exception {
startBroker(true);
}
public void startBroker(boolean deleteAllMessagesOnStartup) throws Exception {
broker = createBroker(deleteAllMessagesOnStartup);
broker.start();
}
public void startBroker(boolean deleteAllMessagesOnStartup, String bindAddress) throws Exception {
broker = createBroker(deleteAllMessagesOnStartup, bindAddress);
broker.start();
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup) throws Exception {
return createBroker(deleteAllMessagesOnStartup, TRANSPORT_URI);
}
public BrokerService createBroker(boolean deleteAllMessagesOnStartup, String bindAddress) throws Exception {
broker = new BrokerService();
broker.setUseJmx(false);
broker.setAdvisorySupport(false);
broker.addConnector(url);
broker.addConnector(bindAddress);
broker.setDeleteAllMessagesOnStartup(deleteAllMessagesOnStartup);
url = broker.getTransportConnectors().get(0).getConnectUri().toString();
return broker;
}
@ -114,7 +127,7 @@ public class FailoverTransactionTest extends TestSupport {
// restart to force failover and connection state recovery before the commit
broker.stop();
startBroker(false);
startBroker(false, url);
session.commit();
assertNotNull("we got the message", consumer.receive(20000));
@ -182,7 +195,7 @@ public class FailoverTransactionTest extends TestSupport {
// will be stopped by the plugin
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
broker.start();
@ -202,7 +215,7 @@ public class FailoverTransactionTest extends TestSupport {
broker.waitUntilStopped();
LOG.info("Checking for remaining/hung messages..");
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
broker.start();
@ -285,7 +298,7 @@ public class FailoverTransactionTest extends TestSupport {
// will be stopped by the plugin
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
LOG.info("restarting....");
broker.start();
@ -309,7 +322,7 @@ public class FailoverTransactionTest extends TestSupport {
broker.waitUntilStopped();
LOG.info("Checking for remaining/hung messages with second restart..");
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
broker.start();
@ -430,7 +443,7 @@ public class FailoverTransactionTest extends TestSupport {
broker.waitUntilStopped();
LOG.info("Checking for remaining/hung messages with restart..");
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
broker.start();
@ -462,7 +475,7 @@ public class FailoverTransactionTest extends TestSupport {
// restart to force failover and connection state recovery before the commit
broker.stop();
startBroker(false);
startBroker(false, url);
session.commit();
@ -493,7 +506,7 @@ public class FailoverTransactionTest extends TestSupport {
// restart to force failover and connection state recovery before the commit
broker.stop();
startBroker(false);
startBroker(false, url);
session.commit();
for (int i = 0; i < count; i++) {
@ -543,7 +556,7 @@ public class FailoverTransactionTest extends TestSupport {
// restart to force failover and connection state recovery before the commit
broker.stop();
startBroker(false);
startBroker(false, url);
session.commit();
for (int i = 0; i < count - 1; i++) {
@ -671,7 +684,7 @@ public class FailoverTransactionTest extends TestSupport {
// will be stopped by the plugin
broker.waitUntilStopped();
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
broker.start();
@ -708,7 +721,7 @@ public class FailoverTransactionTest extends TestSupport {
broker.waitUntilStopped();
LOG.info("Checking for remaining/hung messages..");
broker = createBroker(false);
broker = createBroker(false, url);
setDefaultPersistenceAdapter(broker);
broker.start();
@ -744,7 +757,7 @@ public class FailoverTransactionTest extends TestSupport {
assertNotNull(msg);
broker.stop();
broker = createBroker(false);
broker = createBroker(false, url);
// use empty jdbc store so that default wait(0) for redeliveries will timeout after failover
setPersistenceAdapter(broker, PersistenceAdapterChoice.JDBC);
broker.start();
@ -756,7 +769,7 @@ public class FailoverTransactionTest extends TestSupport {
}
broker.stop();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
assertNotNull("should get rolledback message from original restarted broker", consumer.receive(20000));
@ -784,7 +797,7 @@ public class FailoverTransactionTest extends TestSupport {
assertNotNull("got message just produced", msg);
broker.stop();
broker = createBroker(false);
broker = createBroker(false, url);
// use empty jdbc store so that wait for re-deliveries occur when failover resumes
setPersistenceAdapter(broker, PersistenceAdapterChoice.JDBC);
broker.start();
@ -803,7 +816,7 @@ public class FailoverTransactionTest extends TestSupport {
});
broker.stop();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
assertTrue("commit was successful", commitDone.await(30, TimeUnit.SECONDS));
@ -836,7 +849,7 @@ public class FailoverTransactionTest extends TestSupport {
MessageConsumer consumer2 = consumerSession.createConsumer(consumerSession.createQueue(QUEUE_NAME + "?consumer.prefetchSize=1"));
broker.stop();
broker = createBroker(false);
broker = createBroker(false, url);
broker.start();
final CountDownLatch commitDone = new CountDownLatch(1);