commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1570993 [18/24] - in /commons/proper/jcs/trunk/src: assembly/ changes/ conf/ java/org/apache/commons/jcs/access/ java/org/apache/commons/jcs/access/exception/ java/org/apache/commons/jcs/admin/ java/org/apache/commons/jcs/auxiliary/ java/o...
Date Sun, 23 Feb 2014 10:37:52 GMT
Modified: commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java Sun Feb 23 10:37:48 2014
@@ -1,195 +1,195 @@
-package org.apache.commons.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.util.HashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.jcs.engine.control.MockCompositeCacheManager;
-
-/**
- * Runs basic tests for the JDBC disk cache.
- *<p>
- * @author Aaron Smuts
- */
-public class JDBCDiskCacheUnitTest
-    extends TestCase
-{
-    /** Test setup */
-    @Override
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestJDBCDiskCache.ccf" );
-    }
-
-    /**
-     * Test the basic JDBC disk cache functionality with a hsql backing.
-     * @throws Exception
-     */
-    public void testSimpleJDBCPutGetWithHSQL()
-        throws Exception
-    {
-        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 );
-
-        HsqlSetupTableUtil.setupTABLE( cConn, "JCS_STORE2" );
-
-        runTestForRegion( "testCache1", 200 );
-    }
-
-    /**
-     * 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.
-     * <p>
-     * @param region Name of the region to access
-     * @param items
-     * @exception Exception If an error occurs
-     */
-    public void runTestForRegion( String region, int items )
-        throws Exception
-    {
-        CacheAccess<String, String> 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() );
-
-        Thread.sleep( 1000 );
-
-        System.out.println( jcs.getStats() );
-
-        // Test that all items are in cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-
-        // Test that getElements returns all the expected values
-        Set<String> keys = new HashSet<String>();
-        for ( int i = 0; i <= items; i++ )
-        {
-            keys.add( i + ":key" );
-        }
-
-        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
-        for ( int i = 0; i <= items; i++ )
-        {
-            ICacheElement<String, String> element = elements.get( i + ":key" );
-            assertNotNull( "element " + i + ":key is missing", element );
-            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
-        }
-
-        // 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" ) );
-        }
-    }
-
-    /**
-     * Verfiy that it uses the pool access manager config.
-     * <p>
-     * @throws Exception
-     */
-    public void testInitializePoolAccess_withPoolName()
-        throws Exception
-    {
-        // SETUP
-        String poolName = "testInitializePoolAccess_withPoolName";
-
-        String url = "jdbc:hsqldb:";
-        String userName = "sa";
-        String password = "";
-        int maxActive = 10;
-        String driverClassName = "org.hsqldb.jdbcDriver";
-
-        Properties props = new Properties();
-        String prefix = JDBCDiskCachePoolAccessManager.POOL_CONFIGURATION_PREFIX + poolName
-            + JDBCDiskCachePoolAccessManager.ATTRIBUTE_PREFIX;
-        props.put( prefix + ".url", url );
-        props.put( prefix + ".userName", userName );
-        props.put( prefix + ".password", password );
-        props.put( prefix + ".maxActive", String.valueOf( maxActive ) );
-        props.put( prefix + ".driverClassName", driverClassName );
-
-        JDBCDiskCacheAttributes cattr = new JDBCDiskCacheAttributes();
-        cattr.setConnectionPoolName( poolName );
-
-        TableState tableState = new TableState( "JCSTESTTABLE_InitializePoolAccess" );
-        MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
-        compositeCacheManager.setConfigurationProperties( props );
-
-        JDBCDiskCache<String, String> diskCache = new JDBCDiskCache<String, String>( cattr, tableState, compositeCacheManager );
-
-        System.setProperty( "hsqldb.cache_scale", "8" );
-
-        String rafroot = "target";
-        String database = rafroot + "/cache_hsql_db";
-
-        new org.hsqldb.jdbcDriver();
-        Class.forName( driverClassName ).newInstance();
-        Connection cConn = DriverManager.getConnection( url + database, userName, password );
-
-        HsqlSetupTableUtil.setupTABLE( cConn, "JCSTESTTABLE_InitializePoolAccess" );
-
-        // DO WORK
-        JDBCDiskCachePoolAccess result = diskCache.initializePoolAccess( cattr, compositeCacheManager );
-
-        // VEIFY
-        assertNotNull( "Should have an access class", result );
-        assertEquals( "wrong name", poolName, result.getPoolName() );
-    }
-}
+package org.apache.commons.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.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.jcs.engine.control.MockCompositeCacheManager;
+
+/**
+ * Runs basic tests for the JDBC disk cache.
+ *<p>
+ * @author Aaron Smuts
+ */
+public class JDBCDiskCacheUnitTest
+    extends TestCase
+{
+    /** Test setup */
+    @Override
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestJDBCDiskCache.ccf" );
+    }
+
+    /**
+     * Test the basic JDBC disk cache functionality with a hsql backing.
+     * @throws Exception
+     */
+    public void testSimpleJDBCPutGetWithHSQL()
+        throws Exception
+    {
+        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 );
+
+        HsqlSetupTableUtil.setupTABLE( cConn, "JCS_STORE2" );
+
+        runTestForRegion( "testCache1", 200 );
+    }
+
+    /**
+     * 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.
+     * <p>
+     * @param region Name of the region to access
+     * @param items
+     * @exception Exception If an error occurs
+     */
+    public void runTestForRegion( String region, int items )
+        throws Exception
+    {
+        CacheAccess<String, String> 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() );
+
+        Thread.sleep( 1000 );
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Test that getElements returns all the expected values
+        Set<String> keys = new HashSet<String>();
+        for ( int i = 0; i <= items; i++ )
+        {
+            keys.add( i + ":key" );
+        }
+
+        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
+        for ( int i = 0; i <= items; i++ )
+        {
+            ICacheElement<String, String> element = elements.get( i + ":key" );
+            assertNotNull( "element " + i + ":key is missing", element );
+            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
+        }
+
+        // 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" ) );
+        }
+    }
+
+    /**
+     * Verfiy that it uses the pool access manager config.
+     * <p>
+     * @throws Exception
+     */
+    public void testInitializePoolAccess_withPoolName()
+        throws Exception
+    {
+        // SETUP
+        String poolName = "testInitializePoolAccess_withPoolName";
+
+        String url = "jdbc:hsqldb:";
+        String userName = "sa";
+        String password = "";
+        int maxActive = 10;
+        String driverClassName = "org.hsqldb.jdbcDriver";
+
+        Properties props = new Properties();
+        String prefix = JDBCDiskCachePoolAccessManager.POOL_CONFIGURATION_PREFIX + poolName
+            + JDBCDiskCachePoolAccessManager.ATTRIBUTE_PREFIX;
+        props.put( prefix + ".url", url );
+        props.put( prefix + ".userName", userName );
+        props.put( prefix + ".password", password );
+        props.put( prefix + ".maxActive", String.valueOf( maxActive ) );
+        props.put( prefix + ".driverClassName", driverClassName );
+
+        JDBCDiskCacheAttributes cattr = new JDBCDiskCacheAttributes();
+        cattr.setConnectionPoolName( poolName );
+
+        TableState tableState = new TableState( "JCSTESTTABLE_InitializePoolAccess" );
+        MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
+        compositeCacheManager.setConfigurationProperties( props );
+
+        JDBCDiskCache<String, String> diskCache = new JDBCDiskCache<String, String>( cattr, tableState, compositeCacheManager );
+
+        System.setProperty( "hsqldb.cache_scale", "8" );
+
+        String rafroot = "target";
+        String database = rafroot + "/cache_hsql_db";
+
+        new org.hsqldb.jdbcDriver();
+        Class.forName( driverClassName ).newInstance();
+        Connection cConn = DriverManager.getConnection( url + database, userName, password );
+
+        HsqlSetupTableUtil.setupTABLE( cConn, "JCSTESTTABLE_InitializePoolAccess" );
+
+        // DO WORK
+        JDBCDiskCachePoolAccess result = diskCache.initializePoolAccess( cattr, compositeCacheManager );
+
+        // VEIFY
+        assertNotNull( "Should have an access class", result );
+        assertEquals( "wrong name", poolName, result.getPoolName() );
+    }
+}

