View Javadoc
1   package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
2   
3   import org.apache.commons.jcs3.JCS;
4   import org.apache.commons.jcs3.engine.control.CompositeCacheManager;
5   
6   /*
7    * Licensed to the Apache Software Foundation (ASF) under one
8    * or more contributor license agreements.  See the NOTICE file
9    * distributed with this work for additional information
10   * regarding copyright ownership.  The ASF licenses this file
11   * to you under the Apache License, Version 2.0 (the
12   * "License"); you may not use this file except in compliance
13   * with the License.  You may obtain a copy of the License at
14   *
15   *   http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing,
18   * software distributed under the License is distributed on an
19   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20   * KIND, either express or implied.  See the License for the
21   * specific language governing permissions and limitations
22   * under the License.
23   */
24  
25  import junit.extensions.ActiveTestSuite;
26  import junit.framework.Test;
27  import junit.framework.TestCase;
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( final String testName )
42      {
43          super( testName );
44      }
45  
46      /**
47       * A unit test suite for JUnit
48       *
49       * @return The test suite
50       */
51      public static Test suite()
52      {
53  
54          System.setProperty( "jcs.auxiliary.LTCP.attributes.PutOnlyMode", "false" );
55  
56          final ActiveTestSuite suite = new ActiveTestSuite();
57  
58          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache1" )
59          {
60              @Override
61              public void runTest()
62                  throws Exception
63              {
64                  this.runTestForRegion( "region1", 1, 200, 1 );
65              }
66          } );
67  
68          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache2" )
69          {
70              @Override
71              public void runTest()
72                  throws Exception
73              {
74                  this.runTestForRegion( "region2", 10000, 12000, 2 );
75              }
76          } );
77  
78          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache3" )
79          {
80              @Override
81              public void runTest()
82                  throws Exception
83              {
84                  this.runTestForRegion( "region3", 10000, 12000, 3 );
85              }
86          } );
87  
88          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache4" )
89          {
90              @Override
91              public void runTest()
92                  throws Exception
93              {
94                  this.runTestForRegion( "region3", 10000, 13000, 4 );
95              }
96          } );
97  
98          suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache5" )
99          {
100             @Override
101             public void runTest()
102                 throws Exception
103             {
104                 this.runTestForRegion( "region4", 10000, 11000, 5 );
105             }
106         } );
107 
108         return suite;
109     }
110 
111     /**
112      * Test setup
113      */
114     @Override
115     public void setUp()
116     {
117         JCS.setConfigFilename( "/TestTCPLateralCacheConcurrent.ccf" );
118     }
119 
120     /**
121      * Test tearDown. Dispose of the cache.
122      */
123     @Override
124     public void tearDown()
125     {
126         try
127         {
128             final CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
129             cacheMgr.shutDown();
130         }
131         catch ( final Exception e )
132         {
133             e.printStackTrace();
134         }
135     }
136 }