1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.jms.reliability;
12
13 import org.mule.api.context.notification.ExceptionNotificationListener;
14 import org.mule.context.notification.ExceptionNotification;
15 import org.mule.exception.DefaultSystemExceptionStrategy;
16 import org.mule.routing.filters.WildcardFilter;
17 import org.mule.transport.jms.redelivery.MessageRedeliveredException;
18 import org.mule.util.concurrent.Latch;
19
20 import java.util.concurrent.TimeUnit;
21
22 import org.junit.Test;
23
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27
28
29
30
31
32
33
34
35 public class InboundMessageLossTestCase extends AbstractJmsReliabilityTestCase
36 {
37 protected Latch messageRedelivered;
38 protected final int latchTimeout = 5000;
39
40 @Override
41 protected String getConfigResources()
42 {
43 return "reliability/activemq-config.xml, reliability/inbound-message-loss.xml";
44 }
45
46 @Override
47 protected void doSetUp() throws Exception
48 {
49 super.doSetUp();
50
51
52 ((DefaultSystemExceptionStrategy) muleContext.getExceptionListener()).setRollbackTxFilter(new WildcardFilter("*"));
53
54
55 messageRedelivered = new Latch();
56 muleContext.registerListener(new ExceptionNotificationListener<ExceptionNotification>()
57 {
58 @Override
59 public void onNotification(ExceptionNotification notification)
60 {
61 if (notification.getException() instanceof MessageRedeliveredException)
62 {
63 messageRedelivered.countDown();
64 }
65 }
66 });
67 }
68
69 @Test
70 public void testNoException() throws Exception
71 {
72 putMessageOnQueue("noException");
73
74
75 assertFalse("Message should not have been redelivered",
76 messageRedelivered.await(latchTimeout, TimeUnit.MILLISECONDS));
77 }
78
79 @Test
80 public void testTransformerException() throws Exception
81 {
82 putMessageOnQueue("transformerException");
83
84
85 assertTrue("Message was not redelivered",
86 messageRedelivered.await(latchTimeout, TimeUnit.MILLISECONDS));
87 }
88
89 @Test
90 public void testRouterException() throws Exception
91 {
92 putMessageOnQueue("routerException");
93
94
95 assertTrue("Message was not redelivered",
96 messageRedelivered.await(latchTimeout, TimeUnit.MILLISECONDS));
97 }
98
99 @Test
100 public void testComponentException() throws Exception
101 {
102 putMessageOnQueue("componentException");
103
104
105
106 assertFalse("Message should not have been redelivered",
107 messageRedelivered.await(latchTimeout, TimeUnit.MILLISECONDS));
108 }
109 }