Modified: commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java Sun Feb 23 10:37:48 2014
@@ -1,176 +1,176 @@
-package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
-
-/*
- * 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.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import junit.extensions.ActiveTestSuite;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-
-/**
- * Test which exercises the indexed disk cache. This one uses three different regions for thre
- * threads.
- */
-public class HSQLDiskCacheConcurrentUnitTest
-    extends TestCase
-{
-    /**
-     * Number of items to cache, twice the configured maxObjects for the memory cache regions.
-     */
-    private static int items = 100;
-
-    /**
-     * Constructor for the TestDiskCache object.
-     * @param testName
-     */
-    public HSQLDiskCacheConcurrentUnitTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Main method passes this test to the text test runner.
-     * <p>
-     * @param args
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { HSQLDiskCacheConcurrentUnitTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
-    }
-
-    /**
-     * A unit test suite for JUnit. Uses ActiveTestSuite to run multiple tests concurrently.
-     * <p>
-     * @return The test suite
-     */
-    public static Test suite()
-    {
-        ActiveTestSuite suite = new ActiveTestSuite();
-
-        suite.addTest( new HSQLDiskCacheConcurrentUnitTest( "testHSQLDiskCache1" )
-        {
-            @Override
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion1" );
-            }
-        } );
-
-        suite.addTest( new HSQLDiskCacheConcurrentUnitTest( "testHSQLDiskCache2" )
-        {
-            @Override
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion2" );
-            }
-        } );
-
-        suite.addTest( new HSQLDiskCacheConcurrentUnitTest( "testHSQLDiskCache3" )
-        {
-            @Override
-            public void runTest()
-                throws Exception
-            {
-                this.runTestForRegion( "indexedRegion3" );
-            }
-        } );
-
-        return suite;
-    }
-
-    /**
-     * Test setup
-     */
-    @Override
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestHSQLDiskCacheConcurrent.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.
-     * <p>
-     * @param region Name of the region to access
-     * @exception Exception If an error occurs
-     */
-    public void runTestForRegion( String region )
-        throws Exception
-    {
-        CacheAccess<String, String> jcs = JCS.getInstance( region );
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        System.out.println( jcs.getStats() );
-
-        // Test that all items are in cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-
-        // Test that getElements returns all the expected values
-        Set<String> keys = new HashSet<String>();
-        for ( int i = 0; i <= items; i++ )
-        {
-            keys.add( i + ":key" );
-        }
-
-        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
-        for ( int i = 0; i <= items; i++ )
-        {
-            ICacheElement<String, String> element = elements.get( i + ":key" );
-            assertNotNull( "element " + i + ":key is missing", element );
-            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
-        }
-
-        // 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" ) );
-        }
-    }
-}
+package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
+
+/*
+ * 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.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.extensions.ActiveTestSuite;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Test which exercises the indexed disk cache. This one uses three different regions for thre
+ * threads.
+ */
+public class HSQLDiskCacheConcurrentUnitTest
+    extends TestCase
+{
+    /**
+     * Number of items to cache, twice the configured maxObjects for the memory cache regions.
+     */
+    private static int items = 100;
+
+    /**
+     * Constructor for the TestDiskCache object.
+     * @param testName
+     */
+    public HSQLDiskCacheConcurrentUnitTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * Main method passes this test to the text test runner.
+     * <p>
+     * @param args
+     */
+    public static void main( String args[] )
+    {
+        String[] testCaseName = { HSQLDiskCacheConcurrentUnitTest.class.getName() };
+        junit.textui.TestRunner.main( testCaseName );
+    }
+
+    /**
+     * A unit test suite for JUnit. Uses ActiveTestSuite to run multiple tests concurrently.
+     * <p>
+     * @return The test suite
+     */
+    public static Test suite()
+    {
+        ActiveTestSuite suite = new ActiveTestSuite();
+
+        suite.addTest( new HSQLDiskCacheConcurrentUnitTest( "testHSQLDiskCache1" )
+        {
+            @Override
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion1" );
+            }
+        } );
+
+        suite.addTest( new HSQLDiskCacheConcurrentUnitTest( "testHSQLDiskCache2" )
+        {
+            @Override
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion2" );
+            }
+        } );
+
+        suite.addTest( new HSQLDiskCacheConcurrentUnitTest( "testHSQLDiskCache3" )
+        {
+            @Override
+            public void runTest()
+                throws Exception
+            {
+                this.runTestForRegion( "indexedRegion3" );
+            }
+        } );
+
+        return suite;
+    }
+
+    /**
+     * Test setup
+     */
+    @Override
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestHSQLDiskCacheConcurrent.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.
+     * <p>
+     * @param region Name of the region to access
+     * @exception Exception If an error occurs
+     */
+    public void runTestForRegion( String region )
+        throws Exception
+    {
+        CacheAccess<String, String> jcs = JCS.getInstance( region );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Test that getElements returns all the expected values
+        Set<String> keys = new HashSet<String>();
+        for ( int i = 0; i <= items; i++ )
+        {
+            keys.add( i + ":key" );
+        }
+
+        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
+        for ( int i = 0; i <= items; i++ )
+        {
+            ICacheElement<String, String> element = elements.get( i + ":key" );
+            assertNotNull( "element " + i + ":key is missing", element );
+            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
+        }
+
+        // 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" ) );
+        }
+    }
+}

