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