View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.spring;
8   
9   import org.mule.api.service.Service;
10  import org.mule.component.PooledJavaComponent;
11  import org.mule.config.PoolingProfile;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertEquals;
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertTrue;
19  
20  public class PoolingProfileTestCase  extends FunctionalTestCase
21  {
22  
23      @Override
24      protected String getConfigResources()
25      {
26          return "pooling-profile-test.xml";
27      }
28  
29      @Test
30      public void testDefault()
31      {
32          doTest("default", PoolingProfile.DEFAULT_POOL_EXHAUSTED_ACTION,
33                  PoolingProfile.DEFAULT_POOL_INITIALISATION_POLICY,
34                  PoolingProfile.DEFAULT_MAX_POOL_ACTIVE,
35                  PoolingProfile.DEFAULT_MAX_POOL_IDLE,
36                  PoolingProfile.DEFAULT_MAX_POOL_WAIT);
37      }
38  
39      @Test
40      public void testFailAll()
41      {
42          doTest("fail_all", PoolingProfile.WHEN_EXHAUSTED_FAIL,
43                  PoolingProfile.INITIALISE_ALL, 1, 2, 3);
44      }
45  
46      @Test
47      public void testGrowOne()
48      {
49          doTest("grow_one", PoolingProfile.WHEN_EXHAUSTED_GROW,
50                  PoolingProfile.INITIALISE_ONE, 2, 3, 4);
51      }
52  
53      @Test
54      public void testWaitNone()
55      {
56          doTest("wait_none", PoolingProfile.WHEN_EXHAUSTED_WAIT,
57                  PoolingProfile.INITIALISE_NONE, 3, 4, 5);
58      }
59  
60      protected void doTest(String service, int exhausted, int initialisation,
61                            int active, int idle, long wait)
62      {
63          Service c = muleContext.getRegistry().lookupService(service);
64          assertNotNull(service, c);
65          assertTrue(c.getComponent() instanceof PooledJavaComponent);
66          PooledJavaComponent pjc = (PooledJavaComponent)c.getComponent();
67          PoolingProfile profile = pjc.getPoolingProfile();
68          assertNotNull(profile);
69          assertEquals("exhausted:", exhausted, profile.getExhaustedAction());
70          assertEquals("initialisation:", initialisation, profile.getInitialisationPolicy());
71          assertEquals("active:", active, profile.getMaxActive());
72          assertEquals("idle:", idle, profile.getMaxIdle());
73          assertEquals("wait:", wait, profile.getMaxWait());
74      }
75  }