View Javadoc
1   package org.apache.commons.jcs.auxiliary.lateral.socket.tcp;
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 junit.extensions.ActiveTestSuite;
23  import junit.framework.Test;
24  import junit.framework.TestCase;
25  import org.apache.commons.jcs.JCS;
26  import org.apache.commons.jcs.engine.control.CompositeCacheManager;
27  
28  /**
29   * Test which exercises the tcp lateral cache. Runs two threads against the
30   * same region and two against other regions.
31   */
32  public class LateralTCPNoDeadLockConcurrentTest
33      extends TestCase
34  {
35      /**
36       * Constructor for the TestDiskCache object.
37       *
38       * @param testName
39       */
40      public LateralTCPNoDeadLockConcurrentTest( String testName )
41      {
42          super( testName );
43      }
44  
45      /**
46       * Main method passes this test to the text test runner.
47       *
48       * @param args
49       */
50      public static void main( String args[] )
51      {
52          String[] testCaseName = { LateralTCPNoDeadLockConcurrentTest.class.getName() };
53          junit.textui.TestRunner.main( testCaseName );
54      }
55  
56      /**
57       * A unit test suite for JUnit
58       *
59       * @return The test suite
60       */
61      public static Test suite()
62      {
63  
64          System.setProperty( "jcs.auxiliary.LTCP.attributes.PutOnlyMode", "false" );
65  
66          ActiveTestSuite suite = new ActiveTestSuite();
67  
68          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache1" )
69          {
70              @Override
71              public void runTest()
72                  throws Exception
73              {
74                  this.runTestForRegion( "region1", 1, 200, 1 );
75              }
76          } );
77  
78          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache2" )
79          {
80              @Override
81              public void runTest()
82                  throws Exception
83              {
84                  this.runTestForRegion( "region2", 10000, 12000, 2 );
85              }
86          } );
87  
88          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache3" )
89          {
90              @Override
91              public void runTest()
92                  throws Exception
93              {
94                  this.runTestForRegion( "region3", 10000, 12000, 3 );
95              }
96          } );
97  
98          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache4" )
99          {
100             @Override
101             public void runTest()
102                 throws Exception
103             {
104                 this.runTestForRegion( "region3", 10000, 13000, 4 );
105             }
106         } );
107 
108         suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache5" )
109         {
110             @Override
111             public void runTest()
112                 throws Exception
113             {
114                 this.runTestForRegion( "region4", 10000, 11000, 5 );
115             }
116         } );
117 
118         return suite;
119     }
120 
121     /**
122      * Test setup
123      */
124     @Override
125     public void setUp()
126     {
127         JCS.setConfigFilename( "/TestTCPLateralCacheConcurrent.ccf" );
128     }
129 
130     /**
131      * Test tearDown. Dispose of the cache.
132      */
133     @Override
134     public void tearDown()
135     {
136         try
137         {
138             CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
139             cacheMgr.shutDown();
140         }
141         catch ( Exception e )
142         {
143             e.printStackTrace();
144         }
145     }
146 }