1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.spring;
12
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import static org.junit.Assert.*;
17
18 import java.util.Arrays;
19 import java.util.Collection;
20
21 import org.junit.Test;
22 import org.junit.runners.Parameterized.Parameters;
23 import org.mule.api.service.Service;
24 import org.mule.component.PooledJavaComponent;
25 import org.mule.config.PoolingProfile;
26 import org.mule.construct.Flow;
27 import org.mule.tck.AbstractServiceAndFlowTestCase;
28
29 public class PoolingProfileTestCase extends AbstractServiceAndFlowTestCase
30 {
31
32 public PoolingProfileTestCase(ConfigVariant variant, String configResources)
33 {
34 super(variant, configResources);
35 }
36
37
38 @Parameters
39 public static Collection<Object[]> parameters()
40 {
41 return Arrays.asList(new Object[][]{
42 {ConfigVariant.SERVICE, "pooling-profile-test-service.xml"},
43 {ConfigVariant.FLOW, "pooling-profile-test-flow.xml"}
44 });
45 }
46
47 @Test
48 public void testDefault()
49 {
50 doTest("default", PoolingProfile.DEFAULT_POOL_EXHAUSTED_ACTION,
51 PoolingProfile.DEFAULT_POOL_INITIALISATION_POLICY,
52 PoolingProfile.DEFAULT_MAX_POOL_ACTIVE,
53 PoolingProfile.DEFAULT_MAX_POOL_IDLE,
54 PoolingProfile.DEFAULT_MAX_POOL_WAIT);
55 }
56
57 @Test
58 public void testFailAll()
59 {
60 doTest("fail_all", PoolingProfile.WHEN_EXHAUSTED_FAIL,
61 PoolingProfile.INITIALISE_ALL, 1, 2, 3);
62 }
63
64 @Test
65 public void testGrowOne()
66 {
67 doTest("grow_one", PoolingProfile.WHEN_EXHAUSTED_GROW,
68 PoolingProfile.INITIALISE_ONE, 2, 3, 4);
69 }
70
71 @Test
72 public void testWaitNone()
73 {
74 doTest("wait_none", PoolingProfile.WHEN_EXHAUSTED_WAIT,
75 PoolingProfile.INITIALISE_NONE, 3, 4, 5);
76 }
77
78 protected void doTest(String serviceFlow, int exhausted, int initialisation,
79 int active, int idle, long wait)
80 {
81 Object o = muleContext.getRegistry().lookupObject(serviceFlow);
82 assertNotNull(serviceFlow, o);
83
84 PooledJavaComponent pjc = null;
85
86 if(variant.equals(ConfigVariant.SERVICE))
87 {
88 assertTrue(((Service)o).getComponent() instanceof PooledJavaComponent);
89 pjc = (PooledJavaComponent) ((Service)o).getComponent();
90 }
91 else
92 {
93 assertTrue(((Flow)o).getMessageProcessors().get(0) instanceof PooledJavaComponent);
94 pjc = (PooledJavaComponent) ((Flow)o).getMessageProcessors().get(0);
95 }
96
97 PoolingProfile profile = pjc.getPoolingProfile();
98 assertNotNull(profile);
99 assertEquals("exhausted:", exhausted, profile.getExhaustedAction());
100 assertEquals("initialisation:", initialisation, profile.getInitialisationPolicy());
101 assertEquals("active:", active, profile.getMaxActive());
102 assertEquals("idle:", idle, profile.getMaxIdle());
103 assertEquals("wait:", wait, profile.getMaxWait());
104 }
105 }