1 18 package org.apache.activemq.broker.ft; 19 20 import java.io.File ; 21 import org.apache.activemq.ActiveMQConnectionFactory; 22 import org.apache.activemq.JmsTopicSendReceiveWithTwoConnectionsTest; 23 import org.apache.activemq.broker.BrokerService; 24 import org.apache.activemq.xbean.BrokerFactoryBean; 25 import org.springframework.core.io.ClassPathResource; 26 27 31 public class QueueMasterSlaveTest extends JmsTopicSendReceiveWithTwoConnectionsTest{ 32 33 34 35 protected BrokerService master; 36 protected BrokerService slave; 37 protected int inflightMessageCount = 0; 38 protected int failureCount = 50; 39 protected String uriString="failover://(tcp://localhost:62001,tcp://localhost:62002)?randomize=false"; 40 41 protected void setUp() throws Exception { 42 if(System.getProperty("basedir")==null){ 43 File file=new File ("."); 44 System.setProperty("basedir",file.getAbsolutePath()); 45 } 46 failureCount = super.messageCount/2; 47 super.topic = isTopic(); 48 BrokerFactoryBean brokerFactory=new BrokerFactoryBean(new ClassPathResource(getMasterXml())); 49 brokerFactory.afterPropertiesSet(); 50 master=brokerFactory.getBroker(); 51 brokerFactory=new BrokerFactoryBean(new ClassPathResource(getSlaveXml())); 52 brokerFactory.afterPropertiesSet(); 53 slave=brokerFactory.getBroker(); 54 master.start(); 55 slave.start(); 56 Thread.sleep(1000); 58 super.setUp(); 59 60 } 61 62 protected String getSlaveXml() { 63 return "org/apache/activemq/broker/ft/slave.xml"; 64 } 65 66 protected String getMasterXml() { 67 return "org/apache/activemq/broker/ft/master.xml"; 68 } 69 70 protected void tearDown() throws Exception { 71 super.tearDown(); 72 slave.stop(); 73 master.stop(); 74 } 75 76 protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { 77 return new ActiveMQConnectionFactory(uriString); 78 } 79 80 protected void messageSent() throws Exception { 81 if (++inflightMessageCount >= failureCount){ 82 inflightMessageCount = 0; 83 Thread.sleep(1000); 84 System.err.println("MASTER STOPPED!@!!!!"); 85 master.stop(); 86 } 87 } 88 89 protected boolean isTopic(){ 90 return false; 91 } 92 } 93 | Popular Tags |