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