1   /*
2    * $Id: CommonsPoolTestCase.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.mule.commonspool;
12  
13  import org.mule.config.pool.CommonsPoolFactory;
14  import org.mule.config.pool.CommonsPoolProxyPool;
15  import org.mule.impl.MuleDescriptor;
16  import org.mule.impl.model.seda.SedaModel;
17  import org.mule.tck.model.AbstractPoolTestCase;
18  import org.mule.umo.lifecycle.InitialisationException;
19  import org.mule.umo.model.UMOPoolFactory;
20  import org.mule.util.ObjectPool;
21  
22  import org.apache.commons.pool.impl.GenericObjectPool;
23  
24  public class CommonsPoolTestCase extends AbstractPoolTestCase
25  {
26  
27      /*
28       * (non-Javadoc)
29       * 
30       * @see org.mule.test.mule.AbstractPoolTestCase#createPool(org.mule.umo.UMODescriptor,
31       *      byte)
32       */
33      public ObjectPool createPool(MuleDescriptor descriptor, byte action) throws InitialisationException
34      {
35          GenericObjectPool.Config config = new GenericObjectPool.Config();
36          config.maxActive = DEFAULT_POOL_SIZE;
37          config.maxWait = DEFAULT_WAIT;
38  
39          if (action == FAIL_WHEN_EXHAUSTED)
40          {
41              config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL;
42          }
43          else if (action == GROW_WHEN_EXHAUSTED)
44          {
45              config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
46          }
47          else if (action == BLOCK_WHEN_EXHAUSTED)
48          {
49              config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
50          }
51          else
52          {
53              fail("Action type for pool not recognised. Type is: " + action);
54          }
55          return new CommonsPoolProxyPool(descriptor, new SedaModel(), config);
56      }
57  
58      public UMOPoolFactory getPoolFactory()
59      {
60          return new CommonsPoolFactory();
61      }
62  
63  }