have master wait for slave to ensure slave is always present for duration of test

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@711264 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2008-11-04 14:38:20 +00:00
parent f561d6bb67
commit c27db108fd
1 changed files with 20 additions and 4 deletions

View File

@ -19,7 +19,6 @@ package org.apache.activemq.advisory;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.jms.JMSException;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageConsumer; import javax.jms.MessageConsumer;
import javax.jms.MessageListener; import javax.jms.MessageListener;
@ -47,18 +46,35 @@ public class MasterSlaveTempQueueMemoryTest extends TempQueueMemoryTest {
bindAddress = masterBindAddress; bindAddress = masterBindAddress;
BrokerService master = super.createBroker(); BrokerService master = super.createBroker();
master.setBrokerName("master"); master.setBrokerName("master");
master.setUseJmx(false);
bindAddress = slaveBindAddress; bindAddress = slaveBindAddress;
slave = super.createBroker(); slave = super.createBroker();
slave.setBrokerName("slave"); slave.setBrokerName("slave");
slave.setMasterConnectorURI(masterBindAddress); slave.setMasterConnectorURI(masterBindAddress);
slave.setUseJmx(false);
bindAddress = masterBindAddress; bindAddress = masterBindAddress;
return master; return master;
} }
@Override @Override
protected void startBroker() throws Exception { protected void startBroker() throws Exception {
super.startBroker();
// because master will wait for slave to connect it needs
// to be in a separate thread
new Thread() {
public void run() {
try {
broker.setWaitForSlave(true);
broker.start();
} catch (Exception e) {
fail("failed to start broker, reason:" + e);
e.printStackTrace();
}
}
}.start();
slave.start(); slave.start();
assertTrue("slave is indeed a slave", slave.isSlave());
} }
@Override @Override
@ -136,18 +152,18 @@ public class MasterSlaveTempQueueMemoryTest extends TempQueueMemoryTest {
Message msg = clientSession.createMessage(); Message msg = clientSession.createMessage();
producer.send(msg); producer.send(msg);
} }
Thread.sleep(5000);
RegionBroker slaveRb = (RegionBroker) slave.getBroker().getAdaptor( RegionBroker slaveRb = (RegionBroker) slave.getBroker().getAdaptor(
RegionBroker.class); RegionBroker.class);
RegionBroker masterRb = (RegionBroker) broker.getBroker().getAdaptor( RegionBroker masterRb = (RegionBroker) broker.getBroker().getAdaptor(
RegionBroker.class); RegionBroker.class);
Thread.sleep(4000);
assertEquals("inflight match expected", messageCount, masterRb.getDestinationStatistics().getInflight().getCount()); assertEquals("inflight match expected", messageCount, masterRb.getDestinationStatistics().getInflight().getCount());
assertEquals("inflight match on slave and master", slaveRb.getDestinationStatistics().getInflight().getCount(), masterRb.getDestinationStatistics().getInflight().getCount()); assertEquals("inflight match on slave and master", slaveRb.getDestinationStatistics().getInflight().getCount(), masterRb.getDestinationStatistics().getInflight().getCount());
latch.countDown(); latch.countDown();
Thread.sleep(4000); Thread.sleep(5000);
assertEquals("inflight match expected", 0, masterRb.getDestinationStatistics().getInflight().getCount()); assertEquals("inflight match expected", 0, masterRb.getDestinationStatistics().getInflight().getCount());
assertEquals("inflight match on slave and master", slaveRb.getDestinationStatistics().getInflight().getCount(), masterRb.getDestinationStatistics().getInflight().getCount()); assertEquals("inflight match on slave and master", slaveRb.getDestinationStatistics().getInflight().getCount(), masterRb.getDestinationStatistics().getInflight().getCount());
} }