View Javadoc
1   package org.apache.commons.jcs3;
2   
3   
4   
5   /*
6    * Licensed to the Apache Software Foundation (ASF) under one
7    * or more contributor license agreements.  See the NOTICE file
8    * distributed with this work for additional information
9    * regarding copyright ownership.  The ASF licenses this file
10   * to you under the Apache License, Version 2.0 (the
11   * "License"); you may not use this file except in compliance
12   * with the License.  You may obtain a copy of the License at
13   *
14   *   http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing,
17   * software distributed under the License is distributed on an
18   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19   * KIND, either express or implied.  See the License for the
20   * specific language governing permissions and limitations
21   * under the License.
22   */
23  
24  import junit.extensions.ActiveTestSuite;
25  import junit.framework.Test;
26  import junit.framework.TestCase;
27  
28  /**
29   * Test which exercises the hierarchical removal when the cache is active.
30   */
31  public class ConcurrentRemovalLoadTest
32      extends TestCase
33  {
34      /**
35       * A unit test suite for JUnit. This verifies that we can remove hierarchically while the region
36       * is active.
37       * @return The test suite
38       */
39      public static Test suite()
40      {
41          final ActiveTestSuite suite = new ActiveTestSuite();
42  
43          suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
44          {
45              @Override
46              public void runTest()
47                  throws Exception
48              {
49                  runTestPutThenRemoveCategorical( 0, 200 );
50              }
51          } );
52  
53          suite.addTest( new RemovalTestUtil( "testPutCache1" )
54          {
55              @Override
56              public void runTest()
57                  throws Exception
58              {
59                  runPutInRange( 300, 400 );
60              }
61          } );
62  
63          suite.addTest( new RemovalTestUtil( "testPutCache2" )
64          {
65              @Override
66              public void runTest()
67                  throws Exception
68              {
69                  runPutInRange( 401, 600 );
70              }
71          } );
72  
73          // stomp on previous put
74          suite.addTest( new RemovalTestUtil( "testPutCache3" )
75          {
76              @Override
77              public void runTest()
78                  throws Exception
79              {
80                  runPutInRange( 401, 600 );
81              }
82          } );
83  
84          suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
85          {
86              @Override
87              public void runTest()
88                  throws Exception
89              {
90                  runTestPutThenRemoveCategorical( 601, 700 );
91              }
92          } );
93  
94          suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
95          {
96              @Override
97              public void runTest()
98                  throws Exception
99              {
100                 runTestPutThenRemoveCategorical( 701, 800 );
101             }
102         } );
103 
104         suite.addTest( new RemovalTestUtil( "testRemoveCache1" )
105         {
106             @Override
107             public void runTest()
108                 throws Exception
109             {
110                 runTestPutThenRemoveCategorical( 901, 1000 );
111             }
112         } );
113 
114         suite.addTest( new RemovalTestUtil( "testPutCache2" )
115         {
116             // verify that there are no errors with concurrent gets.
117             @Override
118             public void runTest()
119                 throws Exception
120             {
121                 runGetInRange( 0, 1000, false );
122             }
123         } );
124         return suite;
125     }
126 
127     /**
128      * Test setup
129      * <p>
130      * @throws Exception
131      */
132     @Override
133     public void setUp()
134         throws Exception
135     {
136         JCS.setConfigFilename( "/TestRemoval.ccf" );
137         JCS.getInstance( "testCache1" );
138     }
139 }