1   /*
2    * $Id: ThreadingProfileTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.test.config;
12  
13  import org.mule.config.ThreadingProfile;
14  import org.mule.tck.AbstractMuleTestCase;
15  
16  import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionHandler;
17  import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
18  
19  public class ThreadingProfileTestCase extends AbstractMuleTestCase
20  {
21  
22      public void testCustomRejectedExecutionHandler()
23      {
24          RejectedExecutionHandler handler = new RejectedExecutionHandler()
25          {
26              public void rejectedExecution(Runnable arg0, ThreadPoolExecutor arg1)
27              {
28                  // nothing to do here
29              }
30          };
31  
32          ThreadingProfile profile = new ThreadingProfile();
33          profile.setRejectedExecutionHandler(handler);
34          ThreadPoolExecutor pool = profile.createPool("testPool");
35          assertSame(handler, pool.getRejectedExecutionHandler());
36      }
37  
38      public void testPoolExhaustedActionStrings()
39      {
40          ThreadingProfile tp = new ThreadingProfile();
41  
42          tp.setPoolExhaustedActionString(null);
43          assertEquals(ThreadingProfile.DEFAULT_POOL_EXHAUST_ACTION, tp.getPoolExhaustedAction());
44  
45          tp.setPoolExhaustedActionString("BAZ");
46          assertEquals(ThreadingProfile.DEFAULT_POOL_EXHAUST_ACTION, tp.getPoolExhaustedAction());
47  
48          tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_WAIT");
49          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_WAIT, tp.getPoolExhaustedAction());
50          tp.setPoolExhaustedActionString("WAIT");
51          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_WAIT, tp.getPoolExhaustedAction());
52  
53          tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_DISCARD");
54          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD, tp.getPoolExhaustedAction());
55          tp.setPoolExhaustedActionString("DISCARD");
56          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD, tp.getPoolExhaustedAction());
57  
58          tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_DISCARD_OLDEST");
59          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD_OLDEST, tp.getPoolExhaustedAction());
60          tp.setPoolExhaustedActionString("DISCARD_OLDEST");
61          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_DISCARD_OLDEST, tp.getPoolExhaustedAction());
62  
63          tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_ABORT");
64          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_ABORT, tp.getPoolExhaustedAction());
65          tp.setPoolExhaustedActionString("ABORT");
66          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_ABORT, tp.getPoolExhaustedAction());
67  
68          tp.setPoolExhaustedActionString("WHEN_EXHAUSTED_RUN");
69          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_RUN, tp.getPoolExhaustedAction());
70          tp.setPoolExhaustedActionString("RUN");
71          assertEquals(ThreadingProfile.WHEN_EXHAUSTED_RUN, tp.getPoolExhaustedAction());
72      }
73  
74  }