1
2
3
4
5
6
7
8
9
10
11 package org.mule.management;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.management.stats.FlowConstructStatistics;
15 import org.mule.management.stats.ServiceStatistics;
16 import org.mule.module.client.MuleClient;
17 import org.mule.tck.FunctionalTestCase;
18
19 import java.util.Iterator;
20
21 public class JmxStatisticsAsyncTestCase extends FunctionalTestCase
22 {
23 @Override
24 protected String getConfigResources()
25 {
26 return "jmx-statistics-test.xml";
27 }
28
29 @Override
30 protected void doSetUp() throws Exception
31 {
32 super.doSetUp();
33
34 MuleClient muleClient = new MuleClient(muleContext);
35 muleClient.dispatch("vm://in", "Hello world", null);
36 MuleMessage response = muleClient.request("vm://out", RECEIVE_TIMEOUT * 2);
37 assertNotNull(response);
38 assertEquals("data", response.getPayloadAsString());
39 muleClient.dispatch("vm://inflow", "Flow data", null);
40 response = muleClient.request("vm://outflow", RECEIVE_TIMEOUT * 2);
41 assertNotNull(response);
42 assertEquals("Flow data", response.getPayloadAsString());
43 }
44
45 @Override
46 protected void doTearDown() throws Exception
47 {
48 getServiceStatistics().clear();
49 super.doTearDown();
50 }
51
52 public void testCorrectAverageQueueSize() throws Exception
53 {
54 ServiceStatistics stats = getServiceStatistics();
55 assertEquals(1, stats.getAverageQueueSize());
56 }
57
58 public void testCorrectAsynchEventsReceived() throws Exception
59 {
60 ServiceStatistics stats = getServiceStatistics();
61 assertEquals(1, stats.getAsyncEventsReceived());
62 FlowConstructStatistics fstats = getFlowConstructStatistics();
63 assertEquals(1, fstats.getAsyncEventsReceived());
64 }
65
66 public void testCorrectMaxQueueSize() throws Exception
67 {
68 ServiceStatistics stats = getServiceStatistics();
69 assertEquals(1, stats.getMaxQueueSize());
70 }
71
72 public void testCorrectAsynchEventsSent() throws Exception
73 {
74 ServiceStatistics stats = getServiceStatistics();
75 assertEquals(1, stats.getAsyncEventsSent());
76 }
77
78 public void testCorrectTotalEventsSent() throws Exception
79 {
80 ServiceStatistics stats = getServiceStatistics();
81 assertEquals(1, stats.getTotalEventsSent());
82 }
83
84 public void testCorrectTotalEventsReceived() throws Exception
85 {
86 ServiceStatistics stats = getServiceStatistics();
87 assertEquals(1, stats.getTotalEventsReceived());
88 FlowConstructStatistics fstats = getFlowConstructStatistics();
89 assertEquals(1, fstats.getTotalEventsReceived());
90 }
91
92 private ServiceStatistics getServiceStatistics()
93 {
94 Iterator<FlowConstructStatistics> iterator = muleContext.getStatistics().getServiceStatistics().iterator();
95 FlowConstructStatistics stat1 = iterator.next();
96 if (stat1 instanceof ServiceStatistics)
97 {
98 return (ServiceStatistics)stat1;
99 }
100 else
101 {
102 return (ServiceStatistics)iterator.next();
103 }
104 }
105
106 private FlowConstructStatistics getFlowConstructStatistics()
107 {
108 Iterator<FlowConstructStatistics> iterator = muleContext.getStatistics().getServiceStatistics().iterator();
109 FlowConstructStatistics stat1 = iterator.next();
110 if (stat1 instanceof FlowConstructStatistics)
111 {
112 return (FlowConstructStatistics)stat1;
113 }
114 else
115 {
116 return (FlowConstructStatistics)iterator.next();
117 }
118 }
119 }