View Javadoc
1   package org.apache.commons.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       * @param testName
35       */
36      public ConcurrentRemovalLoadTest( String testName )
37      {
38          super( testName );
39      }
40  
41      /**
42       * Main method passes this test to the text test runner.
43       * @param args
44       */
45      public static void main( String args[] )
46      {
47          String[] testCaseName = { RemovalTestUtil.class.getName() };
48          junit.textui.TestRunner.main( testCaseName );
49      }
50  
51      /**
52       * A unit test suite for JUnit. This verfies that we can remove hierarchically while the region
53       * is active.
54       * @return The test suite
55       */
56      public static Test suite()
57      {
58          ActiveTestSuite suite = new ActiveTestSuite();
59  
60          suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
61          {
62              @Override
63              public void runTest()
64                  throws Exception
65              {
66                  runTestPutThenRemoveCategorical( 0, 200 );
67              }
68          } );
69  
70          suite.addTest( new RemovalTestUtil( "testPutCache1" )
71          {
72              @Override
73              public void runTest()
74                  throws Exception
75              {
76                  runPutInRange( 300, 400 );
77              }
78          } );
79  
80          suite.addTest( new RemovalTestUtil( "testPutCache2" )
81          {
82              @Override
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              @Override
94              public void runTest()
95                  throws Exception
96              {
97                  runPutInRange( 401, 600 );
98              }
99          } );
100 
101         suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
102         {
103             @Override
104             public void runTest()
105                 throws Exception
106             {
107                 runTestPutThenRemoveCategorical( 601, 700 );
108             }
109         } );
110 
111         suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
112         {
113             @Override
114             public void runTest()
115                 throws Exception
116             {
117                 runTestPutThenRemoveCategorical( 701, 800 );
118             }
119         } );
120 
121         suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
122         {
123             @Override
124             public void runTest()
125                 throws Exception
126             {
127                 runTestPutThenRemoveCategorical( 901, 1000 );
128             }
129         } );
130 
131         suite.addTest( new RemovalTestUtil( "testPutCache2" )
132         {
133             // verify that there are no errors with concurrent gets.
134             @Override
135             public void runTest()
136                 throws Exception
137             {
138                 runGetInRange( 0, 1000, false );
139             }
140         } );
141         return suite;
142     }
143 
144     /**
145      * Test setup
146      * <p>
147      * @throws Exception
148      */
149     @Override
150     public void setUp()
151         throws Exception
152     {
153         JCS.setConfigFilename( "/TestRemoval.ccf" );
154         JCS.getInstance( "testCache1" );
155     }
156 }