1   package org.apache.jcs.auxiliary.disk.block;
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.framework.TestCase;
23  
24  import org.apache.jcs.JCS;
25  import org.apache.jcs.access.TestCacheAccess;
26  
27  /***
28   * This is used by other tests to generate a random load on the disk cache.
29   */
30  public class BlockDiskCacheRandomConcurrentTestUtil
31      extends TestCase
32  {
33      /***
34       * Constructor for the TestDiskCache object.
35       *
36       * @param testName
37       */
38      public BlockDiskCacheRandomConcurrentTestUtil( String testName )
39      {
40          super( testName );
41      }
42  
43      /***
44       * Randomly adds items to cache, gets them, and removes them. The range
45       * count is more than the size of the memory cache, so items should spool to
46       * disk.
47       * <p>
48       * @param region
49       *            Name of the region to access
50       * @param range
51       * @param numOps
52       * @param testNum
53       *
54       * @exception Exception
55       *                If an error occurs
56       */
57      public void runTestForRegion( String region, int range, int numOps, int testNum )
58          throws Exception
59      {
60          // run a rondom operation test to detect deadlocks
61          TestCacheAccess tca = new TestCacheAccess( "/TestBlockDiskCacheCon.ccf" );
62          tca.setRegion( region );
63          tca.random( range, numOps );
64  
65          // make sure a simple put then get works
66          // this may fail if the other tests are flooding the disk cache
67          JCS jcs = JCS.getInstance( region );
68          String key = "testKey" + testNum;
69          String data = "testData" + testNum;
70          jcs.put( key, data );
71          String value = (String) jcs.get( key );
72          assertEquals( data, value );
73      }
74  
75      /***
76       * Test setup
77       */
78      public void setUp()
79      {
80          JCS.setConfigFilename( "/TestBlockDiskCacheCon.ccf" );
81      }
82  }