Modified: commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java Sun Feb 23 10:37:48 2014
@@ -1,190 +1,190 @@
-package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
-
-/*
- * 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.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.access.exception.CacheException;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-
-/**
- * Test which exercises the indexed disk cache. This one uses three different regions for thre
- * threads.
- */
-public class HSQLDiskCacheUnitTest
-    extends TestCase
-{
-    /**
-     * Test setup
-     */
-    @Override
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestHSQLDiskCache.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.
-     * <p>
-     * @exception Exception If an error occurs
-     */
-    public void testBasicPutRemove()
-        throws Exception
-    {
-        int items = 20;
-
-        String region = "testBasicPutRemove";
-
-        CacheAccess<String, String> jcs = JCS.getInstance( region );
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        //SleepUtil.sleepAtLeast( 1000 );
-
-        System.out.println( jcs.getStats() );
-
-        // Test that all items are in cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-
-        // Test that getElements returns all the expected values
-        Set<String> keys = new HashSet<String>();
-        for ( int i = 0; i <= items; i++ )
-        {
-            keys.add( i + ":key" );
-        }
-
-        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
-        for ( int i = 0; i <= items; i++ )
-        {
-            ICacheElement<String, String> element = elements.get( i + ":key" );
-            assertNotNull( "element " + i + ":key is missing", element );
-            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
-        }
-
-
-        // 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 remove all work son a region where it is not prohibited.
-     * <p>
-     * @throws CacheException
-     * @throws InterruptedException
-     */
-    public void testRemoveAll()
-        throws CacheException, InterruptedException
-    {
-        String region = "removeAllAllowed";
-        CacheAccess<String, String> jcs = JCS.getInstance( region );
-
-        int items = 20;
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        // a db thread could be updating when we call remove all?
-        // there was a race on remove all, an element may be put to disk after it is called even
-        // though the put
-        // was called before clear.
-        // I discovered it and removed it.
-        // Thread.sleep( 500 );
-
-        System.out.println( jcs.getStats() );
-
-        jcs.clear();
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = jcs.get( i + ":key" );
-
-            assertNull( "value should be null key = [" + i + ":key] value = [" + value + "]", value );
-        }
-    }
-
-    /**
-     * Verify that remove all does not work on a region where it is prohibited.
-     * <p>
-     * @throws CacheException
-     * @throws InterruptedException
-     */
-    public void testRemoveAllProhibition()
-        throws CacheException, InterruptedException
-    {
-        String region = "noRemoveAll";
-        CacheAccess<String, String> jcs = JCS.getInstance( region );
-
-        int items = 20;
-
-        // Add items to cache
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-
-        // a db thread could be updating the disk when
-        // Thread.sleep( 500 );
-
-        System.out.println( jcs.getStats() );
-
-        jcs.clear();
-
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-    }
-}
+package org.apache.commons.jcs.auxiliary.disk.jdbc.hsql;
+
+/*
+ * 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.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.access.exception.CacheException;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Test which exercises the indexed disk cache. This one uses three different regions for thre
+ * threads.
+ */
+public class HSQLDiskCacheUnitTest
+    extends TestCase
+{
+    /**
+     * Test setup
+     */
+    @Override
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestHSQLDiskCache.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.
+     * <p>
+     * @exception Exception If an error occurs
+     */
+    public void testBasicPutRemove()
+        throws Exception
+    {
+        int items = 20;
+
+        String region = "testBasicPutRemove";
+
+        CacheAccess<String, String> jcs = JCS.getInstance( region );
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        //SleepUtil.sleepAtLeast( 1000 );
+
+        System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Test that getElements returns all the expected values
+        Set<String> keys = new HashSet<String>();
+        for ( int i = 0; i <= items; i++ )
+        {
+            keys.add( i + ":key" );
+        }
+
+        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
+        for ( int i = 0; i <= items; i++ )
+        {
+            ICacheElement<String, String> element = elements.get( i + ":key" );
+            assertNotNull( "element " + i + ":key is missing", element );
+            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
+        }
+
+
+        // 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 remove all work son a region where it is not prohibited.
+     * <p>
+     * @throws CacheException
+     * @throws InterruptedException
+     */
+    public void testRemoveAll()
+        throws CacheException, InterruptedException
+    {
+        String region = "removeAllAllowed";
+        CacheAccess<String, String> jcs = JCS.getInstance( region );
+
+        int items = 20;
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        // a db thread could be updating when we call remove all?
+        // there was a race on remove all, an element may be put to disk after it is called even
+        // though the put
+        // was called before clear.
+        // I discovered it and removed it.
+        // Thread.sleep( 500 );
+
+        System.out.println( jcs.getStats() );
+
+        jcs.clear();
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = jcs.get( i + ":key" );
+
+            assertNull( "value should be null key = [" + i + ":key] value = [" + value + "]", value );
+        }
+    }
+
+    /**
+     * Verify that remove all does not work on a region where it is prohibited.
+     * <p>
+     * @throws CacheException
+     * @throws InterruptedException
+     */
+    public void testRemoveAllProhibition()
+        throws CacheException, InterruptedException
+    {
+        String region = "noRemoveAll";
+        CacheAccess<String, String> jcs = JCS.getInstance( region );
+
+        int items = 20;
+
+        // Add items to cache
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+
+        // a db thread could be updating the disk when
+        // Thread.sleep( 500 );
+
+        System.out.println( jcs.getStats() );
+
+        jcs.clear();
+
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+    }
+}

