1   package org.apache.jcs;
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  /***
27   * Test which exercises the hierarchical removal when the cache is active.
28   */
29  public class ConcurrentRemovalLoadTest
30      extends TestCase
31  {
32      /***
33       * Constructor for the TestDiskCache object.
34       *
35       * @param testName
36       */
37      public ConcurrentRemovalLoadTest( String testName )
38      {
39          super( testName );
40      }
41  
42      /***
43       * Main method passes this test to the text test runner.
44       *
45       * @param args
46       */
47      public static void main( String args[] )
48      {
49          String[] testCaseName = { RemovalTestUtil.class.getName() };
50          junit.textui.TestRunner.main( testCaseName );
51      }
52  
53      /***
54       * A unit test suite for JUnit. This verfies that we can remove
55       * hierarchically while the region is active.
56       *
57       * @return The test suite
58       */
59      public static Test suite()
60      {
61          ActiveTestSuite suite = new ActiveTestSuite();
62  
63          suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
64          {
65              public void runTest()
66                  throws Exception
67              {
68                  runTestPutThenRemoveCategorical( 0, 200 );
69              }
70          } );
71  
72          suite.addTest( new RemovalTestUtil( "testPutCache1" )
73          {
74              public void runTest()
75                  throws Exception
76              {
77                  runPutInRange( 300, 400 );
78              }
79          } );
80  
81          suite.addTest( new RemovalTestUtil( "testPutCache2" )
82          {
83              public void runTest()
84                  throws Exception
85              {
86                  runPutInRange( 401, 600 );
87              }
88          } );
89  
90          // stomp on previous put
91          suite.addTest( new RemovalTestUtil( "testPutCache3" )
92          {
93              public void runTest()
94                  throws Exception
95              {
96                  runPutInRange( 401, 600 );
97              }
98          } );
99  
100         suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
101         {
102             public void runTest()
103                 throws Exception
104             {
105                 runTestPutThenRemoveCategorical( 601, 700 );
106             }
107         } );
108 
109         suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
110         {
111             public void runTest()
112                 throws Exception
113             {
114                 runTestPutThenRemoveCategorical( 701, 800 );
115             }
116         } );
117 
118         suite.addTest( new RemovalTestUtil( "testPutCache2" )
119         {
120             // verify that there are no errors with concurrent gets.
121             public void runTest()
122                 throws Exception
123             {
124                 runGetInRange( 0, 1000, false );
125             }
126         } );
127         return suite;
128 
129     }
130 
131     /***
132      * Test setup
133      */
134     public void setUp()
135         throws Exception
136     {
137         JCS.setConfigFilename( "/TestRemoval.ccf" );
138         JCS.getInstance( "testCache1" );
139     }
140 
141 }