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 as...@apache.org on 2008/10/17 18:25:29 UTC
svn commit: r705663 - in /jakarta/jcs/trunk:
src/java/org/apache/jcs/auxiliary/disk/jdbc/ src/test-conf/
src/test/org/apache/jcs/auxiliary/disk/jdbc/
src/test/org/apache/jcs/auxiliary/remote/server/ xdocs/
Author: asmuts
Date: Fri Oct 17 09:25:28 2008
New Revision: 705663
URL: http://svn.apache.org/viewvc?rev=705663&view=rev
Log:
Documented the shared connection pool configuration for the JDBC disk cache. Added a jdbc prefix to the config prefix. Added an addition unit test that uses a shared pool
Added:
jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheSharedPool.ccf
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheSharedPoolUnitTest.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java
jakarta/jcs/trunk/xdocs/JDBCDiskCache.xml
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java?rev=705663&r1=705662&r2=705663&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java Fri Oct 17 09:25:28 2008
@@ -29,7 +29,7 @@
private Map pools = new HashMap();
/** props prefix */
- public static final String POOL_CONFIGURATION_PREFIX = "jcs.connectionpool.";
+ public static final String POOL_CONFIGURATION_PREFIX = "jcs.jdbcconnectionpool.";
/** .attributes */
public final static String ATTRIBUTE_PREFIX = ".attributes";
Added: jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheSharedPool.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheSharedPool.ccf?rev=705663&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheSharedPool.ccf (added)
+++ jakarta/jcs/trunk/src/test-conf/TestJDBCDiskCacheSharedPool.ccf Fri Oct 17 09:25:28 2008
@@ -0,0 +1,83 @@
+# 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.
+# Cache configuration for the 'TestHSQLDiskCache' test. The memory cache has a
+# a maximum of 100 objects, so objects should get pushed into the disk cache
+
+jcs.default=JDBC_0
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.default.cacheattributes.UseMemoryShrinker=false
+jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
+jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
+jcs.default.elementattributes.IsEternal=false
+jcs.default.elementattributes.MaxLifeSeconds=700
+jcs.default.elementattributes.IdleTime=1800
+jcs.default.elementattributes.IsSpool=true
+jcs.default.elementattributes.IsRemote=true
+jcs.default.elementattributes.IsLateral=true
+
+# #############################################################
+# ################# CONFIGURED REGIONS ########################
+
+jcs.region.testCache1=JDBC_1
+jcs.region.testCache1.cacheattributes.MaxObjects=100
+
+# #############################################################
+# ################# AUXILIARY CACHES AVAILABLE ################
+# JDBC disk cache
+jcs.auxiliary.JDBC_0=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheFactory
+jcs.auxiliary.JDBC_0.attributes=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes
+jcs.auxiliary.JDBC_0.attributes.tableName=JCS_STORE_0
+jcs.auxiliary.JDBC_0.attributes.testBeforeInsert=false
+jcs.auxiliary.JDBC_0.attributes.allowRemoveAll=true
+jcs.auxiliary.JDBC_0.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC_0.attributes.connectionPoolName=MySharedPool
+jcs.auxiliary.JDBC_0.attributes.EventQueueType=POOLED
+jcs.auxiliary.JDBC_0.attributes.EventQueuePoolName=disk_cache_event_queue
+
+jcs.auxiliary.JDBC_1=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheFactory
+jcs.auxiliary.JDBC_1.attributes=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes
+jcs.auxiliary.JDBC_1.attributes.tableName=JCS_STORE_1
+jcs.auxiliary.JDBC_1.attributes.testBeforeInsert=false
+jcs.auxiliary.JDBC_1.attributes.allowRemoveAll=true
+jcs.auxiliary.JDBC_1.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC_1.attributes.connectionPoolName=MySharedPool
+jcs.auxiliary.JDBC_1.attributes.EventQueueType=POOLED
+jcs.auxiliary.JDBC_1.attributes.EventQueuePoolName=disk_cache_event_queue
+
+# #############################################################
+# ######## OPTIONAL SHARED CONNECTION POOL CONFIGURATION ######
+# My Shared Pool
+
+jcs.jdbcconnectionpool.MySharedPool.attributes.userName=sa
+jcs.jdbcconnectionpool.MySharedPool.attributes.password=
+jcs.jdbcconnectionpool.MySharedPool.attributes.url=jdbc:hsqldb:target/cache_hsql_db_sharedpool
+jcs.jdbcconnectionpool.MySharedPool.attributes.driverClassName=org.hsqldb.jdbcDriver
+jcs.jdbcconnectionpool.MySharedPool.attributes.maxActive=15
+
+# #############################################################
+# ################# OPTIONAL THREAD POOL CONFIGURATION #########
+# Disk Cache pool
+thread_pool.disk_cache_event_queue.useBoundary=false
+thread_pool.disk_cache_event_queue.boundarySize=500
+thread_pool.disk_cache_event_queue.maximumPoolSize=15
+thread_pool.disk_cache_event_queue.minimumPoolSize=10
+thread_pool.disk_cache_event_queue.keepAliveTime=3500
+thread_pool.disk_cache_event_queue.whenBlockedPolicy=RUN
+thread_pool.disk_cache_event_queue.startUpSize=10
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheSharedPoolUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheSharedPoolUnitTest.java?rev=705663&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheSharedPoolUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheSharedPoolUnitTest.java Fri Oct 17 09:25:28 2008
@@ -0,0 +1,140 @@
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Runs basic tests for the JDBC disk cache using a shared connection pool.
+ *<p>
+ * @author Aaron Smuts
+ */
+public class JDBCDiskCacheSharedPoolUnitTest
+ extends TestCase
+{
+ /** Test setup */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestJDBCDiskCacheSharedPool.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_sharedpool" );
+ 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_STORE_0" );
+
+ HsqlSetupTableUtil.setupTABLE( cConn, "JCS_STORE_1" );
+
+ 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
+ {
+ JCS jcs = JCS.getInstance( region );
+
+ System.out.println( "BEFORE PUT \n" + jcs.getStats() );
+
+ // Add items to cache
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", region + " data " + i );
+ }
+
+ System.out.println( jcs.getStats() );
+
+ Thread.sleep( 1000 );
+
+ System.out.println( jcs.getStats() );
+
+ // Test that all items are in cache
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ String value = (String) jcs.get( i + ":key" );
+
+ assertEquals( "key = [" + i + ":key] value = [" + value + "]", region + " data " + i, value );
+ }
+
+ // Test that getElements returns all the expected values
+ Set keys = new HashSet();
+ for ( int i = 0; i <= items; i++ )
+ {
+ keys.add( i + ":key" );
+ }
+
+ Map elements = jcs.getCacheElements( keys );
+ for ( int i = 0; i <= items; i++ )
+ {
+ ICacheElement element = (ICacheElement) 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: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java?rev=705663&r1=705662&r2=705663&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerUnitTest.java Fri Oct 17 09:25:28 2008
@@ -31,6 +31,7 @@
import org.apache.jcs.auxiliary.remote.server.behavior.IRemoteCacheServerAttributes;
import org.apache.jcs.engine.CacheElement;
import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.utils.timing.SleepUtil;
/**
* Since the server does not know that it is a server, it is easy to unit test. The factory does all
@@ -302,9 +303,9 @@
server.update( element, clusterListener.getListenerId() );
}
- Thread.sleep( 100 );
+ SleepUtil.sleepAtLeast( 200 );
Thread.yield();
- Thread.sleep( 100 );
+ SleepUtil.sleepAtLeast( 200 );
// VERIFY
assertEquals( "Wrong number of items put to listener.", numToPut, localListener.putItems.size() );
Modified: jakarta/jcs/trunk/xdocs/JDBCDiskCache.xml
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/xdocs/JDBCDiskCache.xml?rev=705663&r1=705662&r2=705663&view=diff
==============================================================================
--- jakarta/jcs/trunk/xdocs/JDBCDiskCache.xml (original)
+++ jakarta/jcs/trunk/xdocs/JDBCDiskCache.xml Fri Oct 17 09:25:28 2008
@@ -1,42 +1,37 @@
<?xml version="1.0"?>
-<!--
- 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.
--->
-
+ <!--
+ 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.
+ -->
<document>
<properties>
<title>JDBC Disk Cache</title>
<author email="asmuts@apache.org">Aaron Smuts</author>
</properties>
-
<body>
<section name="JDBC Disk Auxiliary Cache">
- <p>
- The JDBC disk cache uses a relational database such as
- MySQL as a persistent store. It works with Oracle, MySQL
- and HSQL. The cache elements are serialized and written
- into a BLOB. Multiple regions can share a single table.
- You can define multiple, differently configured JDBC
- disk caches in one JCS instance. This allows you to use
- different tables for different cache regions.
- </p>
-
- <subsection name="Example cache.ccf (MySQL)">
+ <p> The JDBC disk cache uses a relational database such as MySQL as a
+ persistent store. It works with Oracle, MySQL and HSQL. The cache
+ elements are serialized and written into a BLOB. Multiple regions
+ can share a single table. You can define multiple, differently
+ configured JDBC disk caches in one JCS instance. This allows you to
+ use different tables for different cache regions.</p>
+ <p> If you want to use numerous JDBC disk cache instances that talk
+ to the same database, you can configure them to share a connection
+ pool. You might want to use several different tables to partition
+ the data. Some operations, such as index building on a MyISAM
+ storage engine take longer if there are more items in the table.</p>
+ <subsection name="Example #1 cache.ccf (MySQL)">
<source>
<![CDATA[
##############################################################
@@ -92,8 +87,81 @@
]]>
</source>
</subsection>
+
+ <subsection name="Example #2 cache.ccf (MySQL)">
+ <p>
+ This example uses two JDBC Disck Cache instances and a shared connection pool.
+ </p>
+ <source>
+ <![CDATA[
+jcs.default=JDBC_0
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.default.cacheattributes.UseMemoryShrinker=false
+jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
+jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
+jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
+jcs.default.elementattributes.IsEternal=false
+jcs.default.elementattributes.MaxLifeSeconds=700
+jcs.default.elementattributes.IdleTime=1800
+jcs.default.elementattributes.IsSpool=true
+jcs.default.elementattributes.IsRemote=true
+jcs.default.elementattributes.IsLateral=true
+
+# #############################################################
+# ################# CONFIGURED REGIONS ########################
+jcs.region.testCache1=JDBC_1
+jcs.region.testCache1.cacheattributes.MaxObjects=10000
+# #############################################################
+# ################# AUXILIARY CACHES AVAILABLE ################
+# JDBC disk cache
+jcs.auxiliary.JDBC_0=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheFactory
+jcs.auxiliary.JDBC_0.attributes=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes
+jcs.auxiliary.JDBC_0.attributes.tableName=JCS_STORE_0
+jcs.auxiliary.JDBC_0.attributes.testBeforeInsert=false
+jcs.auxiliary.JDBC_0.attributes.allowRemoveAll=true
+jcs.auxiliary.JDBC_0.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC_0.attributes.connectionPoolName=MySharedPool
+jcs.auxiliary.JDBC_0.attributes.EventQueueType=POOLED
+jcs.auxiliary.JDBC_0.attributes.EventQueuePoolName=disk_cache_event_queue
+
+jcs.auxiliary.JDBC_1=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheFactory
+jcs.auxiliary.JDBC_1.attributes=org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes
+jcs.auxiliary.JDBC_1.attributes.tableName=JCS_STORE_1
+jcs.auxiliary.JDBC_1.attributes.testBeforeInsert=false
+jcs.auxiliary.JDBC_1.attributes.allowRemoveAll=true
+jcs.auxiliary.JDBC_1.attributes.MaxPurgatorySize=10000000
+jcs.auxiliary.JDBC_1.attributes.connectionPoolName=MySharedPool
+jcs.auxiliary.JDBC_1.attributes.EventQueueType=POOLED
+jcs.auxiliary.JDBC_1.attributes.EventQueuePoolName=disk_cache_event_queue
+
+# #############################################################
+# ######## OPTIONAL SHARED CONNECTION POOL CONFIGURATION ######
+# My Shared Pool
+
+jcs.jdbcconnectionpool.MySharedPool.attributes.userName=sa
+jcs.jdbcconnectionpool.MySharedPool.attributes.password=
+jcs.jdbcconnectionpool.MySharedPool.attributes.url=jdbc:hsqldb:target/cache_hsql_db
+jcs.jdbcconnectionpool.MySharedPool.attributes.driverClassName=org.hsqldb.jdbcDriver
+jcs.jdbcconnectionpool.MySharedPool.attributes.maxActive=15
+
+# #############################################################
+# ################# OPTIONAL THREAD POOL CONFIGURATION #########
+# Disk Cache pool
+thread_pool.disk_cache_event_queue.useBoundary=false
+thread_pool.disk_cache_event_queue.boundarySize=500
+thread_pool.disk_cache_event_queue.maximumPoolSize=15
+thread_pool.disk_cache_event_queue.minimumPoolSize=10
+thread_pool.disk_cache_event_queue.keepAliveTime=3500
+thread_pool.disk_cache_event_queue.whenBlockedPolicy=RUN
+thread_pool.disk_cache_event_queue.startUpSize=10
+ ]]>
+ </source>
+ </subsection>
+
<subsection name="Table Creation Script (MySQL)">
<source>
<![CDATA[
@@ -122,4 +190,4 @@
</subsection>
</section>
</body>
-</document>
+</document>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org