View Javadoc

1   /*
2    * $Id: JmxStatisticsAsyncTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.management;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.management.stats.ServiceStatistics;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  public class JmxStatisticsAsyncTestCase extends FunctionalTestCase
19  {
20      @Override
21      protected String getConfigResources()
22      {
23          return "jmx-statistics-test.xml";
24      }
25  
26      @Override
27      protected void doSetUp() throws Exception
28      {
29          super.doSetUp();
30                  
31          MuleClient muleClient = new MuleClient(muleContext);
32          muleClient.dispatch("vm://in", "Hello world", null);
33          MuleMessage response = muleClient.request("vm://out", RECEIVE_TIMEOUT * 2);
34          assertNotNull(response);
35          assertEquals("data", response.getPayloadAsString());
36      }
37  
38      @Override
39      protected void doTearDown() throws Exception
40      {
41          getServiceStatistics().clear();
42          super.doTearDown();
43      }
44  
45      public void testCorrectAverageQueueSize() throws Exception
46      {
47          ServiceStatistics stats = getServiceStatistics();
48          assertEquals(1, stats.getAverageQueueSize());
49      }
50  
51      public void testCorrectAsynchEventsReceived() throws Exception
52      {
53          ServiceStatistics stats = getServiceStatistics();
54          assertEquals(1, stats.getAsyncEventsReceived());
55      }
56  
57      public void testCorrectMaxQueueSize() throws Exception
58      {
59          ServiceStatistics stats = getServiceStatistics();
60          assertEquals(1, stats.getMaxQueueSize());
61      }
62  
63      public void testCorrectAsynchEventsSent() throws Exception
64      {
65          ServiceStatistics stats = getServiceStatistics();
66          assertEquals(1, stats.getAsyncEventsSent());
67      }
68  
69      public void testCorrectTotalEventsSent() throws Exception
70      {
71          ServiceStatistics stats = getServiceStatistics();
72          assertEquals(1, stats.getTotalEventsSent());
73      }
74  
75      public void testCorrectTotalEventsReceived() throws Exception
76      {
77          ServiceStatistics stats = getServiceStatistics();
78          assertEquals(1, stats.getTotalEventsReceived());
79      }
80  
81      private ServiceStatistics getServiceStatistics()
82      {
83          return muleContext.getStatistics().getServiceStatistics().iterator().next();
84      }
85  }