svn commit: r536904 [28/38] - in /jakarta/jcs/trunk: ./ auxiliary-builds/javagroups/ auxiliary-builds/javagroups/src/java/org/apache/jcs/auxiliary/javagroups/ auxiliary-builds/javagroups/src/test/org/apache/jcs/auxiliary/javagroups/ auxiliary-builds/jd...

[email protected]
Newsgroups gmane.comp.jakarta.turbine.jcs.devel
Message-ID <[email protected]>
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
 package org.apache.jcs.auxiliary.disk.indexed;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 import java.io.Serializable;
 import java.text.DecimalFormat;
 import java.util.Random;
@@ -121,7 +140,7 @@
         public Integer id;
 
         /**Byte size
-         * 
+         *
          */
         public byte[] imageBytes;
 

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java Thu May 10 09:03:42 2007
@@ -1,135 +1,154 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.ElementAttributes;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.IElementAttributes;
-
-/**
- * Test store and load keys.
- * 
- * @author Aaron Smuts
- * 
- */
-public class IndexedDiskCacheKeyStoreUnitTest
-    extends TestCase
-{
-
-    /**
-     * Add some keys, store them, load them from disk, then check to see that we
-     * can get the items.
-     * 
-     * @throws Exception
-     * 
-     */
-    public void testStoreKeys()
-        throws Exception
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testStoreKeys" );
-        cattr.setMaxKeySize( 100 );
-        cattr.setDiskPath( "target/test-sandbox/KeyStoreUnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        disk.doRemoveAll();
-
-        int cnt = 25;
-        for ( int i = 0; i < cnt; i++ )
-        {
-            IElementAttributes eAttr = new ElementAttributes();
-            eAttr.setIsSpool( true );
-            ICacheElement element = new CacheElement( cattr.getCacheName(), "key:" + i, "data:" + i );
-            element.setElementAttributes( eAttr );
-            disk.doUpdate( element );
-        }
-
-        for ( int i = 0; i < cnt; i++ )
-        {
-            ICacheElement element = disk.doGet( "key:" + i );
-            assertNotNull( "presave, Should have recevied an element.", element );
-            assertEquals( "presave, element is wrong.", "data:" + i, element.getVal() );
-        }
-
-        disk.saveKeys();
-
-        disk.loadKeys();
-
-        assertEquals( "The disk is the wrong size.", cnt, disk.getSize() );
-
-        for ( int i = 0; i < cnt; i++ )
-        {
-            ICacheElement element = disk.doGet( "key:" + i );
-            assertNotNull( "postsave, Should have recevied an element.", element );
-            assertEquals( "postsave, element is wrong.", "data:" + i, element.getVal() );
-        }
-
-        disk.dump();
-        
-    }
-
-    
-    /**
-     * Add some elements, remove 1, call optiiize, verify that the removed isn't present.
-     * 
-     * We should also compare the data file sizes. . . .
-     * 
-     * @throws Exception
-     * 
-     */
-    public void testOptiimize()
-        throws Exception
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testOptimize" );
-        cattr.setMaxKeySize( 100 );
-        cattr.setDiskPath( "target/test-sandbox/KeyStoreUnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        disk.doRemoveAll();
-
-        int cnt = 25;
-        for ( int i = 0; i < cnt; i++ )
-        {
-            IElementAttributes eAttr = new ElementAttributes();
-            eAttr.setIsSpool( true );
-            ICacheElement element = new CacheElement( cattr.getCacheName(), "key:" + i, "data:" + i );
-            element.setElementAttributes( eAttr );
-            disk.doUpdate( element );
-        }
-        
-        long preAddRemoveSize = disk.getDataFileSize();
-        
-        IElementAttributes eAttr = new ElementAttributes();
-        eAttr.setIsSpool( true );
-        ICacheElement elementSetup = new CacheElement( cattr.getCacheName(), "key:" + "A", "data:" + "A" );
-        elementSetup.setElementAttributes( eAttr );
-        disk.doUpdate( elementSetup );
-                
-        ICacheElement elementRet = disk.doGet( "key:" + "A" );
-        assertNotNull( "postsave, Should have recevied an element.", elementRet );
-        assertEquals( "postsave, element is wrong.", "data:" + "A", elementRet.getVal() );
-        
-        disk.remove( "key:" + "A" );
-
-        long preSize = disk.getDataFileSize();
-        // synchronous versoin
-        disk.optimizeFile(); //deoptimizeRealTime();
-        long postSize = disk.getDataFileSize();
-        
-        System.out.println( "preAddRemoveSize " + preAddRemoveSize );
-        System.out.println( "preSize " + preSize );
-        System.out.println( "postSize " + postSize );
-        
-        assertTrue( "Should be smaller.", postSize < preSize );
-        assertEquals( "Should be the same size after optimization as before add and remove.", preAddRemoveSize, postSize );
-              
-        for ( int i = 0; i < cnt; i++ )
-        {
-            ICacheElement element = disk.doGet( "key:" + i );
-            assertNotNull( "postsave, Should have recevied an element.", element );
-            assertEquals( "postsave, element is wrong.", "data:" + i, element.getVal() );
-        }                     
-    }             
-}
+package org.apache.jcs.auxiliary.disk.indexed;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+
+/**
+ * Test store and load keys.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class IndexedDiskCacheKeyStoreUnitTest
+    extends TestCase
+{
+
+    /**
+     * Add some keys, store them, load them from disk, then check to see that we
+     * can get the items.
+     *
+     * @throws Exception
+     *
+     */
+    public void testStoreKeys()
+        throws Exception
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testStoreKeys" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/KeyStoreUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( cattr.getCacheName(), "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "presave, Should have recevied an element.", element );
+            assertEquals( "presave, element is wrong.", "data:" + i, element.getVal() );
+        }
+
+        disk.saveKeys();
+
+        disk.loadKeys();
+
+        assertEquals( "The disk is the wrong size.", cnt, disk.getSize() );
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "postsave, Should have recevied an element.", element );
+            assertEquals( "postsave, element is wrong.", "data:" + i, element.getVal() );
+        }
+
+        disk.dump();
+
+    }
+
+
+    /**
+     * Add some elements, remove 1, call optiiize, verify that the removed isn't present.
+     *
+     * We should also compare the data file sizes. . . .
+     *
+     * @throws Exception
+     *
+     */
+    public void testOptiimize()
+        throws Exception
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testOptimize" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/KeyStoreUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( cattr.getCacheName(), "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        long preAddRemoveSize = disk.getDataFileSize();
+
+        IElementAttributes eAttr = new ElementAttributes();
+        eAttr.setIsSpool( true );
+        ICacheElement elementSetup = new CacheElement( cattr.getCacheName(), "key:" + "A", "data:" + "A" );
+        elementSetup.setElementAttributes( eAttr );
+        disk.doUpdate( elementSetup );
+
+        ICacheElement elementRet = disk.doGet( "key:" + "A" );
+        assertNotNull( "postsave, Should have recevied an element.", elementRet );
+        assertEquals( "postsave, element is wrong.", "data:" + "A", elementRet.getVal() );
+
+        disk.remove( "key:" + "A" );
+
+        long preSize = disk.getDataFileSize();
+        // synchronous versoin
+        disk.optimizeFile(); //deoptimizeRealTime();
+        long postSize = disk.getDataFileSize();
+
+        System.out.println( "preAddRemoveSize " + preAddRemoveSize );
+        System.out.println( "preSize " + preSize );
+        System.out.println( "postSize " + postSize );
+
+        assertTrue( "Should be smaller.", postSize < preSize );
+        assertEquals( "Should be the same size after optimization as before add and remove.", preAddRemoveSize, postSize );
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "postsave, Should have recevied an element.", element );
+            assertEquals( "postsave, element is wrong.", "data:" + i, element.getVal() );
+        }
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java Thu May 10 09:03:42 2007
@@ -1,155 +1,158 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License")
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import junit.extensions.ActiveTestSuite;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Test which exercises the indexed disk cache. This one uses three different
- * regions for thre threads. It uses a config file that specifies 0 items in
- * memory.
- * 
- * @version $Id: TestDiskCacheNoMemory.java 224346 2005-06-04 02:01:59Z asmuts $
- */
-public class IndexedDiskCacheNoMemoryUnitTest
-    extends TestCase
-{
-    /**
-     * Number of items to cache; the configured maxObjects for the memory cache
-     * regions is 0.
-     */
-    private static int items = 2000;
-
-    /**
-     * Constructor for the TestDiskCache object.
-     * 
-     * @param testName
-     */
-    public IndexedDiskCacheNoMemoryUnitTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Main method passes this test to the text test runner.
-     * 
-     * @param args
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { IndexedDiskCacheNoMemoryUnitTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
-    }
-
-    /**
-     * A unit test suite for JUnit
-     * 
-     * @return The test suite
-     */
-    public static Test suite()
-    {
-        ActiveTestSuite suite = new ActiveTestSuite();
-
-        suite.addTest( new IndexedDiskCacheNoMemoryUnitTest( "testIndexedDiskCache1" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion1" );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheNoMemoryUnitTest( "testIndexedDiskCache2" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion2" );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheNoMemoryUnitTest( "testIndexedDiskCache3" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion3" );
-            }
-        } );
-
-        return suite;
-    }
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCacheNoMemory.ccf" );
-    }
-
-    /**
-     * Adds items to cache, gets them, and removes them. The item count is more
-     * than the size of the memory cache, so items should spool to disk.
-     * 
-     * @param region
-     *            Name of the region to access
-     * 
-     * @exception Exception
-     *                If an error occurs
-     */
-    public void runTestForRegion( String region )
-        throws Exception
-    {
-        JCS jcs = JCS.getInstance( region );
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        // Test that all items are in cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = (String) jcs.get( i + ":key" );
-
-            assertEquals( region + " data " + i, value );
-        }
-
-        // Remove all the items
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.remove( i + ":key" );
-        }
-
-        // Verify removal
-        for ( int i = 0; i <= items; i++ )
-        {
-            assertNull( "Removed key should be null: " + i + ":key" + "\n stats " + jcs.getStats(), jcs.get( i + ":key" ) );
-        }
-
-        // dump the stats to the report
-        System.out.println( jcs.getStats() );
-    }
-}
+package org.apache.jcs.auxiliary.disk.indexed;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.extensions.ActiveTestSuite;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/**
+ * Test which exercises the indexed disk cache. This one uses three different
+ * regions for thre threads. It uses a config file that specifies 0 items in
+ * memory.
+ *
+ * @version $Id: TestDiskCacheNoMemory.java 224346 2005-06-04 02:01:59Z asmuts $
+ */
+public class IndexedDiskCacheNoMemoryUnitTest
+    extends TestCase
+{
+    /**
+     * Number of items to cache; the configured maxObjects for the memory cache
+     * regions is 0.
+     */
+    private static int items = 2000;
+
+    /**
+     * Constructor for the TestDiskCache object.
+     *
+     * @param testName
+     */
+    public IndexedDiskCacheNoMemoryUnitTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * Main method passes this test to the text test runner.
+     *
+     * @param args
+     */
+    public static void main( String args[] )
+    {
+        String[] testCaseName = { IndexedDiskCacheNoMemoryUnitTest.class.getName() };
+        junit.textui.TestRunner.main( testCaseName );
+    }
+
+    /**
+     * A unit test suite for JUnit
+     *
+     * @return The test suite
+     */
+    public static Test suite()
+    {
+        ActiveTestSuite suite = new ActiveTestSuite();
+
+        suite.addTest( new IndexedDiskCacheNoMemoryUnitTest( "testIndexedDiskCache1" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion1" );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheNoMemoryUnitTest( "testIndexedDiskCache2" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion2" );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheNoMemoryUnitTest( "testIndexedDiskCache3" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion3" );
+            }
+        } );
+
+        return suite;
+    }
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCacheNoMemory.ccf" );
+    }
+
+    /**
+     * Adds items to cache, gets them, and removes them. The item count is more
+     * than the size of the memory cache, so items should spool to disk.
+     *
+     * @param region
+     *            Name of the region to access
+     *
+     * @exception Exception
+     *                If an error occurs
+     */
+    public void runTestForRegion( String region )
+        throws Exception
+    {
+        JCS jcs = JCS.getInstance( region );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = (String) jcs.get( i + ":key" );
+
+            assertEquals( region + " data " + i, value );
+        }
+
+        // Remove all the items
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.remove( i + ":key" );
+        }
+
+        // Verify removal
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key" + "\n stats " + jcs.getStats(), jcs.get( i + ":key" ) );
+        }
+
+        // dump the stats to the report
+        System.out.println( jcs.getStats() );
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheOptimizationUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheOptimizationUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheOptimizationUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheOptimizationUnitTest.java Thu May 10 09:03:42 2007
@@ -1,74 +1,93 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.utils.timing.SleepUtil;
-
-/**
- * Tests for the optimization routine.
- * <p>
- * @author Aaron Smuts
- */
-public class IndexedDiskCacheOptimizationUnitTest
-    extends TestCase
-{
-    /**
-     * Set the optimize at remove count to 10. Add 20. Check the file size. Remove 10. Check the
-     * times optimized. Check the file size.
-     * @throws Exception
-     */
-    public void testBasicOptimization()
-        throws Exception
-    {
-        // SETUP
-        int removeCount = 50;
-
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testOptimization" );
-        cattr.setMaxKeySize( removeCount * 3 );
-        cattr.setOptimizeAtRemoveCount( removeCount );
-        cattr.setMaxRecycleBinSize( removeCount * 3 );
-        cattr.setDiskPath( "target/test-sandbox/testOptimization" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        disk.removeAll();
-
-        int numberToInsert = removeCount * 2;
-        ICacheElement[] elements = DiskTestObjectUtil
-            .createCacheElementsWithTestObjectsOfVariableSizes( numberToInsert, cattr.getCacheName() );
-
-        for ( int i = 0; i < elements.length; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        Thread.sleep( 1000 );
-        long sizeBeforeRemove = disk.getDataFileSize();
-        System.out.println( "file sizeBeforeRemove " + sizeBeforeRemove );
-        System.out.println( "totalSize inserted " + DiskTestObjectUtil.totalSize( elements, numberToInsert ) );
-
-        // DO WORK
-        for ( int i = 0; i < removeCount; i++ )
-        {
-            disk.doRemove( new Integer( i ) );
-        }
-
-        SleepUtil.sleepAtLeast( 1000 );
-        
-        // VERIFY
-        long sizeAfterRemove = disk.getDataFileSize();
-        System.out.println( "file sizeAfterRemove " + sizeAfterRemove );
-        long expectedSizeAfterRemove = DiskTestObjectUtil.totalSize( elements, removeCount, elements.length );
-        System.out.println( "totalSize expected after remove " + expectedSizeAfterRemove );
-
-        // test is prone to failure for timing reasons.
-        if ( expectedSizeAfterRemove != sizeAfterRemove )
-        {
-            SleepUtil.sleepAtLeast( 2000 ); 
-        }
-        
-        assertTrue( "The post optimization size should be smaller.", sizeAfterRemove < sizeBeforeRemove );
-        assertEquals( "The file size is not as expected size.", expectedSizeAfterRemove, sizeAfterRemove );
-    }
-}
+package org.apache.jcs.auxiliary.disk.indexed;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.utils.timing.SleepUtil;
+
+/**
+ * Tests for the optimization routine.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class IndexedDiskCacheOptimizationUnitTest
+    extends TestCase
+{
+    /**
+     * Set the optimize at remove count to 10. Add 20. Check the file size. Remove 10. Check the
+     * times optimized. Check the file size.
+     * @throws Exception
+     */
+    public void testBasicOptimization()
+        throws Exception
+    {
+        // SETUP
+        int removeCount = 50;
+
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testOptimization" );
+        cattr.setMaxKeySize( removeCount * 3 );
+        cattr.setOptimizeAtRemoveCount( removeCount );
+        cattr.setMaxRecycleBinSize( removeCount * 3 );
+        cattr.setDiskPath( "target/test-sandbox/testOptimization" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.removeAll();
+
+        int numberToInsert = removeCount * 2;
+        ICacheElement[] elements = DiskTestObjectUtil
+            .createCacheElementsWithTestObjectsOfVariableSizes( numberToInsert, cattr.getCacheName() );
+
+        for ( int i = 0; i < elements.length; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        Thread.sleep( 1000 );
+        long sizeBeforeRemove = disk.getDataFileSize();
+        System.out.println( "file sizeBeforeRemove " + sizeBeforeRemove );
+        System.out.println( "totalSize inserted " + DiskTestObjectUtil.totalSize( elements, numberToInsert ) );
+
+        // DO WORK
+        for ( int i = 0; i < removeCount; i++ )
+        {
+            disk.doRemove( new Integer( i ) );
+        }
+
+        SleepUtil.sleepAtLeast( 1000 );
+
+        // VERIFY
+        long sizeAfterRemove = disk.getDataFileSize();
+        System.out.println( "file sizeAfterRemove " + sizeAfterRemove );
+        long expectedSizeAfterRemove = DiskTestObjectUtil.totalSize( elements, removeCount, elements.length );
+        System.out.println( "totalSize expected after remove " + expectedSizeAfterRemove );
+
+        // test is prone to failure for timing reasons.
+        if ( expectedSizeAfterRemove != sizeAfterRemove )
+        {
+            SleepUtil.sleepAtLeast( 2000 );
+        }
+
+        assertTrue( "The post optimization size should be smaller.", sizeAfterRemove < sizeBeforeRemove );
+        assertEquals( "The file size is not as expected size.", expectedSizeAfterRemove, sizeAfterRemove );
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java Thu May 10 09:03:42 2007
@@ -1,66 +1,85 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.access.TestCacheAccess;
-
-/**
- * This is used by other tests to generate a random load on the disk cache.
- */
-public class IndexedDiskCacheRandomConcurrentTestUtil
-    extends TestCase
-{
-
-    /**
-     * Constructor for the TestDiskCache object.
-     * 
-     * @param testName
-     */
-    public IndexedDiskCacheRandomConcurrentTestUtil( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Randomly adds items to cache, gets them, and removes them. The range
-     * count is more than the size of the memory cache, so items should spool to
-     * disk.
-     * 
-     * @param region
-     *            Name of the region to access
-     * @param range
-     * @param numOps
-     * @param testNum
-     * 
-     * @exception Exception
-     *                If an error occurs
-     */
-    public void runTestForRegion( String region, int range, int numOps, int testNum )
-        throws Exception
-    {
-        // run a rondom operation test to detect deadlocks
-        TestCacheAccess tca = new TestCacheAccess( "/TestDiskCacheCon.ccf" );
-        tca.setRegion( region );
-        tca.random( range, numOps );
-
-        // make sure a simple put then get works
-        // this may fail if the other tests are flooding the disk cache
-        JCS jcs = JCS.getInstance( region );
-        String key = "testKey" + testNum;
-        String data = "testData" + testNum;
-        jcs.put( key, data );
-        String value = (String) jcs.get( key );
-        assertEquals( data, value );
-
-    }
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
-    }
-
-}
+package org.apache.jcs.auxiliary.disk.indexed;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.access.TestCacheAccess;
+
+/**
+ * This is used by other tests to generate a random load on the disk cache.
+ */
+public class IndexedDiskCacheRandomConcurrentTestUtil
+    extends TestCase
+{
+
+    /**
+     * Constructor for the TestDiskCache object.
+     *
+     * @param testName
+     */
+    public IndexedDiskCacheRandomConcurrentTestUtil( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * Randomly adds items to cache, gets them, and removes them. The range
+     * count is more than the size of the memory cache, so items should spool to
+     * disk.
+     *
+     * @param region
+     *            Name of the region to access
+     * @param range
+     * @param numOps
+     * @param testNum
+     *
+     * @exception Exception
+     *                If an error occurs
+     */
+    public void runTestForRegion( String region, int range, int numOps, int testNum )
+        throws Exception
+    {
+        // run a rondom operation test to detect deadlocks
+        TestCacheAccess tca = new TestCacheAccess( "/TestDiskCacheCon.ccf" );
+        tca.setRegion( region );
+        tca.random( range, numOps );
+
+        // make sure a simple put then get works
+        // this may fail if the other tests are flooding the disk cache
+        JCS jcs = JCS.getInstance( region );
+        String key = "testKey" + testNum;
+        String data = "testData" + testNum;
+        jcs.put( key, data );
+        String value = (String) jcs.get( key );
+        assertEquals( data, value );
+
+    }
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
+    }
+
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java Thu May 10 09:03:42 2007
@@ -1,184 +1,187 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License")
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import junit.extensions.ActiveTestSuite;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Test which exercises the indexed disk cache. Runs three threads against the
- * same region.
- * 
- * @version $Id: TestDiskCacheConcurrent.java,v 1.8 2005/02/01 00:01:59 asmuts
- *          Exp $
- */
-public class IndexedDiskCacheSameRegionConcurrentUnitTest
-    extends TestCase
-{
-    /**
-     * Constructor for the TestDiskCache object.
-     * 
-     * @param testName
-     */
-    public IndexedDiskCacheSameRegionConcurrentUnitTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Main method passes this test to the text test runner.
-     * 
-     * @param args
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { IndexedDiskCacheSameRegionConcurrentUnitTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
-    }
-
-    /**
-     * A unit test suite for JUnit
-     * 
-     * @return The test suite
-     */
-    public static Test suite()
-    {
-        ActiveTestSuite suite = new ActiveTestSuite();
-
-        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache1" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 0, 200 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache2" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 1000, 1200 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache3" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 2000, 2200 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache4" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 2200, 5200 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache5" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 0, 5200 );
-            }
-        } );
-
-        return suite;
-    }
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
-    }
-
-    // /**
-    // * Tests the region which uses the indexed disk cache
-    // */
-    // public void testIndexedDiskCache()
-    // throws Exception
-    // {
-    // runTestForRegion( "indexedRegion" );
-    // }
-    //
-    // /**
-    // * Tests the region which uses the indexed disk cache
-    // */
-    // public void testIndexedDiskCache2()
-    // throws Exception
-    // {
-    // runTestForRegion( "indexedRegion2" );
-    // }
-
-    /**
-     * Adds items to cache, gets them, and removes them. The item count is more
-     * than the size of the memory cache, so items should spool to disk.
-     * 
-     * @param region
-     *            Name of the region to access
-     * @param start
-     * @param end
-     * 
-     * @exception Exception
-     *                If an error occurs
-     */
-    public void runTestForRegion( String region, int start, int end )
-        throws Exception
-    {
-        JCS jcs = JCS.getInstance( region );
-
-        // Add items to cache
-
-        for ( int i = start; i <= end; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        // Test that all items are in cache
-
-        for ( int i = start; i <= end; i++ )
-        {
-            String value = (String) jcs.get( i + ":key" );
-
-            assertEquals( region + " data " + i, value );
-        }
-
-        /*
-         * // you can't remove in one thread and expect them to be in another //
-         * Remove all the items
-         * 
-         * for ( int i = start; i <= end; i++ ) { jcs.remove( i + ":key" ); } //
-         * Verify removal
-         * 
-         * for ( int i = start; i <= end; i++ ) { assertNull( "Removed key
-         * should be null: " + i + ":key", jcs.get( i + ":key" ) ); }
-         */
-
-    }
-}
+package org.apache.jcs.auxiliary.disk.indexed;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.extensions.ActiveTestSuite;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/**
+ * Test which exercises the indexed disk cache. Runs three threads against the
+ * same region.
+ *
+ * @version $Id: TestDiskCacheConcurrent.java,v 1.8 2005/02/01 00:01:59 asmuts
+ *          Exp $
+ */
+public class IndexedDiskCacheSameRegionConcurrentUnitTest
+    extends TestCase
+{
+    /**
+     * Constructor for the TestDiskCache object.
+     *
+     * @param testName
+     */
+    public IndexedDiskCacheSameRegionConcurrentUnitTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * Main method passes this test to the text test runner.
+     *
+     * @param args
+     */
+    public static void main( String args[] )
+    {
+        String[] testCaseName = { IndexedDiskCacheSameRegionConcurrentUnitTest.class.getName() };
+        junit.textui.TestRunner.main( testCaseName );
+    }
+
+    /**
+     * A unit test suite for JUnit
+     *
+     * @return The test suite
+     */
+    public static Test suite()
+    {
+        ActiveTestSuite suite = new ActiveTestSuite();
+
+        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache1" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 0, 200 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache2" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 1000, 1200 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache3" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 2000, 2200 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache4" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 2200, 5200 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheSameRegionConcurrentUnitTest( "testIndexedDiskCache5" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 0, 5200 );
+            }
+        } );
+
+        return suite;
+    }
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
+    }
+
+    // /**
+    // * Tests the region which uses the indexed disk cache
+    // */
+    // public void testIndexedDiskCache()
+    // throws Exception
+    // {
+    // runTestForRegion( "indexedRegion" );
+    // }
+    //
+    // /**
+    // * Tests the region which uses the indexed disk cache
+    // */
+    // public void testIndexedDiskCache2()
+    // throws Exception
+    // {
+    // runTestForRegion( "indexedRegion2" );
+    // }
+
+    /**
+     * Adds items to cache, gets them, and removes them. The item count is more
+     * than the size of the memory cache, so items should spool to disk.
+     *
+     * @param region
+     *            Name of the region to access
+     * @param start
+     * @param end
+     *
+     * @exception Exception
+     *                If an error occurs
+     */
+    public void runTestForRegion( String region, int start, int end )
+        throws Exception
+    {
+        JCS jcs = JCS.getInstance( region );
+
+        // Add items to cache
+
+        for ( int i = start; i <= end; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        // Test that all items are in cache
+
+        for ( int i = start; i <= end; i++ )
+        {
+            String value = (String) jcs.get( i + ":key" );
+
+            assertEquals( region + " data " + i, value );
+        }
+
+        /*
+         * // you can't remove in one thread and expect them to be in another //
+         * Remove all the items
+         *
+         * for ( int i = start; i <= end; i++ ) { jcs.remove( i + ":key" ); } //
+         * Verify removal
+         *
+         * for ( int i = start; i <= end; i++ ) { assertNull( "Removed key
+         * should be null: " + i + ":key", jcs.get( i + ":key" ) ); }
+         */
+
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSteadyLoadTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSteadyLoadTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSteadyLoadTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSteadyLoadTest.java Thu May 10 09:03:42 2007
@@ -1,131 +1,150 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-import java.text.DecimalFormat;
-import java.util.Random;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.auxiliary.disk.DiskTestObject;
-import org.apache.jcs.utils.timing.ElapsedTimer;
-
-/**
- * This allows you to put thousands of large objects into the disk cache and to force removes to
- * trigger optimizations along the way.
- * <p>
- * @author Aaron Smuts
- */
-public class IndexedDiskCacheSteadyLoadTest
-    extends TestCase
-{
-    private static final String LOG_DIVIDER = "---------------------------";
-
-    private static Runtime rt = Runtime.getRuntime();
-
-    private static DecimalFormat format = new DecimalFormat( "#,###" );
-
-    /**
-     * Insert 2000 wait 1 second, repeat. Average 1000 / sec.
-     * <p>
-     * @throws Exception
-     */
-    public void testRunSteadyLoadTest()
-        throws Exception
-    {
-        JCS.setConfigFilename( "/TestDiskCacheSteadyLoad.ccf" );
-
-        System.out.println( "runSteadyLoadTest" );
-
-        logMemoryUsage();
-
-        int numPerRun = 200;
-        long pauseBetweenRuns = 1000;
-        int runCount = 0;
-        int runs = 1000;
-        int upperKB = 50;
-
-        JCS jcs = JCS.getInstance( ( numPerRun / 2 ) + "aSecond" );
-
-        ElapsedTimer timer = new ElapsedTimer();
-        int numToGet = numPerRun * ( runs / 10 );
-        for ( int i = 0; i < numToGet; i++ )
-        {
-            jcs.get( String.valueOf( i ) );
-        }
-        System.out.println( LOG_DIVIDER );
-        System.out.println( "After getting " + numToGet );
-        System.out.println( "Elapsed " + timer.getElapsedTimeString() );
-        logMemoryUsage();
-
-        jcs.clear();
-        Thread.sleep( 3000 );
-        System.out.println( LOG_DIVIDER );
-        System.out.println( "Start putting" );
-
-        long totalSize = 0;
-        int totalPut = 0;
-
-        Random random = new Random( 89 );
-        while ( runCount < runs )
-        {
-            runCount++;
-            for ( int i = 0; i < numPerRun; i++ )
-            {
-                // 1/2 upper to upperKB-4 KB
-                int kiloBytes = Math.max( upperKB / 2, random.nextInt( upperKB ) );
-                int bytes = ( kiloBytes ) * 1024;
-                totalSize += bytes;
-                totalPut++;
-                DiskTestObject object = new DiskTestObject( new Integer( i ), new byte[bytes] );
-                jcs.put( String.valueOf( totalPut ), object );
-            }
-
-            // remove half of those inserted the previous run
-            if ( runCount > 1 )
-            {
-                for ( int j = ( ( totalPut - numPerRun ) - ( numPerRun / 2 ) ); j < ( totalPut - numPerRun ); j++ )
-                {
-                    jcs.remove( String.valueOf( j ) );
-                }
-            }
-
-            Thread.sleep( pauseBetweenRuns );
-            if ( runCount % 1 == 0 )
-            {
-                System.out.println( LOG_DIVIDER );
-                System.out.println( "Elapsed " + timer.getElapsedTimeString() );
-                System.out.println( "Run count: " + runCount + " Average size: " + ( totalSize / totalPut ) + "\n"
-                    + jcs.getStats() );
-                logMemoryUsage();
-            }
-        }
-
-        Thread.sleep( 3000 );
-        System.out.println( jcs.getStats() );
-        logMemoryUsage();
-
-        Thread.sleep( 10000 );
-        System.out.println( jcs.getStats() );
-        logMemoryUsage();
-
-        System.gc();
-        Thread.sleep( 3000 );
-        System.gc();
-        System.out.println( jcs.getStats() );
-        logMemoryUsage();
-    }
-
-    /**
-     * Logs the memory usage.
-     */
-    private static void logMemoryUsage()
-    {
-        long byte2MB = 1024 * 1024;
-        long total = rt.totalMemory() / byte2MB;
-        long free = rt.freeMemory() / byte2MB;
-        long used = total - free;
-        System.out.println( LOG_DIVIDER );
-        System.out.println( "Memory:" + " Used:" + format.format( used ) + "MB" + " Free:" + format.format( free )
-            + "MB" + " Total:" + format.format( total ) + "MB" );
-    }
-}
+package org.apache.jcs.auxiliary.disk.indexed;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.text.DecimalFormat;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.auxiliary.disk.DiskTestObject;
+import org.apache.jcs.utils.timing.ElapsedTimer;
+
+/**
+ * This allows you to put thousands of large objects into the disk cache and to force removes to
+ * trigger optimizations along the way.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class IndexedDiskCacheSteadyLoadTest
+    extends TestCase
+{
+    private static final String LOG_DIVIDER = "---------------------------";
+
+    private static Runtime rt = Runtime.getRuntime();
+
+    private static DecimalFormat format = new DecimalFormat( "#,###" );
+
+    /**
+     * Insert 2000 wait 1 second, repeat. Average 1000 / sec.
+     * <p>
+     * @throws Exception
+     */
+    public void testRunSteadyLoadTest()
+        throws Exception
+    {
+        JCS.setConfigFilename( "/TestDiskCacheSteadyLoad.ccf" );
+
+        System.out.println( "runSteadyLoadTest" );
+
+        logMemoryUsage();
+
+        int numPerRun = 200;
+        long pauseBetweenRuns = 1000;
+        int runCount = 0;
+        int runs = 1000;
+        int upperKB = 50;
+
+        JCS jcs = JCS.getInstance( ( numPerRun / 2 ) + "aSecond" );
+
+        ElapsedTimer timer = new ElapsedTimer();
+        int numToGet = numPerRun * ( runs / 10 );
+        for ( int i = 0; i < numToGet; i++ )
+        {
+            jcs.get( String.valueOf( i ) );
+        }
+        System.out.println( LOG_DIVIDER );
+        System.out.println( "After getting " + numToGet );
+        System.out.println( "Elapsed " + timer.getElapsedTimeString() );
+        logMemoryUsage();
+
+        jcs.clear();
+        Thread.sleep( 3000 );
+        System.out.println( LOG_DIVIDER );
+        System.out.println( "Start putting" );
+
+        long totalSize = 0;
+        int totalPut = 0;
+
+        Random random = new Random( 89 );
+        while ( runCount < runs )
+        {
+            runCount++;
+            for ( int i = 0; i < numPerRun; i++ )
+            {
+                // 1/2 upper to upperKB-4 KB
+                int kiloBytes = Math.max( upperKB / 2, random.nextInt( upperKB ) );
+                int bytes = ( kiloBytes ) * 1024;
+                totalSize += bytes;
+                totalPut++;
+                DiskTestObject object = new DiskTestObject( new Integer( i ), new byte[bytes] );
+                jcs.put( String.valueOf( totalPut ), object );
+            }
+
+            // remove half of those inserted the previous run
+            if ( runCount > 1 )
+            {
+                for ( int j = ( ( totalPut - numPerRun ) - ( numPerRun / 2 ) ); j < ( totalPut - numPerRun ); j++ )
+                {
+                    jcs.remove( String.valueOf( j ) );
+                }
+            }
+
+            Thread.sleep( pauseBetweenRuns );
+            if ( runCount % 1 == 0 )
+            {
+                System.out.println( LOG_DIVIDER );
+                System.out.println( "Elapsed " + timer.getElapsedTimeString() );
+                System.out.println( "Run count: " + runCount + " Average size: " + ( totalSize / totalPut ) + "\n"
+                    + jcs.getStats() );
+                logMemoryUsage();
+            }
+        }
+
+        Thread.sleep( 3000 );
+        System.out.println( jcs.getStats() );
+        logMemoryUsage();
+
+        Thread.sleep( 10000 );
+        System.out.println( jcs.getStats() );
+        logMemoryUsage();
+
+        System.gc();
+        Thread.sleep( 3000 );
+        System.gc();
+        System.out.println( jcs.getStats() );
+        logMemoryUsage();
+    }
+
+    /**
+     * Logs the memory usage.
+     */
+    private static void logMemoryUsage()
+    {
+        long byte2MB = 1024 * 1024;
+        long total = rt.totalMemory() / byte2MB;
+        long free = rt.freeMemory() / byte2MB;
+        long used = total - free;
+        System.out.println( LOG_DIVIDER );
+        System.out.println( "Memory:" + " Used:" + format.format( used ) + "MB" + " Free:" + format.format( free )
+            + "MB" + " Total:" + format.format( total ) + "MB" );
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheRemovalUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheRemovalUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheRemovalUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheRemovalUnitTest.java Thu May 10 09:03:42 2007
@@ -1,154 +1,173 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/** Tests for the removal functionality. */
-public class JDBCDiskCacheRemovalUnitTest
-    extends TestCase
-{
-    /** db name -- set in system props */
-    private String databaseName = "JCS_STORE_REMOVAL";
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        System.setProperty( "DATABASE_NAME", databaseName );
-        JCS.setConfigFilename( "/TestJDBCDiskCacheRemoval.ccf" );
-    }
-
-    /**
-     * Verify the fix for BUG JCS-20
-     * <p>
-     * Setup an hsql db. Add an item. Remove using partial key.
-     */
-    public void testPartialKeyRemoval_Good()
-        throws Exception
-    {
-        // SETUP
-        setupDatabase();
-
-        String keyPart1 = "part1";
-        String keyPart2 = "part2";
-        String region = "testCache1";
-        String data = "adfadsfasfddsafasasd";
-
-        JCS jcs = JCS.getInstance( region );
-
-        // DO WORK
-        jcs.put( keyPart1 + ":" + keyPart2, data );
-        Thread.sleep( 1000 );
-
-        // VERIFY
-        String resultBeforeRemove = (String) jcs.get( keyPart1 + ":" + keyPart2 );
-        assertEquals( "Wrong result", data, resultBeforeRemove );
-
-        jcs.remove( keyPart1 + ":" );
-        String resultAfterRemove = (String) jcs.get( keyPart1 + ":" + keyPart2 );
-        assertNull( "Should not have a result after removal.", resultAfterRemove );
-        
-        System.out.println( jcs.getStats() );
-    }
-
-    /**
-     * Create the database.
-     * @throws SQLException
-     */
-    private void setupDatabase()
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-    {
-        System.setProperty( "hsqldb.cache_scale", "8" );
-
-        String rafroot = "target";
-        Properties p = new Properties();
-        String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
-        String url = p.getProperty( "url", "jdbc:hsqldb:" );
-        String database = p.getProperty( "database", rafroot + "/cache_hsql_db" );
-        String user = p.getProperty( "user", "sa" );
-        String password = p.getProperty( "password", "" );
-
-        new org.hsqldb.jdbcDriver();
-        Class.forName( driver ).newInstance();
-        Connection cConn = DriverManager.getConnection( url + database, user, password );
-
-        setupTABLE( cConn );
-    }
-
-    /**
-     * SETUP TABLE FOR CACHE
-     * @param cConn
-     */
-    private void setupTABLE( Connection cConn )
-    {
-        boolean newT = true;
-
-        StringBuffer createSql = new StringBuffer();
-        createSql.append( "CREATE CACHED TABLE " + databaseName );
-        createSql.append( "( " );
-        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
-        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
-        createSql.append( "ELEMENT               BINARY, " );
-        createSql.append( "CREATE_TIME           DATE, " );
-        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
-        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
-        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
-        createSql.append( "IS_ETERNAL            CHAR(1), " );
-        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
-        createSql.append( ");" );
-
-        Statement sStatement = null;
-        try
-        {
-            sStatement = cConn.createStatement();
-        }
-        catch ( SQLException e )
-        {
-            e.printStackTrace();
-        }
-
-        try
-        {
-            sStatement.executeQuery( createSql.toString() );
-            sStatement.close();
-        }
-        catch ( SQLException e )
-        {
-            if ( e.toString().indexOf( "already exists" ) != -1 )
-            {
-                newT = false;
-            }
-            else
-            {
-                // TODO figure out if it exists prior to trying to create it.
-                // log.error( "Problem creating table.", e );
-                e.printStackTrace();
-            }
-        }
-
-        String setupData[] = { "create index iKEY on " + databaseName + " (CACHE_KEY, REGION)" };
-
-        if ( newT )
-        {
-            for ( int i = 1; i < setupData.length; i++ )
-            {
-                try
-                {
-                    sStatement.executeQuery( setupData[i] );
-                }
-                catch ( SQLException e )
-                {
-                    System.out.println( "Exception: " + e );
-                }
-            }
-        } // end ifnew
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/** Tests for the removal functionality. */
+public class JDBCDiskCacheRemovalUnitTest
+    extends TestCase
+{
+    /** db name -- set in system props */
+    private String databaseName = "JCS_STORE_REMOVAL";
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        System.setProperty( "DATABASE_NAME", databaseName );
+        JCS.setConfigFilename( "/TestJDBCDiskCacheRemoval.ccf" );
+    }
+
+    /**
+     * Verify the fix for BUG JCS-20
+     * <p>
+     * Setup an hsql db. Add an item. Remove using partial key.
+     */
+    public void testPartialKeyRemoval_Good()
+        throws Exception
+    {
+        // SETUP
+        setupDatabase();
+
+        String keyPart1 = "part1";
+        String keyPart2 = "part2";
+        String region = "testCache1";
+        String data = "adfadsfasfddsafasasd";
+
+        JCS jcs = JCS.getInstance( region );
+
+        // DO WORK
+        jcs.put( keyPart1 + ":" + keyPart2, data );
+        Thread.sleep( 1000 );
+
+        // VERIFY
+        String resultBeforeRemove = (String) jcs.get( keyPart1 + ":" + keyPart2 );
+        assertEquals( "Wrong result", data, resultBeforeRemove );
+
+        jcs.remove( keyPart1 + ":" );
+        String resultAfterRemove = (String) jcs.get( keyPart1 + ":" + keyPart2 );
+        assertNull( "Should not have a result after removal.", resultAfterRemove );
+
+        System.out.println( jcs.getStats() );
+    }
+
+    /**
+     * Create the database.
+     * @throws SQLException
+     */
+    private void setupDatabase()
+        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+    {
+        System.setProperty( "hsqldb.cache_scale", "8" );
+
+        String rafroot = "target";
+        Properties p = new Properties();
+        String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
+        String url = p.getProperty( "url", "jdbc:hsqldb:" );
+        String database = p.getProperty( "database", rafroot + "/cache_hsql_db" );
+        String user = p.getProperty( "user", "sa" );
+        String password = p.getProperty( "password", "" );
+
+        new org.hsqldb.jdbcDriver();
+        Class.forName( driver ).newInstance();
+        Connection cConn = DriverManager.getConnection( url + database, user, password );
+
+        setupTABLE( cConn );
+    }
+
+    /**
+     * SETUP TABLE FOR CACHE
+     * @param cConn
+     */
+    private void setupTABLE( Connection cConn )
+    {
+        boolean newT = true;
+
+        StringBuffer createSql = new StringBuffer();
+        createSql.append( "CREATE CACHED TABLE " + databaseName );
+        createSql.append( "( " );
+        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
+        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
+        createSql.append( "ELEMENT               BINARY, " );
+        createSql.append( "CREATE_TIME           DATE, " );
+        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
+        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
+        createSql.append( "IS_ETERNAL            CHAR(1), " );
+        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+        createSql.append( ");" );
+
+        Statement sStatement = null;
+        try
+        {
+            sStatement = cConn.createStatement();
+        }
+        catch ( SQLException e )
+        {
+            e.printStackTrace();
+        }
+
+        try
+        {
+            sStatement.executeQuery( createSql.toString() );
+            sStatement.close();
+        }
+        catch ( SQLException e )
+        {
+            if ( e.toString().indexOf( "already exists" ) != -1 )
+            {
+                newT = false;
+            }
+            else
+            {
+                // TODO figure out if it exists prior to trying to create it.
+                // log.error( "Problem creating table.", e );
+                e.printStackTrace();
+            }
+        }
+
+        String setupData[] = { "create index iKEY on " + databaseName + " (CACHE_KEY, REGION)" };
+
+        if ( newT )
+        {
+            for ( int i = 1; i < setupData.length; i++ )
+            {
+                try
+                {
+                    sStatement.executeQuery( setupData[i] );
+                }
+                catch ( SQLException e )
+                {
+                    System.out.println( "Exception: " + e );
+                }
+            }
+        } // end ifnew
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheShrinkUnitTest.java Thu May 10 09:03:42 2007
@@ -1,267 +1,286 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.access.exception.CacheException;
-import org.apache.jcs.utils.timing.SleepUtil;
-
-/**
- * Runs basic tests for the JDBC disk cache.
- * 
- * @author Aaron Smuts
- * 
- */
-public class JDBCDiskCacheShrinkUnitTest
-    extends TestCase
-{
-
-    /**
-     * Test setup
-     * 
-     * @throws ClassNotFoundException
-     * @throws IllegalAccessException
-     * @throws InstantiationException
-     * @throws SQLException
-     */
-    public void setUp()
-        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
-    {
-        JCS.setConfigFilename( "/TestJDBCDiskCacheShrink.ccf" );
-
-        System.setProperty( "hsqldb.cache_scale", "8" );
-
-        String rafroot = "target";
-        Properties p = new Properties();
-        String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
-        String url = p.getProperty( "url", "jdbc:hsqldb:" );
-        String database = p.getProperty( "database", rafroot + "/cache_hsql_db" );
-        String user = p.getProperty( "user", "sa" );
-        String password = p.getProperty( "password", "" );
-
-        new org.hsqldb.jdbcDriver();
-        Class.forName( driver ).newInstance();
-        Connection cConn = DriverManager.getConnection( url + database, user, password );
-
-        setupTABLE( cConn );
-    }
-
-    /**
-     * Test the basic JDBC disk cache functionality with a hsql backing. Verify
-     * that items configured to expire after 1 second actually expire.
-     * 
-     * @throws Exception
-     */
-    public void testExpireInBackground()
-        throws Exception
-    {
-        String regionExpire = "expire1Second";
-        int items = 200;
-
-        JCS jcsExpire = JCS.getInstance( regionExpire );
-
-        System.out.println( "BEFORE PUT \n" + jcsExpire.getStats() );
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcsExpire.put( i + ":key", regionExpire + " data " + i );
-        }
-
-        System.out.println( jcsExpire.getStats() );
-
-        // the shrinker is supposed to run every second
-        SleepUtil.sleepAtLeast( 3000 );
-
-        System.out.println( jcsExpire.getStats() );
-
-        // Test that all items have been removed from the cache
-        for ( int i = 0; i <= items; i++ )
-        {
-            assertNull( "Removed key should be null: " + i + ":key", jcsExpire.get( i + ":key" ) );
-        }
-    }
-
-    /**
-     * Verify that those not scheduled to expire do not expire.
-     * 
-     * @throws CacheException
-     * @throws InterruptedException
-     */
-    public void testDidNotExpire()
-        throws CacheException, InterruptedException
-    {
-        String region = "expire100Second";
-        int items = 200;
-
-        JCS jcs = JCS.getInstance( region );
-
-        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        System.out.println( jcs.getStats() );
-
-        SleepUtil.sleepAtLeast( 1000 );
-
-        System.out.println( jcs.getStats() );
-
-        // Test that all items are in cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = (String) jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-
-        // Remove all the items
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.remove( i + ":key" );
-        }
-
-        // Verify removal
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
-        }
-    }
-
-    /**
-     * Verify that eternal trumps max life.
-     * 
-     * @throws CacheException
-     * @throws InterruptedException
-     */
-    public void testDidNotExpireEternal()
-        throws CacheException, InterruptedException
-    {
-        String region = "eternal";
-        int items = 200;
-
-        JCS jcs = JCS.getInstance( region );
-
-        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        System.out.println( jcs.getStats() );
-
-        SleepUtil.sleepAtLeast( 1000 );
-
-        System.out.println( jcs.getStats() );
-
-        // Test that all items are in cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = (String) jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-
-        // Remove all the items
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.remove( i + ":key" );
-        }
-
-        // Verify removal
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
-        }
-    }    
-    
-    /**
-     * SETUP TABLE FOR CACHE
-     * 
-     * @param cConn
-     */
-    void setupTABLE( Connection cConn )
-    {
-        boolean newT = true;
-
-        StringBuffer createSql = new StringBuffer();
-        createSql.append( "CREATE CACHED TABLE JCS_STORE_SHRINK " );
-        createSql.append( "( " );
-        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
-        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
-        createSql.append( "ELEMENT               BINARY, " );
-        createSql.append( "CREATE_TIME           DATE, " );
-        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
-        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
-        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );                
-        createSql.append( "IS_ETERNAL            CHAR(1), " );
-        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
-        createSql.append( ");" );
-
-        Statement sStatement = null;
-        try
-        {
-            sStatement = cConn.createStatement();
-        }
-        catch ( SQLException e )
-        {
-            e.printStackTrace();
-        }
-
-        try
-        {
-            sStatement.executeQuery( createSql.toString() );
-            sStatement.close();
-        }
-        catch ( SQLException e )
-        {
-            if ( e.toString().indexOf( "already exists" ) != -1 )
-            {
-                newT = false;
-            }
-            else
-            {
-                // TODO figure out if it exists prior to trying to create it.
-                // log.error( "Problem creating table.", e );
-                e.printStackTrace();
-            }
-        }
-
-        String setupData[] = { "create index iKEY on JCS_STORE_SHRINK (CACHE_KEY, REGION)" };
-
-        if ( newT )
-        {
-            for ( int i = 1; i < setupData.length; i++ )
-            {
-                try
-                {
-                    sStatement.executeQuery( setupData[i] );
-                }
-                catch ( SQLException e )
-                {
-                    System.out.println( "Exception: " + e );
-                }
-            }
-        } // end ifnew
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.access.exception.CacheException;
+import org.apache.jcs.utils.timing.SleepUtil;
+
+/**
+ * Runs basic tests for the JDBC disk cache.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class JDBCDiskCacheShrinkUnitTest
+    extends TestCase
+{
+
+    /**
+     * Test setup
+     *
+     * @throws ClassNotFoundException
+     * @throws IllegalAccessException
+     * @throws InstantiationException
+     * @throws SQLException
+     */
+    public void setUp()
+        throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException
+    {
+        JCS.setConfigFilename( "/TestJDBCDiskCacheShrink.ccf" );
+
+        System.setProperty( "hsqldb.cache_scale", "8" );
+
+        String rafroot = "target";
+        Properties p = new Properties();
+        String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
+        String url = p.getProperty( "url", "jdbc:hsqldb:" );
+        String database = p.getProperty( "database", rafroot + "/cache_hsql_db" );
+        String user = p.getProperty( "user", "sa" );
+        String password = p.getProperty( "password", "" );
+
+        new org.hsqldb.jdbcDriver();
+        Class.forName( driver ).newInstance();
+        Connection cConn = DriverManager.getConnection( url + database, user, password );
+
+        setupTABLE( cConn );
+    }
+
+    /**
+     * Test the basic JDBC disk cache functionality with a hsql backing. Verify
+     * that items configured to expire after 1 second actually expire.
+     *
+     * @throws Exception
+     */
+    public void testExpireInBackground()
+        throws Exception
+    {
+        String regionExpire = "expire1Second";
+        int items = 200;
+
+        JCS jcsExpire = JCS.getInstance( regionExpire );
+
+        System.out.println( "BEFORE PUT \n" + jcsExpire.getStats() );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcsExpire.put( i + ":key", regionExpire + " data " + i );
+        }
+
+        System.out.println( jcsExpire.getStats() );
+
+        // the shrinker is supposed to run every second
+        SleepUtil.sleepAtLeast( 3000 );
+
+        System.out.println( jcsExpire.getStats() );
+
+        // Test that all items have been removed from the cache
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key", jcsExpire.get( i + ":key" ) );
+        }
+    }
+
+    /**
+     * Verify that those not scheduled to expire do not expire.
+     *
+     * @throws CacheException
+     * @throws InterruptedException
+     */
+    public void testDidNotExpire()
+        throws CacheException, InterruptedException
+    {
+        String region = "expire100Second";
+        int items = 200;
+
+        JCS jcs = JCS.getInstance( region );
+
+        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        System.out.println( jcs.getStats() );
+
+        SleepUtil.sleepAtLeast( 1000 );
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = (String) jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Remove all the items
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.remove( i + ":key" );
+        }
+
+        // Verify removal
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
+        }
+    }
+
+    /**
+     * Verify that eternal trumps max life.
+     *
+     * @throws CacheException
+     * @throws InterruptedException
+     */
+    public void testDidNotExpireEternal()
+        throws CacheException, InterruptedException
+    {
+        String region = "eternal";
+        int items = 200;
+
+        JCS jcs = JCS.getInstance( region );
+
+        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        System.out.println( jcs.getStats() );
+
+        SleepUtil.sleepAtLeast( 1000 );
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = (String) jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Remove all the items
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.remove( i + ":key" );
+        }
+
+        // Verify removal
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key", jcs.get( i + ":key" ) );
+        }
+    }
+
+    /**
+     * SETUP TABLE FOR CACHE
+     *
+     * @param cConn
+     */
+    void setupTABLE( Connection cConn )
+    {
+        boolean newT = true;
+
+        StringBuffer createSql = new StringBuffer();
+        createSql.append( "CREATE CACHED TABLE JCS_STORE_SHRINK " );
+        createSql.append( "( " );
+        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
+        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
+        createSql.append( "ELEMENT               BINARY, " );
+        createSql.append( "CREATE_TIME           DATE, " );
+        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
+        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
+        createSql.append( "IS_ETERNAL            CHAR(1), " );
+        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+        createSql.append( ");" );
+
+        Statement sStatement = null;
+        try
+        {
+            sStatement = cConn.createStatement();
+        }
+        catch ( SQLException e )
+        {
+            e.printStackTrace();
+        }
+
+        try
+        {
+            sStatement.executeQuery( createSql.toString() );
+            sStatement.close();
+        }
+        catch ( SQLException e )
+        {
+            if ( e.toString().indexOf( "already exists" ) != -1 )
+            {
+                newT = false;
+            }
+            else
+            {
+                // TODO figure out if it exists prior to trying to create it.
+                // log.error( "Problem creating table.", e );
+                e.printStackTrace();
+            }
+        }
+
+        String setupData[] = { "create index iKEY on JCS_STORE_SHRINK (CACHE_KEY, REGION)" };
+
+        if ( newT )
+        {
+            for ( int i = 1; i < setupData.length; i++ )
+            {
+                try
+                {
+                    sStatement.executeQuery( setupData[i] );
+                }
+                catch ( SQLException e )
+                {
+                    System.out.println( "Exception: " + e );
+                }
+            }
+        } // end ifnew
+    }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.