KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > ft > QueueMasterSlaveTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.broker.ft;
19
20 import java.io.File JavaDoc;
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 /**
28  *Test failover for Queues
29  *
30  */

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 JavaDoc uriString="failover://(tcp://localhost:62001,tcp://localhost:62002)?randomize=false";
40
41     protected void setUp() throws Exception JavaDoc{
42         if(System.getProperty("basedir")==null){
43             File JavaDoc file=new File JavaDoc(".");
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         // wait for thing to connect
57
Thread.sleep(1000);
58         super.setUp();
59
60     }
61
62     protected String JavaDoc getSlaveXml() {
63         return "org/apache/activemq/broker/ft/slave.xml";
64     }
65
66     protected String JavaDoc getMasterXml() {
67         return "org/apache/activemq/broker/ft/master.xml";
68     }
69
70     protected void tearDown() throws Exception JavaDoc{
71         super.tearDown();
72         slave.stop();
73         master.stop();
74     }
75
76     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception JavaDoc{
77         return new ActiveMQConnectionFactory(uriString);
78     }
79     
80     protected void messageSent() throws Exception JavaDoc{
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