KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > ReconnectWithJMXEnabledTest


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;
19
20 import org.apache.activemq.EmbeddedBrokerTestSupport;
21
22 import javax.jms.Connection JavaDoc;
23 import javax.jms.Destination JavaDoc;
24 import javax.jms.Message JavaDoc;
25 import javax.jms.MessageConsumer JavaDoc;
26 import javax.jms.MessageProducer JavaDoc;
27 import javax.jms.Session JavaDoc;
28
29 /**
30  *
31  * @version $Revision: 426384 $
32  */

33 public class ReconnectWithJMXEnabledTest extends EmbeddedBrokerTestSupport {
34
35     protected Connection connection;
36     protected boolean transacted;
37     protected int authMode = Session.AUTO_ACKNOWLEDGE;
38
39     public void testTestUseConnectionCloseBrokerThenRestartInSameJVM() throws Exception JavaDoc {
40         connection = connectionFactory.createConnection();
41         useConnection(connection);
42         connection.close();
43
44         broker.stop();
45         broker = createBroker();
46         startBroker();
47
48         connection = connectionFactory.createConnection();
49         useConnection(connection);
50     }
51
52     protected void setUp() throws Exception JavaDoc {
53         bindAddress = "tcp://localhost:61616";
54         super.setUp();
55     }
56
57     protected void tearDown() throws Exception JavaDoc {
58         if (connection != null) {
59             connection.close();
60             connection = null;
61         }
62         super.tearDown();
63     }
64
65     protected BrokerService createBroker() throws Exception JavaDoc {
66         BrokerService answer = new BrokerService();
67         answer.setUseJmx(true);
68         answer.setPersistent(isPersistent());
69         answer.addConnector(bindAddress);
70         return answer;
71     }
72
73     protected void useConnection(Connection connection) throws Exception JavaDoc {
74         connection.setClientID("foo");
75         connection.start();
76         Session JavaDoc session = connection.createSession(transacted, authMode);
77         Destination JavaDoc destination = createDestination();
78         MessageConsumer JavaDoc consumer = session.createConsumer(destination);
79         MessageProducer JavaDoc producer = session.createProducer(destination);
80         Message JavaDoc message = session.createTextMessage("Hello World");
81         producer.send(message);
82         Thread.sleep(1000);
83     }
84 }
85
Popular Tags