View Javadoc
1   package org.apache.commons.jcs3.utils.threadpool;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Properties;
23  import java.util.Set;
24  import java.util.concurrent.ExecutorService;
25  
26  import org.apache.commons.jcs3.utils.props.PropertyLoader;
27  import junit.framework.TestCase;
28  
29  /**
30   * Verify that the manager can create pools as intended by the default and
31   * specified file names.
32   */
33  public class ThreadPoolManagerUnitTest
34      extends TestCase
35  {
36  
37      /**
38       * Make sure it can load a default cache.ccf file
39       */
40      public void testDefaultConfig()
41      {
42          final Properties props = PropertyLoader.loadProperties( "thread_pool.properties" );
43          ThreadPoolManager.setProps( props );
44          final ThreadPoolManager mgr = ThreadPoolManager.getInstance();
45          assertNotNull( mgr );
46  
47          final ExecutorService pool = mgr.getExecutorService( "test1" );
48          assertNotNull( pool );
49      }
50  
51      /**
52       * Make sure it can load a certain configuration
53       */
54      public void testSpecialConfig()
55      {
56          final Properties props = PropertyLoader.loadProperties( "thread_pool.properties" );
57          ThreadPoolManager.setProps( props );
58          final ThreadPoolManager mgr = ThreadPoolManager.getInstance();
59          assertNotNull( mgr );
60  
61          final ExecutorService pool = mgr.getExecutorService( "aborttest" );
62          assertNotNull( pool );
63      }
64  
65      /**
66       * Get a couple pools by name and then see if they are in the list.
67       *
68       */
69      public void testGetPoolNames()
70      {
71          final ThreadPoolManager mgr = ThreadPoolManager.getInstance();
72          assertNotNull( mgr );
73  
74          final String poolName1 = "testGetPoolNames1";
75          mgr.getExecutorService( poolName1 );
76  
77          final String poolName2 = "testGetPoolNames2";
78          mgr.getExecutorService( poolName2 );
79  
80          final Set<String> names = mgr.getPoolNames();
81          assertTrue( "Should have name in list.", names.contains( poolName1 ) );
82          assertTrue( "Should have name in list.", names.contains( poolName2 ) );
83      }
84  }