You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by tv...@apache.org on 2007/05/10 18:04:27 UTC

svn commit: r536904 [27/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...

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/HugeQuantityBlockDiskCacheLoadTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/HugeQuantityBlockDiskCacheLoadTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/HugeQuantityBlockDiskCacheLoadTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/HugeQuantityBlockDiskCacheLoadTest.java Thu May 10 09:03:42 2007
@@ -1,121 +1,140 @@
-package org.apache.jcs.auxiliary.disk.block;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.utils.timing.ElapsedTimer;
-import org.apache.jcs.utils.timing.SleepUtil;
-
-/**
- * Put a few hundred thousand entries in the block disk cache.
- * <p.
- * @author Aaron Smuts
- * 
- */
-public class HugeQuantityBlockDiskCacheLoadTest
-    extends TestCase
-{
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestBlockDiskCacheHuge.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 testLargeNumberOfItems()
-        throws Exception
-    {
-        int items = 300000;
-        String region = "testCache1";
-
-        System.out.println( "--------------------------" );
-        long initialMemory = measureMemoryUse();
-        System.out.println( "Before getting JCS: " + initialMemory );
-
-        JCS jcs = JCS.getInstance( region );
-        jcs.clear();
-        
-        try
-        {
-            ElapsedTimer timer = new ElapsedTimer();            
-            System.out.println( "Start: " + measureMemoryUse() );
-
-            // Add items to cache
-            for ( int i = 0; i <= items; i++ )
-            {
-                jcs.put( i + ":key", region + " data " + i );
-            }
-
-            System.out.println( jcs.getStats() );
-            System.out.println( "--------------------------" );
-            System.out.println( "After put: " + measureMemoryUse() );
-
-            Thread.sleep( 5000 );
-            
-            System.out.println( jcs.getStats() );
-            System.out.println( "--------------------------" );
-            System.out.println( "After wait: " + measureMemoryUse() );
-            
-            for ( int i = 0; i < 10; i++ )
-            {
-                SleepUtil.sleepAtLeast( 3000 );
-                System.out.println( "--------------------------" );
-                System.out.println( "After sleep. " + timer.getElapsedTimeString() + " memory used = " + measureMemoryUse() );
-                System.out.println( jcs.getStats() );                
-            }
-
-            // Test that all items are in cache
-            System.out.println( "--------------------------" );
-            System.out.println( "Retrieving all." );
-            for ( int i = 0; i <= items; i++ )
-            {
-                //System.out.print(  "\033[s" );
-                String value = (String) jcs.get( i + ":key" );
-                if( i % 1000 == 0 )
-                {
-                    //System.out.print(  "\033[r" );
-                    System.out.println(  i + " ");
-                }
-                assertEquals( "Wrong value returned.", region + " data " + i, value );
-            }
-            long aftetGet = measureMemoryUse();
-            System.out.println( "After get: " + aftetGet + " diff = " + (aftetGet - initialMemory));
-        
-        }
-        finally
-        {
-            // dump the stats to the report
-            System.out.println( jcs.getStats() );
-            System.out.println( "--------------------------" );
-            long endMemory = measureMemoryUse();
-            System.out.println( "End: " + endMemory + " diff = " + (endMemory - initialMemory) );
-        }
-    }
-
-    /**
-     * Measure memory used by the VM.
-     * 
-     * @return
-     * @throws InterruptedException
-     */
-    protected long measureMemoryUse()
-        throws InterruptedException
-    {
-        System.gc();
-        Thread.sleep( 3000 );
-        System.gc();
-        return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
-    }
-}
+package org.apache.jcs.auxiliary.disk.block;
+
+/*
+ * 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.utils.timing.ElapsedTimer;
+import org.apache.jcs.utils.timing.SleepUtil;
+
+/**
+ * Put a few hundred thousand entries in the block disk cache.
+ * <p.
+ * @author Aaron Smuts
+ *
+ */
+public class HugeQuantityBlockDiskCacheLoadTest
+    extends TestCase
+{
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestBlockDiskCacheHuge.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 testLargeNumberOfItems()
+        throws Exception
+    {
+        int items = 300000;
+        String region = "testCache1";
+
+        System.out.println( "--------------------------" );
+        long initialMemory = measureMemoryUse();
+        System.out.println( "Before getting JCS: " + initialMemory );
+
+        JCS jcs = JCS.getInstance( region );
+        jcs.clear();
+
+        try
+        {
+            ElapsedTimer timer = new ElapsedTimer();
+            System.out.println( "Start: " + measureMemoryUse() );
+
+            // Add items to cache
+            for ( int i = 0; i <= items; i++ )
+            {
+                jcs.put( i + ":key", region + " data " + i );
+            }
+
+            System.out.println( jcs.getStats() );
+            System.out.println( "--------------------------" );
+            System.out.println( "After put: " + measureMemoryUse() );
+
+            Thread.sleep( 5000 );
+
+            System.out.println( jcs.getStats() );
+            System.out.println( "--------------------------" );
+            System.out.println( "After wait: " + measureMemoryUse() );
+
+            for ( int i = 0; i < 10; i++ )
+            {
+                SleepUtil.sleepAtLeast( 3000 );
+                System.out.println( "--------------------------" );
+                System.out.println( "After sleep. " + timer.getElapsedTimeString() + " memory used = " + measureMemoryUse() );
+                System.out.println( jcs.getStats() );
+            }
+
+            // Test that all items are in cache
+            System.out.println( "--------------------------" );
+            System.out.println( "Retrieving all." );
+            for ( int i = 0; i <= items; i++ )
+            {
+                //System.out.print(  "\033[s" );
+                String value = (String) jcs.get( i + ":key" );
+                if( i % 1000 == 0 )
+                {
+                    //System.out.print(  "\033[r" );
+                    System.out.println(  i + " ");
+                }
+                assertEquals( "Wrong value returned.", region + " data " + i, value );
+            }
+            long aftetGet = measureMemoryUse();
+            System.out.println( "After get: " + aftetGet + " diff = " + (aftetGet - initialMemory));
+
+        }
+        finally
+        {
+            // dump the stats to the report
+            System.out.println( jcs.getStats() );
+            System.out.println( "--------------------------" );
+            long endMemory = measureMemoryUse();
+            System.out.println( "End: " + endMemory + " diff = " + (endMemory - initialMemory) );
+        }
+    }
+
+    /**
+     * Measure memory used by the VM.
+     *
+     * @return
+     * @throws InterruptedException
+     */
+    protected long measureMemoryUse()
+        throws InterruptedException
+    {
+        System.gc();
+        Thread.sleep( 3000 );
+        System.gc();
+        return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/DiskTestObjectUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/DiskTestObjectUtil.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/DiskTestObjectUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/DiskTestObjectUtil.java Thu May 10 09:03:42 2007
@@ -1,131 +1,141 @@
-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 java.io.IOException;
-import java.util.Random;
-
-import org.apache.jcs.auxiliary.disk.DiskTestObject;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.utils.serialization.StandardSerializer;
-
-/**
- * Utility for dealing with test objects.
- * <p>
- * @author Aaron Smuts
- */
-public class DiskTestObjectUtil
-{
-    /**
-     * Total from the start to the endPostion.
-     * <p>
-     * @param testObjects
-     * @param endPosition
-     * @return size
-     * @throws IOException
-     */
-    public static long totalSize( DiskTestObject[] testObjects, int endPosition )
-        throws IOException
-    {
-        StandardSerializer serializer = new StandardSerializer();
-        long total = 0;
-        for ( int i = 0; i < endPosition; i++ )
-        {
-            int tileSize = serializer.serialize( testObjects[i] ).length + IndexedDisk.RECORD_HEADER;
-            total += tileSize;
-        }
-        return total;
-    }
-
-    /**
-     * Total from the start to the endPostion.
-     * <p>
-     * @param elements
-     * @param endPosition
-     * @return size
-     * @throws IOException
-     */
-    public static long totalSize( ICacheElement[] elements, int endPosition )
-        throws IOException
-    {
-        return totalSize( elements, 0, endPosition );
-    }
-
-    /**
-     * Total from the start to the endPostion.
-     * <p>
-     * @param elements
-     * @param startPosition 
-     * @param endPosition
-     * @return size
-     * @throws IOException
-     */
-    public static long totalSize( ICacheElement[] elements, int startPosition, int endPosition )
-        throws IOException
-    {
-        StandardSerializer serializer = new StandardSerializer();
-        long total = 0;
-        for ( int i = startPosition; i < endPosition; i++ )
-        {
-            int tileSize = serializer.serialize( elements[i] ).length + IndexedDisk.RECORD_HEADER;
-            total += tileSize;
-        }
-        return total;
-    }
-
-    /**
-     * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size.
-     * <p>
-     * @param numToCreate
-     * @param bytes
-     * @param cacheName
-     * @return ICacheElement[]
-     */
-    public static ICacheElement[] createCacheElementsWithTestObjects( int numToCreate, int bytes, String cacheName )
-    {
-        ICacheElement[] elements = new ICacheElement[numToCreate];
-        for ( int i = 0; i < numToCreate; i++ )
-        {
-            // 24 KB
-            int size = bytes * 1024;
-            DiskTestObject tile = new DiskTestObject( new Integer( i ), new byte[size] );
-
-            ICacheElement element = new CacheElement( cacheName, tile.id, tile );
-            elements[i] = element;
-        }
-        return elements;
-    }
-
-    /**
-     * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size.
-     * <p>
-     * @param numToCreate
-     * @param cacheName
-     * @return ICacheElement[]
-     */
-    public static ICacheElement[] createCacheElementsWithTestObjectsOfVariableSizes( int numToCreate, String cacheName )
-    {
-        ICacheElement[] elements = new ICacheElement[numToCreate];
-        Random random = new Random( 89 );
-        for ( int i = 0; i < numToCreate; i++ )
-        {
-            int bytes = random.nextInt( 20 );
-            // 4-24 KB
-            int size = ( bytes + 4 ) * 1024;
-            DiskTestObject tile = new DiskTestObject( new Integer( i ), new byte[size] );
-
-            ICacheElement element = new CacheElement( cacheName, tile.id, tile );
-            elements[i] = element;
-        }
-        return elements;
-    }
-
-}
+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.IOException;
+import java.util.Random;
+
+import org.apache.jcs.auxiliary.disk.DiskTestObject;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.utils.serialization.StandardSerializer;
+
+/**
+ * Utility for dealing with test objects.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class DiskTestObjectUtil
+{
+    /**
+     * Total from the start to the endPostion.
+     * <p>
+     * @param testObjects
+     * @param endPosition
+     * @return size
+     * @throws IOException
+     */
+    public static long totalSize( DiskTestObject[] testObjects, int endPosition )
+        throws IOException
+    {
+        StandardSerializer serializer = new StandardSerializer();
+        long total = 0;
+        for ( int i = 0; i < endPosition; i++ )
+        {
+            int tileSize = serializer.serialize( testObjects[i] ).length + IndexedDisk.RECORD_HEADER;
+            total += tileSize;
+        }
+        return total;
+    }
+
+    /**
+     * Total from the start to the endPostion.
+     * <p>
+     * @param elements
+     * @param endPosition
+     * @return size
+     * @throws IOException
+     */
+    public static long totalSize( ICacheElement[] elements, int endPosition )
+        throws IOException
+    {
+        return totalSize( elements, 0, endPosition );
+    }
+
+    /**
+     * Total from the start to the endPostion.
+     * <p>
+     * @param elements
+     * @param startPosition
+     * @param endPosition
+     * @return size
+     * @throws IOException
+     */
+    public static long totalSize( ICacheElement[] elements, int startPosition, int endPosition )
+        throws IOException
+    {
+        StandardSerializer serializer = new StandardSerializer();
+        long total = 0;
+        for ( int i = startPosition; i < endPosition; i++ )
+        {
+            int tileSize = serializer.serialize( elements[i] ).length + IndexedDisk.RECORD_HEADER;
+            total += tileSize;
+        }
+        return total;
+    }
+
+    /**
+     * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size.
+     * <p>
+     * @param numToCreate
+     * @param bytes
+     * @param cacheName
+     * @return ICacheElement[]
+     */
+    public static ICacheElement[] createCacheElementsWithTestObjects( int numToCreate, int bytes, String cacheName )
+    {
+        ICacheElement[] elements = new ICacheElement[numToCreate];
+        for ( int i = 0; i < numToCreate; i++ )
+        {
+            // 24 KB
+            int size = bytes * 1024;
+            DiskTestObject tile = new DiskTestObject( new Integer( i ), new byte[size] );
+
+            ICacheElement element = new CacheElement( cacheName, tile.id, tile );
+            elements[i] = element;
+        }
+        return elements;
+    }
+
+    /**
+     * Creates an array of ICacheElements with DiskTestObjects with payloads the byte size.
+     * <p>
+     * @param numToCreate
+     * @param cacheName
+     * @return ICacheElement[]
+     */
+    public static ICacheElement[] createCacheElementsWithTestObjectsOfVariableSizes( int numToCreate, String cacheName )
+    {
+        ICacheElement[] elements = new ICacheElement[numToCreate];
+        Random random = new Random( 89 );
+        for ( int i = 0; i < numToCreate; i++ )
+        {
+            int bytes = random.nextInt( 20 );
+            // 4-24 KB
+            int size = ( bytes + 4 ) * 1024;
+            DiskTestObject tile = new DiskTestObject( new Integer( i ), new byte[size] );
+
+            ICacheElement element = new CacheElement( cacheName, tile.id, tile );
+            elements[i] = element;
+        }
+        return elements;
+    }
+
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/HugeQuantityIndDiskCacheLoadTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/HugeQuantityIndDiskCacheLoadTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/HugeQuantityIndDiskCacheLoadTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/HugeQuantityIndDiskCacheLoadTest.java Thu May 10 09:03:42 2007
@@ -1,113 +1,132 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Put a few hundred thousand entries in the disk cache.
- * 
- * @author Aaron Smuts
- * 
- */
-public class HugeQuantityIndDiskCacheLoadTest
-    extends TestCase
-{
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCacheHuge.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 testLargeNumberOfItems()
-        throws Exception
-    {
-        int items = 300000;
-        String region = "testCache1";
-
-        JCS jcs = JCS.getInstance( region );
-
-        try
-        {
-
-            System.out.println( "Start: " + measureMemoryUse() );
-
-            // Add items to cache
-
-            for ( int i = 0; i <= items; i++ )
-            {
-                jcs.put( i + ":key", region + " data " + i );
-            }
-
-            System.out.println( jcs.getStats() );
-            System.out.println( "--------------------------" );
-            System.out.println( "After put: " + measureMemoryUse() );
-
-            Thread.sleep( 5000 );
-            
-            System.out.println( jcs.getStats() );
-            System.out.println( "--------------------------" );
-            System.out.println( "After wait: " + measureMemoryUse() );
-
-            // 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 );
-            }
-
-            System.out.println( "After get: " + measureMemoryUse() );
-
-            // // 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" ) );
-            // }
-
-        }
-        finally
-        {
-            // dump the stats to the report
-            System.out.println( jcs.getStats() );
-            System.out.println( "--------------------------" );
-            System.out.println( "End: " + measureMemoryUse() );
-        }
-    }
-
-    /**
-     * Measure memory used by the VM.
-     * 
-     * @return
-     * @throws InterruptedException
-     */
-    protected long measureMemoryUse()
-        throws InterruptedException
-    {
-        System.gc();
-        Thread.sleep( 3000 );
-        System.gc();
-        return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
-    }
-}
+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;
+
+/**
+ * Put a few hundred thousand entries in the disk cache.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class HugeQuantityIndDiskCacheLoadTest
+    extends TestCase
+{
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCacheHuge.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 testLargeNumberOfItems()
+        throws Exception
+    {
+        int items = 300000;
+        String region = "testCache1";
+
+        JCS jcs = JCS.getInstance( region );
+
+        try
+        {
+
+            System.out.println( "Start: " + measureMemoryUse() );
+
+            // Add items to cache
+
+            for ( int i = 0; i <= items; i++ )
+            {
+                jcs.put( i + ":key", region + " data " + i );
+            }
+
+            System.out.println( jcs.getStats() );
+            System.out.println( "--------------------------" );
+            System.out.println( "After put: " + measureMemoryUse() );
+
+            Thread.sleep( 5000 );
+
+            System.out.println( jcs.getStats() );
+            System.out.println( "--------------------------" );
+            System.out.println( "After wait: " + measureMemoryUse() );
+
+            // 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 );
+            }
+
+            System.out.println( "After get: " + measureMemoryUse() );
+
+            // // 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" ) );
+            // }
+
+        }
+        finally
+        {
+            // dump the stats to the report
+            System.out.println( jcs.getStats() );
+            System.out.println( "--------------------------" );
+            System.out.println( "End: " + measureMemoryUse() );
+        }
+    }
+
+    /**
+     * Measure memory used by the VM.
+     *
+     * @return
+     * @throws InterruptedException
+     */
+    protected long measureMemoryUse()
+        throws InterruptedException
+    {
+        System.gc();
+        Thread.sleep( 3000 );
+        System.gc();
+        return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java Thu May 10 09:03:42 2007
@@ -1,524 +1,543 @@
-package org.apache.jcs.auxiliary.disk.indexed;
-
-import java.io.IOException;
-
-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;
-import org.apache.jcs.engine.control.group.GroupAttrName;
-import org.apache.jcs.engine.control.group.GroupId;
-
-/**
- * Tests for common functionality.
- * <p>
- * @author Aaron Smuts
- */
-public class IndexDiskCacheUnitTest
-    extends TestCase
-{
-    /**
-     * Simply verify that we can put items in the disk cache and retrieve them.
-     */
-    public void testSimplePutAndGet()
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testSimplePutAndGet" );
-        cattr.setMaxKeySize( 1000 );
-        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        disk.doRemoveAll();
-
-        int cnt = 999;
-        for ( int i = 0; i < cnt; i++ )
-        {
-            IElementAttributes eAttr = new ElementAttributes();
-            eAttr.setIsSpool( true );
-            ICacheElement element = new CacheElement( "testSimplePutAndGet", "key:" + i, "data:" + i );
-            element.setElementAttributes( eAttr );
-            disk.doUpdate( element );
-        }
-
-        for ( int i = 0; i < cnt; i++ )
-        {
-            ICacheElement element = disk.doGet( "key:" + i );
-            assertNotNull( "Should have recevied an element.", element );
-            assertEquals( "Element is wrong.", "data:" + i, element.getVal() );
-        }
-
-        System.out.println( disk.getStats() );
-    }
-
-    /**
-     * Add some items to the disk cache and then remove them one by one.
-     */
-    public void testRemoveItems()
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRemoveItems" );
-        cattr.setMaxKeySize( 100 );
-        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
-        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( "testRemoveItems", "key:" + i, "data:" + i );
-            element.setElementAttributes( eAttr );
-            disk.doUpdate( element );
-        }
-
-        // remove each
-        for ( int i = 0; i < cnt; i++ )
-        {
-            disk.remove( "key:" + i );
-            ICacheElement element = disk.doGet( "key:" + i );
-            assertNull( "Should not have recevied an element.", element );
-        }
-    }
-
-    /**
-     * Verify that we don't override the largest item.
-     */
-    public void testRecycleBin()
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRemoveItems" );
-        cattr.setMaxRecycleBinSize( 2 );
-        cattr.setOptimizeAtRemoveCount( 7 );
-        cattr.setMaxKeySize( 5 );
-        cattr.setMaxPurgatorySize( 0 );
-        cattr.setDiskPath( "target/test-sandbox/BreakIndexTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        String[] test = { "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhhh", "iiiiiiiiii" };
-        String[] expect = { null, "bb", "ccc", null, null, "ffffff", null, "hhhhhhhhh", "iiiiiiiiii" };
-
-        System.out.println( "------------------------- testRecycleBin " );
-
-        for ( int i = 0; i < 6; i++ )
-        {
-            ICacheElement element = new CacheElement( "testRecycleBin", "key:" + test[i], test[i] );
-            System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
-            disk.doUpdate( element );
-        }
-
-        for ( int i = 3; i < 5; i++ )
-        {
-            System.out.println( "About to remove " + "key:" + test[i] + " i = " + i );
-            disk.remove( "key:" + test[i] );
-        }
-
-        // there was a bug where 7 would try to be put in the empty slot left by 4's removal, but it
-        // will not fit.
-        for ( int i = 7; i < 9; i++ )
-        {
-            ICacheElement element = new CacheElement( "testRecycleBin", "key:" + test[i], test[i] );
-            System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
-            disk.doUpdate( element );
-        }
-
-        try
-        {
-            for ( int i = 0; i < 9; i++ )
-            {
-                ICacheElement element = disk.get( "key:" + test[i] );
-                if ( element != null )
-                {
-                    System.out.println( "element = " + element.getVal() );
-                }
-                else
-                {
-                    System.out.println( "null --" + "key:" + test[i] );
-                }
-
-                String expectedValue = expect[i];
-                if ( expectedValue == null )
-                {
-                    assertNull( "Expected a null element", element );
-                }
-                else
-                {
-                    assertNotNull( "The element for key [" + "key:" + test[i] + "] should not be null. i = " + i,
-                                   element );
-                    assertEquals( "Elements contents do not match expected", element.getVal(), expectedValue );
-                }
-            }
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-            fail( "Should not get an exception: " + e.toString() );
-        }
-
-        disk.removeAll();
-    }
-
-    /**
-     * Verify that the overlap check returns true when there are no overlaps.
-     */
-    public void testCheckForDedOverlaps_noOverlap()
-    {
-        // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testCheckForDedOverlaps_noOverlap" );
-        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        int numDescriptors = 5;
-        int pos = 0;
-        IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors];
-        for ( int i = 0; i < numDescriptors; i++ )
-        {
-            IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor( pos, i * 2 );
-            pos = pos + ( i * 2 ) + IndexedDisk.RECORD_HEADER;
-            sortedDescriptors[i] = descriptor;
-        }
-
-        // DO WORK
-        boolean result = disk.checkForDedOverlaps( sortedDescriptors );
-
-        // VERIFY
-        assertTrue( "There should be no overlap. it should be ok", result );
-    }
-
-    /**
-     * Verify that the overlap check returns false when there are overlaps.
-     */
-    public void testCheckForDedOverlaps_overlaps()
-    {
-        // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testCheckForDedOverlaps_overlaps" );
-        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        int numDescriptors = 5;
-        int pos = 0;
-        IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors];
-        for ( int i = 0; i < numDescriptors; i++ )
-        {
-            IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor( pos, i * 2 );
-            // don't add the header + IndexedDisk.RECORD_HEADER;
-            pos = pos + ( i * 2 );
-            sortedDescriptors[i] = descriptor;
-        }
-
-        // DO WORK
-        boolean result = disk.checkForDedOverlaps( sortedDescriptors );
-
-        // VERIFY
-        assertFalse( "There should be overlaps. it should be not ok", result );
-    }
-
-    /**
-     * Verify that the file size is as expected.
-     * @throws IOException
-     * @throws InterruptedException
-     */
-    public void testFileSize()
-        throws IOException, InterruptedException
-    {
-        // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testFileSize" );
-        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        int numberToInsert = 20;
-        int bytes = 24;
-        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
-            .getCacheName() );
-
-        for ( int i = 0; i < elements.length; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        Thread.yield();
-        Thread.sleep( 100 );
-        Thread.yield();
-
-        long expectedSize = DiskTestObjectUtil.totalSize( elements, numberToInsert );
-        long resultSize = disk.getDataFileSize();
-
-        System.out.println( "testFileSize stats " + disk.getStats() );
-
-        assertEquals( "Wrong file size", expectedSize, resultSize );
-    }
-
-    /**
-     * Verify that items are added to the recyle bin on removal.
-     * <p>
-     * @throws IOException
-     * @throws InterruptedException
-     */
-    public void testRecyleBinSize()
-        throws IOException, InterruptedException
-    {
-        // SETUP
-        int numberToInsert = 20;
-
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRecyleBinSize" );
-        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
-        cattr.setMaxRecycleBinSize( numberToInsert );
-        cattr.setOptimizeAtRemoveCount( numberToInsert );
-        cattr.setMaxKeySize( numberToInsert * 2 );
-        cattr.setMaxPurgatorySize( numberToInsert );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        int bytes = 24;
-        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
-            .getCacheName() );
-
-        for ( int i = 0; i < elements.length; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        Thread.yield();
-        Thread.sleep( 100 );
-        Thread.yield();
-
-        // remove half
-        int numberToRemove = elements.length / 2;
-        for ( int i = 0; i < numberToRemove; i++ )
-        {
-            disk.doRemove( elements[i].getKey() );
-        }
-
-        // verify that the recyle bin has the correct amount.
-        assertEquals( "The recycle bin should have the number removed.", numberToRemove, disk.getRecyleBinSize() );
-    }
-
-    /**
-     * Verify that items of the same size use recyle bin spots. Setup the receyle bin by removing
-     * some items. Add some of the same size. Verify that the recyle count is the number added.
-     * <p>
-     * @throws IOException
-     * @throws InterruptedException
-     */
-    public void testRecyleBinUsage()
-        throws IOException, InterruptedException
-    {
-        // SETUP
-        int numberToInsert = 20;
-
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRecyleBinUsage" );
-        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
-        cattr.setMaxRecycleBinSize( numberToInsert );
-        cattr.setOptimizeAtRemoveCount( numberToInsert );
-        cattr.setMaxKeySize( numberToInsert * 2 );
-        cattr.setMaxPurgatorySize( numberToInsert );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        // we will reuse these
-        int bytes = 24;
-        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
-            .getCacheName() );
-
-        // Add some to the disk
-        for ( int i = 0; i < elements.length; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        Thread.yield();
-        Thread.sleep( 100 );
-        Thread.yield();
-
-        // remove half of those added
-        int numberToRemove = elements.length / 2;
-        for ( int i = 0; i < numberToRemove; i++ )
-        {
-            disk.doRemove( elements[i].getKey() );
-        }
-
-        // verify that the recyle bin has the correct amount.
-        assertEquals( "The recycle bin should have the number removed.", numberToRemove, disk.getRecyleBinSize() );
-
-        // add half as many as we removed. These should all use spots in the recycle bin.
-        int numberToAdd = numberToRemove / 2;
-        for ( int i = 0; i < numberToAdd; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        // verify that we used the correct number of spots
-        assertEquals( "The recycle bin should have the number removed." + disk.getStats(), numberToAdd, disk
-            .getRecyleCount() );
-    }
-
-    /**
-     * Verify that the data size is as expected after a remove and after a put that should use the
-     * spots.
-     * <p>
-     * @throws IOException
-     * @throws InterruptedException
-     */
-    public void testBytesFreeSize()
-        throws IOException, InterruptedException
-    {
-        // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testBytesFreeSize" );
-        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        int numberToInsert = 20;
-        int bytes = 24;
-        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
-            .getCacheName() );
-
-        for ( int i = 0; i < elements.length; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        Thread.yield();
-        Thread.sleep( 100 );
-        Thread.yield();
-
-        // remove half of those added
-        int numberToRemove = elements.length / 2;
-        for ( int i = 0; i < numberToRemove; i++ )
-        {
-            disk.doRemove( elements[i].getKey() );
-        }
-
-        long expectedSize = DiskTestObjectUtil.totalSize( elements, numberToRemove );
-        long resultSize = disk.getBytesFree();
-
-        System.out.println( "testBytesFreeSize stats " + disk.getStats() );
-
-        assertEquals( "Wrong bytes free size" + disk.getStats(), expectedSize, resultSize );
-
-        // add half as many as we removed. These should all use spots in the recycle bin.
-        int numberToAdd = numberToRemove / 2;
-        for ( int i = 0; i < numberToAdd; i++ )
-        {
-            disk.doUpdate( elements[i] );
-        }
-
-        long expectedSize2 = DiskTestObjectUtil.totalSize( elements, numberToAdd );
-        long resultSize2 = disk.getBytesFree();
-        assertEquals( "Wrong bytes free size" + disk.getStats(), expectedSize2, resultSize2 );
-    }
-
-    /**
-     * Add some items to the disk cache and then remove them one by one.
-     */
-    public void testRemove_PartialKey()
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRemove_PartialKey" );
-        cattr.setMaxKeySize( 100 );
-        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
-        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( "testRemove_PartialKey", i + ":key", "data:" + i );
-            element.setElementAttributes( eAttr );
-            disk.doUpdate( element );
-        }
-
-        // verif each
-        for ( int i = 0; i < cnt; i++ )
-        {
-            ICacheElement element = disk.doGet( i + ":key" );
-            assertNotNull( "Shoulds have recevied an element.", element );
-        }
-
-        // remove each
-        for ( int i = 0; i < cnt; i++ )
-        {
-            disk.remove( i + ":" );
-            ICacheElement element = disk.doGet( i + ":key" );
-            assertNull( "Should not have recevied an element.", element );
-        }
-    }
-
-    /**
-     * Verify that group members are removed if we call remove with a group.
-     */
-    public void testRemove_Group()
-    {
-        // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRemove_Group" );
-        cattr.setMaxKeySize( 100 );
-        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
-        IndexedDiskCache disk = new IndexedDiskCache( cattr );
-
-        disk.doRemoveAll();
-
-        String cacheName = "testRemove_Group_Region";
-        String groupName = "testRemove_Group";
-
-        int cnt = 25;
-        for ( int i = 0; i < cnt; i++ )
-        {
-            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
-
-            CacheElement element = new CacheElement( cacheName, groupAttrName, "data:" + i );
-
-            IElementAttributes eAttr = new ElementAttributes();
-            eAttr.setIsSpool( true );
-            element.setElementAttributes( eAttr );
-
-            disk.doUpdate( element );
-        }
-
-        // verify each
-        for ( int i = 0; i < cnt; i++ )
-        {
-            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
-            ICacheElement element = disk.doGet( groupAttrName );
-            assertNotNull( "Should have recevied an element.", element );
-        }
-
-        // DO WORK
-        // remove the group
-        GroupId gid = new GroupId( cacheName, groupName );
-        disk.remove( gid );
-
-        for ( int i = 0; i < cnt; i++ )
-        {
-            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
-            ICacheElement element = disk.doGet( groupAttrName );
-
-            // VERIFY
-            assertNull( "Should not have recevied an element.", element );
-        }
-
-    }
-
-    /**
-     * Internal method used for group functionality.
-     * <p>
-     * @param cacheName 
-     * @param group
-     * @param name
-     * @return GroupAttrName
-     */
-    private GroupAttrName getGroupAttrName( String cacheName, String group, Object name )
-    {
-        GroupId gid = new GroupId( cacheName, group );
-        return new GroupAttrName( gid, name );
-    }
-}
+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.IOException;
+
+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;
+import org.apache.jcs.engine.control.group.GroupAttrName;
+import org.apache.jcs.engine.control.group.GroupId;
+
+/**
+ * Tests for common functionality.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class IndexDiskCacheUnitTest
+    extends TestCase
+{
+    /**
+     * Simply verify that we can put items in the disk cache and retrieve them.
+     */
+    public void testSimplePutAndGet()
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testSimplePutAndGet" );
+        cattr.setMaxKeySize( 1000 );
+        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 999;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( "testSimplePutAndGet", "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "Should have recevied an element.", element );
+            assertEquals( "Element is wrong.", "data:" + i, element.getVal() );
+        }
+
+        System.out.println( disk.getStats() );
+    }
+
+    /**
+     * Add some items to the disk cache and then remove them one by one.
+     */
+    public void testRemoveItems()
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRemoveItems" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+        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( "testRemoveItems", "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        // remove each
+        for ( int i = 0; i < cnt; i++ )
+        {
+            disk.remove( "key:" + i );
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNull( "Should not have recevied an element.", element );
+        }
+    }
+
+    /**
+     * Verify that we don't override the largest item.
+     */
+    public void testRecycleBin()
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRemoveItems" );
+        cattr.setMaxRecycleBinSize( 2 );
+        cattr.setOptimizeAtRemoveCount( 7 );
+        cattr.setMaxKeySize( 5 );
+        cattr.setMaxPurgatorySize( 0 );
+        cattr.setDiskPath( "target/test-sandbox/BreakIndexTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        String[] test = { "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhhh", "iiiiiiiiii" };
+        String[] expect = { null, "bb", "ccc", null, null, "ffffff", null, "hhhhhhhhh", "iiiiiiiiii" };
+
+        System.out.println( "------------------------- testRecycleBin " );
+
+        for ( int i = 0; i < 6; i++ )
+        {
+            ICacheElement element = new CacheElement( "testRecycleBin", "key:" + test[i], test[i] );
+            System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+            disk.doUpdate( element );
+        }
+
+        for ( int i = 3; i < 5; i++ )
+        {
+            System.out.println( "About to remove " + "key:" + test[i] + " i = " + i );
+            disk.remove( "key:" + test[i] );
+        }
+
+        // there was a bug where 7 would try to be put in the empty slot left by 4's removal, but it
+        // will not fit.
+        for ( int i = 7; i < 9; i++ )
+        {
+            ICacheElement element = new CacheElement( "testRecycleBin", "key:" + test[i], test[i] );
+            System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+            disk.doUpdate( element );
+        }
+
+        try
+        {
+            for ( int i = 0; i < 9; i++ )
+            {
+                ICacheElement element = disk.get( "key:" + test[i] );
+                if ( element != null )
+                {
+                    System.out.println( "element = " + element.getVal() );
+                }
+                else
+                {
+                    System.out.println( "null --" + "key:" + test[i] );
+                }
+
+                String expectedValue = expect[i];
+                if ( expectedValue == null )
+                {
+                    assertNull( "Expected a null element", element );
+                }
+                else
+                {
+                    assertNotNull( "The element for key [" + "key:" + test[i] + "] should not be null. i = " + i,
+                                   element );
+                    assertEquals( "Elements contents do not match expected", element.getVal(), expectedValue );
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+            fail( "Should not get an exception: " + e.toString() );
+        }
+
+        disk.removeAll();
+    }
+
+    /**
+     * Verify that the overlap check returns true when there are no overlaps.
+     */
+    public void testCheckForDedOverlaps_noOverlap()
+    {
+        // SETUP
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testCheckForDedOverlaps_noOverlap" );
+        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        int numDescriptors = 5;
+        int pos = 0;
+        IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors];
+        for ( int i = 0; i < numDescriptors; i++ )
+        {
+            IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor( pos, i * 2 );
+            pos = pos + ( i * 2 ) + IndexedDisk.RECORD_HEADER;
+            sortedDescriptors[i] = descriptor;
+        }
+
+        // DO WORK
+        boolean result = disk.checkForDedOverlaps( sortedDescriptors );
+
+        // VERIFY
+        assertTrue( "There should be no overlap. it should be ok", result );
+    }
+
+    /**
+     * Verify that the overlap check returns false when there are overlaps.
+     */
+    public void testCheckForDedOverlaps_overlaps()
+    {
+        // SETUP
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testCheckForDedOverlaps_overlaps" );
+        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        int numDescriptors = 5;
+        int pos = 0;
+        IndexedDiskElementDescriptor[] sortedDescriptors = new IndexedDiskElementDescriptor[numDescriptors];
+        for ( int i = 0; i < numDescriptors; i++ )
+        {
+            IndexedDiskElementDescriptor descriptor = new IndexedDiskElementDescriptor( pos, i * 2 );
+            // don't add the header + IndexedDisk.RECORD_HEADER;
+            pos = pos + ( i * 2 );
+            sortedDescriptors[i] = descriptor;
+        }
+
+        // DO WORK
+        boolean result = disk.checkForDedOverlaps( sortedDescriptors );
+
+        // VERIFY
+        assertFalse( "There should be overlaps. it should be not ok", result );
+    }
+
+    /**
+     * Verify that the file size is as expected.
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    public void testFileSize()
+        throws IOException, InterruptedException
+    {
+        // SETUP
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testFileSize" );
+        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        int numberToInsert = 20;
+        int bytes = 24;
+        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
+            .getCacheName() );
+
+        for ( int i = 0; i < elements.length; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        Thread.yield();
+        Thread.sleep( 100 );
+        Thread.yield();
+
+        long expectedSize = DiskTestObjectUtil.totalSize( elements, numberToInsert );
+        long resultSize = disk.getDataFileSize();
+
+        System.out.println( "testFileSize stats " + disk.getStats() );
+
+        assertEquals( "Wrong file size", expectedSize, resultSize );
+    }
+
+    /**
+     * Verify that items are added to the recyle bin on removal.
+     * <p>
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    public void testRecyleBinSize()
+        throws IOException, InterruptedException
+    {
+        // SETUP
+        int numberToInsert = 20;
+
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRecyleBinSize" );
+        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
+        cattr.setMaxRecycleBinSize( numberToInsert );
+        cattr.setOptimizeAtRemoveCount( numberToInsert );
+        cattr.setMaxKeySize( numberToInsert * 2 );
+        cattr.setMaxPurgatorySize( numberToInsert );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        int bytes = 24;
+        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
+            .getCacheName() );
+
+        for ( int i = 0; i < elements.length; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        Thread.yield();
+        Thread.sleep( 100 );
+        Thread.yield();
+
+        // remove half
+        int numberToRemove = elements.length / 2;
+        for ( int i = 0; i < numberToRemove; i++ )
+        {
+            disk.doRemove( elements[i].getKey() );
+        }
+
+        // verify that the recyle bin has the correct amount.
+        assertEquals( "The recycle bin should have the number removed.", numberToRemove, disk.getRecyleBinSize() );
+    }
+
+    /**
+     * Verify that items of the same size use recyle bin spots. Setup the receyle bin by removing
+     * some items. Add some of the same size. Verify that the recyle count is the number added.
+     * <p>
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    public void testRecyleBinUsage()
+        throws IOException, InterruptedException
+    {
+        // SETUP
+        int numberToInsert = 20;
+
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRecyleBinUsage" );
+        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
+        cattr.setMaxRecycleBinSize( numberToInsert );
+        cattr.setOptimizeAtRemoveCount( numberToInsert );
+        cattr.setMaxKeySize( numberToInsert * 2 );
+        cattr.setMaxPurgatorySize( numberToInsert );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        // we will reuse these
+        int bytes = 24;
+        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
+            .getCacheName() );
+
+        // Add some to the disk
+        for ( int i = 0; i < elements.length; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        Thread.yield();
+        Thread.sleep( 100 );
+        Thread.yield();
+
+        // remove half of those added
+        int numberToRemove = elements.length / 2;
+        for ( int i = 0; i < numberToRemove; i++ )
+        {
+            disk.doRemove( elements[i].getKey() );
+        }
+
+        // verify that the recyle bin has the correct amount.
+        assertEquals( "The recycle bin should have the number removed.", numberToRemove, disk.getRecyleBinSize() );
+
+        // add half as many as we removed. These should all use spots in the recycle bin.
+        int numberToAdd = numberToRemove / 2;
+        for ( int i = 0; i < numberToAdd; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        // verify that we used the correct number of spots
+        assertEquals( "The recycle bin should have the number removed." + disk.getStats(), numberToAdd, disk
+            .getRecyleCount() );
+    }
+
+    /**
+     * Verify that the data size is as expected after a remove and after a put that should use the
+     * spots.
+     * <p>
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    public void testBytesFreeSize()
+        throws IOException, InterruptedException
+    {
+        // SETUP
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testBytesFreeSize" );
+        cattr.setDiskPath( "target/test-sandbox/UnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        int numberToInsert = 20;
+        int bytes = 24;
+        ICacheElement[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects( numberToInsert, bytes, cattr
+            .getCacheName() );
+
+        for ( int i = 0; i < elements.length; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        Thread.yield();
+        Thread.sleep( 100 );
+        Thread.yield();
+
+        // remove half of those added
+        int numberToRemove = elements.length / 2;
+        for ( int i = 0; i < numberToRemove; i++ )
+        {
+            disk.doRemove( elements[i].getKey() );
+        }
+
+        long expectedSize = DiskTestObjectUtil.totalSize( elements, numberToRemove );
+        long resultSize = disk.getBytesFree();
+
+        System.out.println( "testBytesFreeSize stats " + disk.getStats() );
+
+        assertEquals( "Wrong bytes free size" + disk.getStats(), expectedSize, resultSize );
+
+        // add half as many as we removed. These should all use spots in the recycle bin.
+        int numberToAdd = numberToRemove / 2;
+        for ( int i = 0; i < numberToAdd; i++ )
+        {
+            disk.doUpdate( elements[i] );
+        }
+
+        long expectedSize2 = DiskTestObjectUtil.totalSize( elements, numberToAdd );
+        long resultSize2 = disk.getBytesFree();
+        assertEquals( "Wrong bytes free size" + disk.getStats(), expectedSize2, resultSize2 );
+    }
+
+    /**
+     * Add some items to the disk cache and then remove them one by one.
+     */
+    public void testRemove_PartialKey()
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRemove_PartialKey" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+        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( "testRemove_PartialKey", i + ":key", "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        // verif each
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( i + ":key" );
+            assertNotNull( "Shoulds have recevied an element.", element );
+        }
+
+        // remove each
+        for ( int i = 0; i < cnt; i++ )
+        {
+            disk.remove( i + ":" );
+            ICacheElement element = disk.doGet( i + ":key" );
+            assertNull( "Should not have recevied an element.", element );
+        }
+    }
+
+    /**
+     * Verify that group members are removed if we call remove with a group.
+     */
+    public void testRemove_Group()
+    {
+        // SETUP
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRemove_Group" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        String cacheName = "testRemove_Group_Region";
+        String groupName = "testRemove_Group";
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
+
+            CacheElement element = new CacheElement( cacheName, groupAttrName, "data:" + i );
+
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            element.setElementAttributes( eAttr );
+
+            disk.doUpdate( element );
+        }
+
+        // verify each
+        for ( int i = 0; i < cnt; i++ )
+        {
+            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
+            ICacheElement element = disk.doGet( groupAttrName );
+            assertNotNull( "Should have recevied an element.", element );
+        }
+
+        // DO WORK
+        // remove the group
+        GroupId gid = new GroupId( cacheName, groupName );
+        disk.remove( gid );
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            GroupAttrName groupAttrName = getGroupAttrName( cacheName, groupName, i + ":key" );
+            ICacheElement element = disk.doGet( groupAttrName );
+
+            // VERIFY
+            assertNull( "Should not have recevied an element.", element );
+        }
+
+    }
+
+    /**
+     * Internal method used for group functionality.
+     * <p>
+     * @param cacheName
+     * @param group
+     * @param name
+     * @return GroupAttrName
+     */
+    private GroupAttrName getGroupAttrName( String cacheName, String group, Object name )
+    {
+        GroupId gid = new GroupId( cacheName, group );
+        return new GroupAttrName( gid, name );
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java Thu May 10 09:03:42 2007
@@ -1,138 +1,141 @@
-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;
-import org.apache.jcs.engine.control.CompositeCacheManager;
-
-/**
- * Test which exercises the indexed disk cache. Runs three threads against the
- * same region.
- * 
- * @version $Id: TestDiskCacheConcurrentForDeadLock.java,v 1.2 2005/02/01
- *          00:01:59 asmuts Exp $
- */
-public class IndexedDiskCacheConcurrentNoDeadLockUnitTest
-    extends TestCase
-{
-    /**
-     * Constructor for the TestDiskCache object.
-     * 
-     * @param testName
-     */
-    public IndexedDiskCacheConcurrentNoDeadLockUnitTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Main method passes this test to the text test runner.
-     * 
-     * @param args
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { IndexedDiskCacheConcurrentNoDeadLockUnitTest.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 IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache1" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 0, 200, 1 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache2" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 10000, 50000, 2 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache3" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 10000, 50000, 3 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache4" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 10000, 50000, 4 );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache5" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion4", 10000, 50000, 5 );
-            }
-        } );
-
-        return suite;
-    }
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
-    }
-
-    /**
-     * Test tearDown. Dispose of the cache.
-     */
-    public void tearDown()
-    {
-        try
-        {
-            CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
-            cacheMgr.shutDown();
-        }
-        catch ( Exception e )
-        {
-            // log.error(e);
-        }
-    }
-
-}
+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;
+import org.apache.jcs.engine.control.CompositeCacheManager;
+
+/**
+ * Test which exercises the indexed disk cache. Runs three threads against the
+ * same region.
+ *
+ * @version $Id: TestDiskCacheConcurrentForDeadLock.java,v 1.2 2005/02/01
+ *          00:01:59 asmuts Exp $
+ */
+public class IndexedDiskCacheConcurrentNoDeadLockUnitTest
+    extends TestCase
+{
+    /**
+     * Constructor for the TestDiskCache object.
+     *
+     * @param testName
+     */
+    public IndexedDiskCacheConcurrentNoDeadLockUnitTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * Main method passes this test to the text test runner.
+     *
+     * @param args
+     */
+    public static void main( String args[] )
+    {
+        String[] testCaseName = { IndexedDiskCacheConcurrentNoDeadLockUnitTest.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 IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache1" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 0, 200, 1 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache2" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 10000, 50000, 2 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache3" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 10000, 50000, 3 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache4" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 10000, 50000, 4 );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheRandomConcurrentTestUtil( "testIndexedDiskCache5" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion4", 10000, 50000, 5 );
+            }
+        } );
+
+        return suite;
+    }
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCacheCon.ccf" );
+    }
+
+    /**
+     * Test tearDown. Dispose of the cache.
+     */
+    public void tearDown()
+    {
+        try
+        {
+            CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
+            cacheMgr.shutDown();
+        }
+        catch ( Exception e )
+        {
+            // log.error(e);
+        }
+    }
+
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java Thu May 10 09:03:42 2007
@@ -1,208 +1,211 @@
-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.
- * 
- * @version $Id: TestDiskCache.java 224346 2005-06-04 02:01:59Z asmuts $
- */
-public class IndexedDiskCacheConcurrentUnitTest
-    extends TestCase
-{
-    /**
-     * Number of items to cache, twice the configured maxObjects for the memory
-     * cache regions.
-     */
-    private static int items = 200;
-
-    /**
-     * Constructor for the TestDiskCache object.
-     * 
-     * @param testName
-     */
-    public IndexedDiskCacheConcurrentUnitTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Main method passes this test to the text test runner.
-     * 
-     * @param args
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { IndexedDiskCacheConcurrentUnitTest.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 IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache1" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion1" );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache2" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion2" );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache3" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion3" );
-            }
-        } );
-
-        suite.addTest( new IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache4" )
-        {
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegionInRange( "indexedRegion3", 300, 600 );
-            }
-        } );
-
-        return suite;
-    }
-
-    /**
-     * Test setup
-     */
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestDiskCache.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
-        // another thread may have inserted since
-        for ( int i = 0; i <= items; i++ )
-        {
-            assertNull( "Removed key should be null: " + i + ":key" + "\n stats " + jcs.getStats(), jcs
-                .get( i + ":key" ) );
-        }
-    }
-
-    /**
-     * 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 runTestForRegionInRange( 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 );
-        }
-
-        // Remove all the items
-        for ( int i = start; i <= end; i++ )
-        {
-            jcs.remove( i + ":key" );
-        }
-
-        System.out.println( jcs.getStats() );
-
-        // Verify removal
-        // another thread may have inserted since
-        for ( int i = start; i <= end; i++ )
-        {
-            assertNull( "Removed key should be null: " + i + ":key " + "\n stats " + jcs.getStats(), 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. This one uses three different
+ * regions for thre threads.
+ *
+ * @version $Id: TestDiskCache.java 224346 2005-06-04 02:01:59Z asmuts $
+ */
+public class IndexedDiskCacheConcurrentUnitTest
+    extends TestCase
+{
+    /**
+     * Number of items to cache, twice the configured maxObjects for the memory
+     * cache regions.
+     */
+    private static int items = 200;
+
+    /**
+     * Constructor for the TestDiskCache object.
+     *
+     * @param testName
+     */
+    public IndexedDiskCacheConcurrentUnitTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * Main method passes this test to the text test runner.
+     *
+     * @param args
+     */
+    public static void main( String args[] )
+    {
+        String[] testCaseName = { IndexedDiskCacheConcurrentUnitTest.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 IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache1" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion1" );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache2" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion2" );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache3" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion3" );
+            }
+        } );
+
+        suite.addTest( new IndexedDiskCacheConcurrentUnitTest( "testIndexedDiskCache4" )
+        {
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegionInRange( "indexedRegion3", 300, 600 );
+            }
+        } );
+
+        return suite;
+    }
+
+    /**
+     * Test setup
+     */
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestDiskCache.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
+        // another thread may have inserted since
+        for ( int i = 0; i <= items; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key" + "\n stats " + jcs.getStats(), jcs
+                .get( i + ":key" ) );
+        }
+    }
+
+    /**
+     * 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 runTestForRegionInRange( 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 );
+        }
+
+        // Remove all the items
+        for ( int i = start; i <= end; i++ )
+        {
+            jcs.remove( i + ":key" );
+        }
+
+        System.out.println( jcs.getStats() );
+
+        // Verify removal
+        // another thread may have inserted since
+        for ( int i = start; i <= end; i++ )
+        {
+            assertNull( "Removed key should be null: " + i + ":key " + "\n stats " + jcs.getStats(), jcs.get( i
+                + ":key" ) );
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org