1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.service;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.endpoint.InboundEndpoint;
15 import org.mule.api.service.Service;
16 import org.mule.transport.jms.JmsConnector;
17 import org.mule.transport.jms.JmsSupport;
18
19 import java.util.concurrent.CountDownLatch;
20
21 import javax.jms.JMSException;
22 import javax.jms.Message;
23 import javax.jms.MessageConsumer;
24 import javax.jms.MessageListener;
25
26 public class ServiceInFlightMessagesJMSTestCase extends ServiceInFlightMessagesTestCase
27 {
28 protected TestJMSMessageListener listener;
29
30 @Override
31 protected String getConfigResources()
32 {
33 return "org/mule/test/integration/service/service-inflight-messages-jms.xml";
34 }
35
36 @Override
37 protected void doSetUp() throws Exception
38 {
39 super.doSetUp();
40 listener = createTestJMSConsumer();
41 }
42
43 protected void stopService(Service service) throws Exception
44 {
45 service.stop();
46
47 Thread.sleep(WAIT_TIME_MILLIS);
48 }
49
50 protected void startService(Service service) throws Exception
51 {
52 service.start();
53 }
54
55 private TestJMSMessageListener createTestJMSConsumer() throws MuleException, JMSException
56 {
57 TestJMSMessageListener messageListener = new TestJMSMessageListener();
58 createJMSMessageConsumer().setMessageListener(messageListener);
59 return messageListener;
60 }
61
62 private MessageConsumer createJMSMessageConsumer() throws MuleException, JMSException
63 {
64 InboundEndpoint endpoint = muleContext.getEndpointFactory().getInboundEndpoint("jms://out");
65 JmsConnector jmsConnector = (JmsConnector) muleContext.getRegistry().lookupConnector(
66 "outPersistentConnector");
67 JmsSupport jmsSupport = jmsConnector.getJmsSupport();
68 MessageConsumer consumer = jmsSupport.createConsumer(jmsConnector.getSession(endpoint),
69 jmsSupport.createDestination(jmsConnector.getSession(endpoint), endpoint), false, endpoint);
70 return consumer;
71 }
72
73 protected int getOutSize() throws Exception
74 {
75 return (int) (500 - listener.countdownLatch.getCount());
76 }
77
78 protected void recreateAndStartMuleContext() throws Exception, MuleException
79 {
80 muleContext = createMuleContext();
81 muleContext.start();
82 createJMSMessageConsumer().setMessageListener(listener);
83 }
84
85 private class TestJMSMessageListener implements MessageListener
86 {
87 public TestJMSMessageListener()
88 {
89 super();
90 }
91
92 CountDownLatch countdownLatch = new CountDownLatch(ServiceInFlightMessagesJMSTestCase.NUM_MESSAGES);
93
94 public void onMessage(Message message)
95 {
96 countdownLatch.countDown();
97 }
98 }
99 }