Modified: commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java Sun Feb 23 10:37:48 2014
@@ -1,239 +1,239 @@
-package org.apache.commons.jcs.auxiliary.disk.jdbc.mysql;
-
-/*
- * 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.HashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.jcs.JCS;
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-
-/**
- * Runs basic tests for the JDBC disk cache.
- * @author Aaron Smuts
- */
-public class MySQLDiskCacheHsqlBackedUnitTest
-    extends TestCase
-{
-    /**
-     * Creates the DB
-     * <p>
-     * @throws Exception
-     */
-    public MySQLDiskCacheHsqlBackedUnitTest()
-        throws Exception
-    {
-        super();
-        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 + "/MySQLDiskCacheHsqlBackedUnitTest" );
-        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 setup
-     */
-    @Override
-    public void setUp()
-    {
-        JCS.setConfigFilename( "/TestMySQLDiskCache.ccf" );
-    }
-
-    /**
-     * Test the basic JDBC disk cache functionality with a hsql backing.
-     * @throws Exception
-     */
-    public void testSimpleJDBCPutGetWithHSQL()
-        throws Exception
-    {
-        runTestForRegion( "testCache1", 200 );
-    }
-
-    /**
-     * 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.
-     * <p>
-     * @param region Name of the region to access
-     * @param items
-     * @exception Exception If an error occurs
-     */
-    public void runTestForRegion( String region, int items )
-        throws Exception
-    {
-        CacheAccess<String, String> 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() );
-        Thread.sleep( 1000 );
-        //System.out.println( jcs.getStats() );
-
-        // Test that all items are in cache
-        for ( int i = 0; i <= items; i++ )
-        {
-            String value = jcs.get( i + ":key" );
-
-            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
-        }
-
-        // Test that getElements returns all the expected values
-        Set<String> keys = new HashSet<String>();
-        for ( int i = 0; i <= items; i++ )
-        {
-            keys.add( i + ":key" );
-        }
-
-        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
-        for ( int i = 0; i <= items; i++ )
-        {
-            ICacheElement<String, String> element = elements.get( i + ":key" );
-            assertNotNull( "element " + i + ":key is missing", element );
-            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
-        }
-
-        // 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" ) );
-        }
-    }
-
-    /**
-     * Test the basic JDBC disk cache functionality with a hsql backing.
-     * <p>
-     * @throws Exception
-     */
-    public void testPutGetMatchingWithHSQL()
-        throws Exception
-    {
-        // SETUP
-        int items = 200;
-        String region = "testCache2";
-        CacheAccess<String, String> jcs = JCS.getInstance( region );
-        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
-
-        // DO WORK
-        for ( int i = 0; i <= items; i++ )
-        {
-            jcs.put( i + ":key", region + " data " + i );
-        }
-        Thread.sleep( 1000 );
-
-        Map<String, ICacheElement<String, String>> matchingResults = jcs.getMatchingCacheElements( "1.8.+" );
-
-        // VERIFY
-        assertEquals( "Wrong number returned", 10, matchingResults.size() );
-        System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
-        System.out.println( "\nAFTER TEST \n" + jcs.getStats() );
-    }
-
-    /**
-     * SETUP TABLE FOR CACHE
-     * @param cConn
-     */
-    void setupTABLE( Connection cConn ) throws SQLException
-    {
-        boolean newT = true;
-
-        StringBuffer createSql = new StringBuffer();
-        createSql.append( "CREATE CACHED TABLE JCS_STORE_MYSQL " );
-        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           TIMESTAMP, " );
-        createSql.append( "UPDATE_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 = cConn.createStatement();
-
-        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 );
-                throw e;
-            }
-        }
-
-        String setupData[] = { "create index iKEY on JCS_STORE_MYSQL (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.commons.jcs.auxiliary.disk.jdbc.mysql;
+
+/*
+ * 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.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.jcs.JCS;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Runs basic tests for the JDBC disk cache.
+ * @author Aaron Smuts
+ */
+public class MySQLDiskCacheHsqlBackedUnitTest
+    extends TestCase
+{
+    /**
+     * Creates the DB
+     * <p>
+     * @throws Exception
+     */
+    public MySQLDiskCacheHsqlBackedUnitTest()
+        throws Exception
+    {
+        super();
+        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 + "/MySQLDiskCacheHsqlBackedUnitTest" );
+        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 setup
+     */
+    @Override
+    public void setUp()
+    {
+        JCS.setConfigFilename( "/TestMySQLDiskCache.ccf" );
+    }
+
+    /**
+     * Test the basic JDBC disk cache functionality with a hsql backing.
+     * @throws Exception
+     */
+    public void testSimpleJDBCPutGetWithHSQL()
+        throws Exception
+    {
+        runTestForRegion( "testCache1", 200 );
+    }
+
+    /**
+     * 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.
+     * <p>
+     * @param region Name of the region to access
+     * @param items
+     * @exception Exception If an error occurs
+     */
+    public void runTestForRegion( String region, int items )
+        throws Exception
+    {
+        CacheAccess<String, String> 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() );
+        Thread.sleep( 1000 );
+        //System.out.println( jcs.getStats() );
+
+        // Test that all items are in cache
+        for ( int i = 0; i <= items; i++ )
+        {
+            String value = jcs.get( i + ":key" );
+
+            assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+        }
+
+        // Test that getElements returns all the expected values
+        Set<String> keys = new HashSet<String>();
+        for ( int i = 0; i <= items; i++ )
+        {
+            keys.add( i + ":key" );
+        }
+
+        Map<String, ICacheElement<String, String>> elements = jcs.getCacheElements( keys );
+        for ( int i = 0; i <= items; i++ )
+        {
+            ICacheElement<String, String> element = elements.get( i + ":key" );
+            assertNotNull( "element " + i + ":key is missing", element );
+            assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
+        }
+
+        // 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" ) );
+        }
+    }
+
+    /**
+     * Test the basic JDBC disk cache functionality with a hsql backing.
+     * <p>
+     * @throws Exception
+     */
+    public void testPutGetMatchingWithHSQL()
+        throws Exception
+    {
+        // SETUP
+        int items = 200;
+        String region = "testCache2";
+        CacheAccess<String, String> jcs = JCS.getInstance( region );
+        System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+        // DO WORK
+        for ( int i = 0; i <= items; i++ )
+        {
+            jcs.put( i + ":key", region + " data " + i );
+        }
+        Thread.sleep( 1000 );
+
+        Map<String, ICacheElement<String, String>> matchingResults = jcs.getMatchingCacheElements( "1.8.+" );
+
+        // VERIFY
+        assertEquals( "Wrong number returned", 10, matchingResults.size() );
+        System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
+        System.out.println( "\nAFTER TEST \n" + jcs.getStats() );
+    }
+
+    /**
+     * SETUP TABLE FOR CACHE
+     * @param cConn
+     */
+    void setupTABLE( Connection cConn ) throws SQLException
+    {
+        boolean newT = true;
+
+        StringBuffer createSql = new StringBuffer();
+        createSql.append( "CREATE CACHED TABLE JCS_STORE_MYSQL " );
+        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           TIMESTAMP, " );
+        createSql.append( "UPDATE_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 = cConn.createStatement();
+
+        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 );
+                throw e;
+            }
+        }
+
+        String setupData[] = { "create index iKEY on JCS_STORE_MYSQL (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: commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManagerUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManagerUnitTest.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManagerUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManagerUnitTest.java Sun Feb 23 10:37:48 2014
@@ -1,36 +1,55 @@
-package org.apache.commons.jcs.auxiliary.disk.jdbc.mysql;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.jcs.auxiliary.MockCacheEventLogger;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-import org.apache.commons.jcs.engine.control.CompositeCacheManager;
-import org.apache.commons.jcs.engine.control.MockElementSerializer;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-
-/** Unit tests for the manager */
-public class MySQLDiskCacheManagerUnitTest
-    extends TestCase
-{
-    /** Verify that the disk cache has the event logger */
-    public void testGetCache_normal()
-    {
-        // SETUP
-        String cacheName = "testGetCache_normal";
-        MySQLDiskCacheAttributes defaultCacheAttributes = new MySQLDiskCacheAttributes();
-        defaultCacheAttributes.setDiskPath( "target/JDBCDiskCacheManagerUnitTest" );
-
-        ICacheEventLogger cacheEventLogger = new MockCacheEventLogger();
-        IElementSerializer elementSerializer = new MockElementSerializer();
-
-        MySQLDiskCacheManager manager = MySQLDiskCacheManager.getInstance( defaultCacheAttributes, CompositeCacheManager.getUnconfiguredInstance(), cacheEventLogger,
-                                                                           elementSerializer );
-
-        // DO WORK
-        MySQLDiskCache<String, String> cache = manager.getCache( cacheName );
-
-        // VERIFY
-        assertEquals( "wrong cacheEventLogger", cacheEventLogger, cache.getCacheEventLogger() );
-        assertEquals( "wrong elementSerializer", elementSerializer, cache.getElementSerializer() );
-    }
-}
+package org.apache.commons.jcs.auxiliary.disk.jdbc.mysql;
+
+/*
+ * 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.commons.jcs.auxiliary.MockCacheEventLogger;
+import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.engine.control.MockElementSerializer;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+
+/** Unit tests for the manager */
+public class MySQLDiskCacheManagerUnitTest
+    extends TestCase
+{
+    /** Verify that the disk cache has the event logger */
+    public void testGetCache_normal()
+    {
+        // SETUP
+        String cacheName = "testGetCache_normal";
+        MySQLDiskCacheAttributes defaultCacheAttributes = new MySQLDiskCacheAttributes();
+        defaultCacheAttributes.setDiskPath( "target/JDBCDiskCacheManagerUnitTest" );
+
+        ICacheEventLogger cacheEventLogger = new MockCacheEventLogger();
+        IElementSerializer elementSerializer = new MockElementSerializer();
+
+        MySQLDiskCacheManager manager = MySQLDiskCacheManager.getInstance( defaultCacheAttributes, CompositeCacheManager.getUnconfiguredInstance(), cacheEventLogger,
+                                                                           elementSerializer );
+
+        // DO WORK
+        MySQLDiskCache<String, String> cache = manager.getCache( cacheName );
+
+        // VERIFY
+        assertEquals( "wrong cacheEventLogger", cacheEventLogger, cache.getCacheEventLogger() );
+        assertEquals( "wrong elementSerializer", elementSerializer, cache.getElementSerializer() );
+    }
+}

Modified: commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java (original)
+++ commons/proper/jcs/trunk/src/test/org/apache/commons/jcs/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java Sun Feb 23 10:37:48 2014
@@ -1,125 +1,144 @@
-package org.apache.commons.jcs.auxiliary.lateral;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
-
-/**
- * Tests for LateralCacheNoWaitFacade.
- */
-public class LateralCacheNoWaitFacadeUnitTest
-    extends TestCase
-{
-    /**
-     * Verify that we can remove an item.
-     */
-    public void testAddThenRemoveNoWait_InList()
-    {
-        // SETUP
-        @SuppressWarnings("unchecked")
-        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
-        ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
-
-        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
-        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
-
-        // DO WORK
-        facade.addNoWait( noWait );
-
-        // VERIFY
-        assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
-
-        // DO WORK
-        facade.removeNoWait( noWait );
-
-        // VERIFY
-        assertEquals( "Should have 0", 0, facade.noWaits.length );
-        assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
-    }
-
-    /**
-     * Verify that we can remove an item.
-     */
-    public void testAddThenRemoveNoWait_InListSize2()
-    {
-        // SETUP
-        @SuppressWarnings("unchecked")
-        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
-        ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
-
-        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
-        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
-        LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<String, String>( cache );
-
-        // DO WORK
-        facade.addNoWait( noWait );
-        facade.addNoWait( noWait2 );
-
-        // VERIFY
-        assertEquals( "Should have 2", 2, facade.noWaits.length );
-        assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
-        assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
-
-        // DO WORK
-        facade.removeNoWait( noWait );
-
-        // VERIFY
-        assertEquals( "Should only have 1", 1, facade.noWaits.length );
-        assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
-        assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
-    }
-
-    /**
-     * Verify that we can remove an item.
-     */
-    public void testAdd_InList()
-    {
-        // SETUP
-        @SuppressWarnings("unchecked")
-        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
-        ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
-
-        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
-        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
-
-        // DO WORK
-        facade.addNoWait( noWait );
-        facade.addNoWait( noWait );
-
-        // VERIFY
-        assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
-        assertEquals( "Should only have 1", 1, facade.noWaits.length );
-    }
-
-    /**
-     * Verify that we can remove an item.
-     */
-    public void testAddThenRemoveNoWait_NotInList()
-    {
-        // SETUP
-        @SuppressWarnings("unchecked")
-        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
-        ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
-
-        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
-        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
-
-        // DO WORK
-        facade.removeNoWait( noWait );
-
-        // VERIFY
-        assertFalse( "Should not be in the list.", facade.containsNoWait( noWait ) );
-    }
-}
+package org.apache.commons.jcs.auxiliary.lateral;
+
+/*
+ * 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.commons.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes;
+
+/**
+ * Tests for LateralCacheNoWaitFacade.
+ */
+public class LateralCacheNoWaitFacadeUnitTest
+    extends TestCase
+{
+    /**
+     * Verify that we can remove an item.
+     */
+    public void testAddThenRemoveNoWait_InList()
+    {
+        // SETUP
+        @SuppressWarnings("unchecked")
+        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
+        ILateralCacheAttributes cattr = new LateralCacheAttributes();
+        cattr.setCacheName( "testCache1" );
+
+        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
+
+        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
+        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
+
+        // DO WORK
+        facade.addNoWait( noWait );
+
+        // VERIFY
+        assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
+
+        // DO WORK
+        facade.removeNoWait( noWait );
+
+        // VERIFY
+        assertEquals( "Should have 0", 0, facade.noWaits.length );
+        assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
+    }
+
+    /**
+     * Verify that we can remove an item.
+     */
+    public void testAddThenRemoveNoWait_InListSize2()
+    {
+        // SETUP
+        @SuppressWarnings("unchecked")
+        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
+        ILateralCacheAttributes cattr = new LateralCacheAttributes();
+        cattr.setCacheName( "testCache1" );
+
+        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
+
+        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
+        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
+        LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<String, String>( cache );
+
+        // DO WORK
+        facade.addNoWait( noWait );
+        facade.addNoWait( noWait2 );
+
+        // VERIFY
+        assertEquals( "Should have 2", 2, facade.noWaits.length );
+        assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
+        assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
+
+        // DO WORK
+        facade.removeNoWait( noWait );
+
+        // VERIFY
+        assertEquals( "Should only have 1", 1, facade.noWaits.length );
+        assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) );
+        assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) );
+    }
+
+    /**
+     * Verify that we can remove an item.
+     */
+    public void testAdd_InList()
+    {
+        // SETUP
+        @SuppressWarnings("unchecked")
+        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
+        ILateralCacheAttributes cattr = new LateralCacheAttributes();
+        cattr.setCacheName( "testCache1" );
+
+        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
+
+        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
+        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
+
+        // DO WORK
+        facade.addNoWait( noWait );
+        facade.addNoWait( noWait );
+
+        // VERIFY
+        assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) );
+        assertEquals( "Should only have 1", 1, facade.noWaits.length );
+    }
+
+    /**
+     * Verify that we can remove an item.
+     */
+    public void testAddThenRemoveNoWait_NotInList()
+    {
+        // SETUP
+        @SuppressWarnings("unchecked")
+        LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0];
+        ILateralCacheAttributes cattr = new LateralCacheAttributes();
+        cattr.setCacheName( "testCache1" );
+
+        LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr );
+
+        LateralCache<String, String> cache = new LateralCache<String, String>( cattr );
+        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache );
+
+        // DO WORK
+        facade.removeNoWait( noWait );
+
+        // VERIFY
+        assertFalse( "Should not be in the list.", facade.containsNoWait( noWait ) );
+    }
+}



Mime
View raw message