Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,182 +1,201 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Runs basic tests for the JDBC disk cache.
- *
- * @author Aaron Smuts
- *
- */
-public class JDBCDiskCacheUnitTest
- extends TestCase
-{
-
- /**
- * Test setup
- */
- 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 );
-
- setupTABLE( cConn );
-
- 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.
- *
- * @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 );
- }
-
- // Remove all the items
-
- for ( int i = 0; i <= items; i++ )
- {
- jcs.remove( i + ":key" );
- }
-
- // Verify removal
-
- for ( int i = 0; i <= items; i++ )
- {
- assertNull( "Removed key should be null: " + i + ":key", jcs.get(
i + ":key" ) );
- }
- }
-
- /**
- * SETUP TABLE FOR CACHE
- *
- * @param cConn
- */
- void setupTABLE( Connection cConn )
- {
- boolean newT = true;
-
- StringBuffer createSql = new StringBuffer();
- createSql.append( "CREATE CACHED TABLE JCS_STORE2 " );
- createSql.append( "( " );
- createSql.append( "CACHE_KEY VARCHAR(250) NOT
NULL, " );
- createSql.append( "REGION VARCHAR(250) NOT
NULL, " );
- createSql.append( "ELEMENT BINARY, " );
- createSql.append( "CREATE_TIME DATE, " );
- createSql.append( "CREATE_TIME_SECONDS BIGINT, " );
- createSql.append( "MAX_LIFE_SECONDS BIGINT, " );
- createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS BIGINT, " );
- createSql.append( "IS_ETERNAL CHAR(1), " );
- createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
- createSql.append( ");" );
-
- Statement sStatement = null;
- try
- {
- sStatement = cConn.createStatement();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
-
- try
- {
- sStatement.executeQuery( createSql.toString() );
- sStatement.close();
- }
- catch ( SQLException e )
- {
- if ( e.toString().indexOf( "already exists" ) != -1 )
- {
- newT = false;
- }
- else
- {
- // TODO figure out if it exists prior to trying to create it.
- // log.error( "Problem creating table.", e );
- e.printStackTrace();
- }
- }
-
- String setupData[] = { "create index iKEY on JCS_STORE2 (CACHE_KEY,
REGION)" };
-
- if ( newT )
- {
- for ( int i = 1; i < setupData.length; i++ )
- {
- try
- {
- sStatement.executeQuery( setupData[i] );
- }
- catch ( SQLException e )
- {
- System.out.println( "Exception: " + e );
- }
- }
- } // end ifnew
- }
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/**
+ * Runs basic tests for the JDBC disk cache.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class JDBCDiskCacheUnitTest
+ extends TestCase
+{
+
+ /**
+ * Test setup
+ */
+ 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 );
+
+ setupTABLE( cConn );
+
+ 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.
+ *
+ * @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 );
+ }
+
+ // Remove all the items
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.remove( i + ":key" );
+ }
+
+ // Verify removal
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ assertNull( "Removed key should be null: " + i + ":key", jcs.get(
i + ":key" ) );
+ }
+ }
+
+ /**
+ * SETUP TABLE FOR CACHE
+ *
+ * @param cConn
+ */
+ void setupTABLE( Connection cConn )
+ {
+ boolean newT = true;
+
+ StringBuffer createSql = new StringBuffer();
+ createSql.append( "CREATE CACHED TABLE JCS_STORE2 " );
+ createSql.append( "( " );
+ createSql.append( "CACHE_KEY VARCHAR(250) NOT
NULL, " );
+ createSql.append( "REGION VARCHAR(250) NOT
NULL, " );
+ createSql.append( "ELEMENT BINARY, " );
+ createSql.append( "CREATE_TIME DATE, " );
+ createSql.append( "CREATE_TIME_SECONDS BIGINT, " );
+ createSql.append( "MAX_LIFE_SECONDS BIGINT, " );
+ createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS BIGINT, " );
+ createSql.append( "IS_ETERNAL CHAR(1), " );
+ createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+ createSql.append( ");" );
+
+ Statement sStatement = null;
+ try
+ {
+ sStatement = cConn.createStatement();
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ }
+
+ try
+ {
+ sStatement.executeQuery( createSql.toString() );
+ sStatement.close();
+ }
+ catch ( SQLException e )
+ {
+ if ( e.toString().indexOf( "already exists" ) != -1 )
+ {
+ newT = false;
+ }
+ else
+ {
+ // TODO figure out if it exists prior to trying to create it.
+ // log.error( "Problem creating table.", e );
+ e.printStackTrace();
+ }
+ }
+
+ String setupData[] = { "create index iKEY on JCS_STORE2 (CACHE_KEY,
REGION)" };
+
+ if ( newT )
+ {
+ for ( int i = 1; i < setupData.length; i++ )
+ {
+ try
+ {
+ sStatement.executeQuery( setupData[i] );
+ }
+ catch ( SQLException e )
+ {
+ System.out.println( "Exception: " + e );
+ }
+ }
+ } // end ifnew
+ }
+}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheConcurrentUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,159 +1,162 @@
-package org.apache.jcs.auxiliary.disk.jdbc.hsql;
-
-/*
- * 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 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.
- *
- * @param args
- */
- public static void main( String args[] )
- {
- String[] testCaseName = {
HSQLDiskCacheConcurrentUnitTest.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 HSQLDiskCacheConcurrentUnitTest(
"testHSQLDiskCache1" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "indexedRegion1" );
- }
- } );
-
- suite.addTest( new HSQLDiskCacheConcurrentUnitTest(
"testHSQLDiskCache2" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "indexedRegion2" );
- }
- } );
-
- suite.addTest( new HSQLDiskCacheConcurrentUnitTest(
"testHSQLDiskCache3" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "indexedRegion3" );
- }
- } );
-
- return suite;
- }
-
- /**
- * Test setup
- */
- 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.
- *
- * @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 );
- }
-
- 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 );
- }
-
- // 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.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 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 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.
+ *
+ * @param args
+ */
+ public static void main( String args[] )
+ {
+ String[] testCaseName = {
HSQLDiskCacheConcurrentUnitTest.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 HSQLDiskCacheConcurrentUnitTest(
"testHSQLDiskCache1" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "indexedRegion1" );
+ }
+ } );
+
+ suite.addTest( new HSQLDiskCacheConcurrentUnitTest(
"testHSQLDiskCache2" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "indexedRegion2" );
+ }
+ } );
+
+ suite.addTest( new HSQLDiskCacheConcurrentUnitTest(
"testHSQLDiskCache3" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "indexedRegion3" );
+ }
+ } );
+
+ return suite;
+ }
+
+ /**
+ * Test setup
+ */
+ 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.
+ *
+ * @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 );
+ }
+
+ 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 );
+ }
+
+ // 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/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,173 +1,176 @@
-package org.apache.jcs.auxiliary.disk.jdbc.hsql;
-
-/*
- * 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.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.access.exception.CacheException;
-
-/**
- * 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 HSQLDiskCacheUnitTest
- extends TestCase
-{
- /**
- * Test setup
- */
- 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.
- *
- * @param region
- * Name of the region to access
- *
- * @exception Exception
- * If an error occurs
- */
- public void testBasicPutRemove()
- throws Exception
- {
- int items = 20;
-
- String region = "testCache";
-
- JCS 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() );
-
- // 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 );
- }
-
- // 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.
- *
- * @throws CacheException
- * @throws InterruptedException
- *
- */
- public void testRemoveAll()
- throws CacheException, InterruptedException
- {
- String region = "removeAllAllowed";
- JCS 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 = (String) 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.
- *
- * @throws CacheException
- * @throws InterruptedException
- *
- */
- public void testRemoveAllProhibition()
- throws CacheException, InterruptedException
- {
- String region = "noRemoveAll";
- JCS 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 = (String) jcs.get( i + ":key" );
-
- assertEquals( "key = [" + i + ":key] value = [" + value + "]",
region + " data " + i, value );
- }
- }
-}
+package org.apache.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 junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.access.exception.CacheException;
+
+/**
+ * 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 HSQLDiskCacheUnitTest
+ extends TestCase
+{
+ /**
+ * Test setup
+ */
+ 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.
+ *
+ * @param region
+ * Name of the region to access
+ *
+ * @exception Exception
+ * If an error occurs
+ */
+ public void testBasicPutRemove()
+ throws Exception
+ {
+ int items = 20;
+
+ String region = "testCache";
+
+ JCS 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() );
+
+ // 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 );
+ }
+
+ // 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.
+ *
+ * @throws CacheException
+ * @throws InterruptedException
+ *
+ */
+ public void testRemoveAll()
+ throws CacheException, InterruptedException
+ {
+ String region = "removeAllAllowed";
+ JCS 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 = (String) 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.
+ *
+ * @throws CacheException
+ * @throws InterruptedException
+ *
+ */
+ public void testRemoveAllProhibition()
+ throws CacheException, InterruptedException
+ {
+ String region = "noRemoveAll";
+ JCS 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 = (String) jcs.get( i + ":key" );
+
+ assertEquals( "key = [" + i + ":key] value = [" + value + "]",
region + " data " + i, value );
+ }
+ }
+}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheHsqlBackedUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,182 +1,201 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Runs basic tests for the JDBC disk cache.
- *
- * @author Aaron Smuts
- *
- */
-public class MySQLDiskCacheHsqlBackedUnitTest
- extends TestCase
-{
-
- /**
- * Test setup
- */
- 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
- {
- System.setProperty( "hsqldb.cache_scale", "8" );
-
- String rafroot = "target";
- Properties p = new Properties();
- String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
- String url = p.getProperty( "url", "jdbc:hsqldb:" );
- String database = p.getProperty( "database", rafroot +
"/cache_hsql_db" );
- String user = p.getProperty( "user", "sa" );
- String password = p.getProperty( "password", "" );
-
- new org.hsqldb.jdbcDriver();
- Class.forName( driver ).newInstance();
- Connection cConn = DriverManager.getConnection( url + database, user,
password );
-
- setupTABLE( cConn );
-
- runTestForRegion( "testCache1", 30 );
- }
-
- /**
- * 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 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 );
- }
-
- // Remove all the items
-
- for ( int i = 0; i <= items; i++ )
- {
- jcs.remove( i + ":key" );
- }
-
- // Verify removal
-
- for ( int i = 0; i <= items; i++ )
- {
- assertNull( "Removed key should be null: " + i + ":key", jcs.get(
i + ":key" ) );
- }
- }
-
- /**
- * SETUP TABLE FOR CACHE
- *
- * @param cConn
- */
- void setupTABLE( Connection cConn )
- {
- boolean newT = true;
-
- StringBuffer createSql = new StringBuffer();
- createSql.append( "CREATE CACHED TABLE JCS_STORE_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 DATE, " );
- createSql.append( "CREATE_TIME_SECONDS BIGINT, " );
- createSql.append( "MAX_LIFE_SECONDS BIGINT, " );
- createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS BIGINT, " );
- createSql.append( "IS_ETERNAL CHAR(1), " );
- createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
- createSql.append( ");" );
-
- Statement sStatement = null;
- try
- {
- sStatement = cConn.createStatement();
- }
- catch ( SQLException e )
- {
- e.printStackTrace();
- }
-
- try
- {
- sStatement.executeQuery( createSql.toString() );
- sStatement.close();
- }
- catch ( SQLException e )
- {
- if ( e.toString().indexOf( "already exists" ) != -1 )
- {
- newT = false;
- }
- else
- {
- // TODO figure out if it exists prior to trying to create it.
- // log.error( "Problem creating table.", e );
- e.printStackTrace();
- }
- }
-
- String setupData[] = { "create index iKEY on JCS_STORE_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.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.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/**
+ * Runs basic tests for the JDBC disk cache.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class MySQLDiskCacheHsqlBackedUnitTest
+ extends TestCase
+{
+
+ /**
+ * Test setup
+ */
+ 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
+ {
+ System.setProperty( "hsqldb.cache_scale", "8" );
+
+ String rafroot = "target";
+ Properties p = new Properties();
+ String driver = p.getProperty( "driver", "org.hsqldb.jdbcDriver" );
+ String url = p.getProperty( "url", "jdbc:hsqldb:" );
+ String database = p.getProperty( "database", rafroot +
"/cache_hsql_db" );
+ String user = p.getProperty( "user", "sa" );
+ String password = p.getProperty( "password", "" );
+
+ new org.hsqldb.jdbcDriver();
+ Class.forName( driver ).newInstance();
+ Connection cConn = DriverManager.getConnection( url + database, user,
password );
+
+ setupTABLE( cConn );
+
+ runTestForRegion( "testCache1", 30 );
+ }
+
+ /**
+ * 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 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 );
+ }
+
+ // Remove all the items
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.remove( i + ":key" );
+ }
+
+ // Verify removal
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ assertNull( "Removed key should be null: " + i + ":key", jcs.get(
i + ":key" ) );
+ }
+ }
+
+ /**
+ * SETUP TABLE FOR CACHE
+ *
+ * @param cConn
+ */
+ void setupTABLE( Connection cConn )
+ {
+ boolean newT = true;
+
+ StringBuffer createSql = new StringBuffer();
+ createSql.append( "CREATE CACHED TABLE JCS_STORE_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 DATE, " );
+ createSql.append( "CREATE_TIME_SECONDS BIGINT, " );
+ createSql.append( "MAX_LIFE_SECONDS BIGINT, " );
+ createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS BIGINT, " );
+ createSql.append( "IS_ETERNAL CHAR(1), " );
+ createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+ createSql.append( ");" );
+
+ Statement sStatement = null;
+ try
+ {
+ sStatement = cConn.createStatement();
+ }
+ catch ( SQLException e )
+ {
+ e.printStackTrace();
+ }
+
+ try
+ {
+ sStatement.executeQuery( createSql.toString() );
+ sStatement.close();
+ }
+ catch ( SQLException e )
+ {
+ if ( e.toString().indexOf( "already exists" ) != -1 )
+ {
+ newT = false;
+ }
+ else
+ {
+ // TODO figure out if it exists prior to trying to create it.
+ // log.error( "Problem creating table.", e );
+ e.printStackTrace();
+ }
+ }
+
+ String setupData[] = { "create index iKEY on JCS_STORE_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:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,40 +1,59 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.auxiliary.disk.jdbc.TableState;
-
-/**
- * Simple tests for the MySQLDisk Cache.
- * <p>
- * We will probably need to setup an hsql behind this, to test some of the
pass through methods.
- * <p>
- * @author Aaron Smuts
- */
-public class MySQLDiskCacheUnitTest
- extends TestCase
-{
- /**
- * Verify that we simply return null on get if an optimization is in
- * progress and the cache is configured to balk on optimization.
- * <p>
- * This is a bit tricky since we don't want to have to have a mysql
instance
- * running. Right now this doesn't really test much
- */
- public void testBalkOnGet()
- {
- MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
- String tableName = "JCS_TEST";
- attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
- attributes.setTableName( tableName );
- attributes.setBalkDuringOptimization( true );
-
- TableState tableState = new TableState( tableName );
- tableState.setState( TableState.OPTIMIZATION_RUNNING );
-
- MySQLDiskCache cache = new MySQLDiskCache( attributes, tableState );
-
- Object result = cache.doGet( "myKey" );
- assertNull( "The result should be null", result );
- }
-}
+package org.apache.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.jcs.auxiliary.disk.jdbc.TableState;
+
+/**
+ * Simple tests for the MySQLDisk Cache.
+ * <p>
+ * We will probably need to setup an hsql behind this, to test some of the
pass through methods.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class MySQLDiskCacheUnitTest
+ extends TestCase
+{
+ /**
+ * Verify that we simply return null on get if an optimization is in
+ * progress and the cache is configured to balk on optimization.
+ * <p>
+ * This is a bit tricky since we don't want to have to have a mysql
instance
+ * running. Right now this doesn't really test much
+ */
+ public void testBalkOnGet()
+ {
+ MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
+ String tableName = "JCS_TEST";
+ attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
+ attributes.setTableName( tableName );
+ attributes.setBalkDuringOptimization( true );
+
+ TableState tableState = new TableState( tableName );
+ tableState.setState( TableState.OPTIMIZATION_RUNNING );
+
+ MySQLDiskCache cache = new MySQLDiskCache( attributes, tableState );
+
+ Object result = cache.doGet( "myKey" );
+ assertNull( "The result should be null", result );
+ }
+}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java
Thu May 10 09:03:42 2007
@@ -1,54 +1,73 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql;
-
-import org.apache.jcs.auxiliary.disk.jdbc.TableState;
-
-import junit.framework.TestCase;
-
-/**
- * Hand run tests for the MySQL table optimizer.
- * <p>
- * @author Aaron Smuts
- */
-public class MySQLTableOptimizerManualTester
- extends TestCase
-{
-
- /**
- * Run the optimization against live a table.
- */
- public void testBasicOptimization()
- {
- MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
- attributes.setUserName( "java" );
- attributes.setPassword( "letmein" );
- attributes.setUrl( "jdbc:mysql://10.19.98.43:3306/flight_option_cache"
);
- attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
- String tableName = "JCS_STORE_FLIGHT_OPTION_ITINERARY";
- attributes.setTableName( tableName );
- TableState tableState = new TableState( tableName);
-
- MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes,
tableState );
-
- optimizer.optimizeTable();
- }
-
- /**
- * Run the optimization against live a table.
- */
- public void testBasicOptimizationUnknownTable()
- {
- MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
- attributes.setUserName( "java" );
- attributes.setPassword( "letmein" );
- attributes.setUrl( "jdbc:mysql://10.19.98.43:3306/flight_option_cache"
);
- attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
- String tableName = "DOESNTEXIST";
- attributes.setTableName( tableName );
- TableState tableState = new TableState( tableName);
-
- MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes,
tableState );
-
- optimizer.optimizeTable();
- }
-
-}
+package org.apache.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 org.apache.jcs.auxiliary.disk.jdbc.TableState;
+
+import junit.framework.TestCase;
+
+/**
+ * Hand run tests for the MySQL table optimizer.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class MySQLTableOptimizerManualTester
+ extends TestCase
+{
+
+ /**
+ * Run the optimization against live a table.
+ */
+ public void testBasicOptimization()
+ {
+ MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
+ attributes.setUserName( "java" );
+ attributes.setPassword( "letmein" );
+ attributes.setUrl( "jdbc:mysql://10.19.98.43:3306/flight_option_cache"
);
+ attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
+ String tableName = "JCS_STORE_FLIGHT_OPTION_ITINERARY";
+ attributes.setTableName( tableName );
+ TableState tableState = new TableState( tableName);
+
+ MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes,
tableState );
+
+ optimizer.optimizeTable();
+ }
+
+ /**
+ * Run the optimization against live a table.
+ */
+ public void testBasicOptimizationUnknownTable()
+ {
+ MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes();
+ attributes.setUserName( "java" );
+ attributes.setPassword( "letmein" );
+ attributes.setUrl( "jdbc:mysql://10.19.98.43:3306/flight_option_cache"
);
+ attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" );
+ String tableName = "DOESNTEXIST";
+ attributes.setTableName( tableName );
+ TableState tableState = new TableState( tableName);
+
+ MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes,
tableState );
+
+ optimizer.optimizeTable();
+ }
+
+}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/util/ScheduleParserUtilUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,109 +1,128 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql.util;
-
-import java.util.Date;
-
-import junit.framework.TestCase;
-
-/**
- * Unit tests for the schedule parser.
- * <p>
- * @author Aaron Smuts
- */
-public class ScheduleParserUtilUnitTest
- extends TestCase
-{
-
- /**
- * Verify that we get an exception and not a null pointer for null input.
- */
- public void testGetDatesWithNullInput()
- {
- try
- {
- ScheduleParser.createDatesForSchedule( null );
-
- fail( "Should have thrown an exception" );
- }
- catch ( ScheduleFormatException e )
- {
- // expected
- }
- }
-
- /**
- * Verify that we get an exception and not a null pointer for null input.
- */
- public void testGetDateWithNullInput()
- {
- try
- {
- ScheduleParser.getDateForSchedule( null );
-
- fail( "Should have thrown an exception" );
- }
- catch ( ScheduleFormatException e )
- {
- // expected
- }
- }
-
- /**
- * Verify that we get one date for one date.
- * @throws ScheduleFormatException
- */
- public void testGetsDatesSingle()
- throws ScheduleFormatException
- {
- String schedule = "12:34:56";
- Date[] dates = ScheduleParser.createDatesForSchedule( schedule );
-
- assertEquals( "Wrong number of dates returned.", 1, dates.length );
- }
- /**
- * Verify that we get one date for one date.
- * @throws ScheduleFormatException
- */
- public void testGetsDatesMultiple()
- throws ScheduleFormatException
- {
- String schedule = "12:34:56,03:51:00,12:34:12";
- Date[] dates = ScheduleParser.createDatesForSchedule( schedule );
- //System.out.println( dates );
- assertEquals( "Wrong number of dates returned.", 3, dates.length );
- }
-
- /**
- * Verify that we get an exception for a single bad date in a list.
- */
- public void testGetDatesMalformedNoColon()
- {
- try
- {
- String schedule = "12:34:56,03:51:00,123234";
- ScheduleParser.createDatesForSchedule( schedule );
-
- fail( "Should have thrown an exception for a malformed date" );
- }
- catch ( ScheduleFormatException e )
- {
- // expected
- }
- }
- /**
- * Verify that we get an exception for a schedule that has a non numeric
item.
- */
- public void testGetDatesMalformedNan()
- {
- try
- {
- String schedule = "12:34:56,03:51:00,aa:12:12";
- ScheduleParser.createDatesForSchedule( schedule );
-
- fail( "Should have thrown an exception for a malformed date" );
- }
- catch ( ScheduleFormatException e )
- {
- // expected
- }
- }
-}
+package org.apache.jcs.auxiliary.disk.jdbc.mysql.util;
+
+/*
+ * 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.Date;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the schedule parser.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class ScheduleParserUtilUnitTest
+ extends TestCase
+{
+
+ /**
+ * Verify that we get an exception and not a null pointer for null input.
+ */
+ public void testGetDatesWithNullInput()
+ {
+ try
+ {
+ ScheduleParser.createDatesForSchedule( null );
+
+ fail( "Should have thrown an exception" );
+ }
+ catch ( ScheduleFormatException e )
+ {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that we get an exception and not a null pointer for null input.
+ */
+ public void testGetDateWithNullInput()
+ {
+ try
+ {
+ ScheduleParser.getDateForSchedule( null );
+
+ fail( "Should have thrown an exception" );
+ }
+ catch ( ScheduleFormatException e )
+ {
+ // expected
+ }
+ }
+
+ /**
+ * Verify that we get one date for one date.
+ * @throws ScheduleFormatException
+ */
+ public void testGetsDatesSingle()
+ throws ScheduleFormatException
+ {
+ String schedule = "12:34:56";
+ Date[] dates = ScheduleParser.createDatesForSchedule( schedule );
+
+ assertEquals( "Wrong number of dates returned.", 1, dates.length );
+ }
+ /**
+ * Verify that we get one date for one date.
+ * @throws ScheduleFormatException
+ */
+ public void testGetsDatesMultiple()
+ throws ScheduleFormatException
+ {
+ String schedule = "12:34:56,03:51:00,12:34:12";
+ Date[] dates = ScheduleParser.createDatesForSchedule( schedule );
+ //System.out.println( dates );
+ assertEquals( "Wrong number of dates returned.", 3, dates.length );
+ }
+
+ /**
+ * Verify that we get an exception for a single bad date in a list.
+ */
+ public void testGetDatesMalformedNoColon()
+ {
+ try
+ {
+ String schedule = "12:34:56,03:51:00,123234";
+ ScheduleParser.createDatesForSchedule( schedule );
+
+ fail( "Should have thrown an exception for a malformed date" );
+ }
+ catch ( ScheduleFormatException e )
+ {
+ // expected
+ }
+ }
+ /**
+ * Verify that we get an exception for a schedule that has a non numeric
item.
+ */
+ public void testGetDatesMalformedNan()
+ {
+ try
+ {
+ String schedule = "12:34:56,03:51:00,aa:12:12";
+ ScheduleParser.createDatesForSchedule( schedule );
+
+ fail( "Should have thrown an exception for a malformed date" );
+ }
+ catch ( ScheduleFormatException e )
+ {
+ // expected
+ }
+ }
+}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/http/broadcast/LateralCacheTester.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/http/broadcast/LateralCacheTester.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/http/broadcast/LateralCacheTester.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/http/broadcast/LateralCacheTester.java
Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
package org.apache.jcs.auxiliary.lateral.http.broadcast;
+/*
+ * 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.
+ */
+
/**
* @author Aaron Smuts
* @created January 15, 2002
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
Thu May 10 09:03:42 2007
@@ -1,182 +1,201 @@
-package org.apache.jcs.auxiliary.lateral.socket.tcp;
-
-import java.util.Random;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * @author asmuts
- */
-public class LateralTCPConcurrentRandomTestUtil
- extends TestCase
-{
-
- private static boolean isSysOut = false;
- //private static boolean isSysOut = true;
-
- /**
- * Constructor for the TestDiskCache object.
- *
- * @param testName
- */
- public LateralTCPConcurrentRandomTestUtil( String testName )
- {
- super( testName );
- }
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestTCPLateralCacheConcurrent.ccf" );
- }
-
- /**
- * Randomly adds items to cache, gets them, and removes them. The range
- * count is more than the size of the memory cache, so items should spool
to
- * disk.
- * <p>
- * @param region
- * Name of the region to access
- * @param range
- * @param numOps
- * @param testNum
- *
- * @exception Exception
- * If an error occurs
- */
- public void runTestForRegion( String region, int range, int numOps, int
testNum )
- throws Exception
- {
- boolean show = true;//false;
-
- JCS cache = JCS.getInstance( region );
-
- TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1103 );
- lattr2.setTransmissionTypeName( "TCP" );
- lattr2.setTcpServer( "localhost:1102" );
-
- // this service will put and remove using the lateral to
- // the cache instance above
- // the cache thinks it is different since the listenerid is different
- LateralTCPService service = new LateralTCPService( lattr2 );
- service.setListenerId( 123456 );
-
- try
- {
- for ( int i = 1; i < numOps; i++ )
- {
- Random ran = new Random( i );
- int n = ran.nextInt( 4 );
- int kn = ran.nextInt( range );
- String key = "key" + kn;
- if ( n == 1 )
- {
- ICacheElement element = new CacheElement( region, key,
region + ":data" + i
- + " junk asdfffffffadfasdfasf " + kn + ":" + n );
- service.update( element );
- if ( show )
- {
- p( "put " + key );
- }
- }
- /**/
- else if ( n == 2 )
- {
- service.remove( region, key );
- if ( show )
- {
- p( "removed " + key );
- }
- }
- /**/
- else
- {
- // slightly greater chance of get
- try
- {
- Object obj = service.get( region, key );
- if ( show && obj != null )
- {
- p( obj.toString() );
- }
- }
- catch ( Exception e )
- {
- // consider failing, some timeouts are expected
- e.printStackTrace();
- }
- }
-
- if ( i % 100 == 0 )
- {
- System.out.println( cache.getStats() );
- }
-
- }
- p( "Finished random cycle of " + numOps );
- }
- catch ( Exception e )
- {
- p( e.toString() );
- e.printStackTrace( System.out );
- throw e;
- }
-
- JCS jcs = JCS.getInstance( region );
- String key = "testKey" + testNum;
- String data = "testData" + testNum;
- jcs.put( key, data );
- String value = (String) jcs.get( key );
- assertEquals( "Couldn't put normally.", data, value );
-
- // make sure the items we can find are in the correct region.
- for ( int i = 1; i < numOps; i++ )
- {
- String keyL = "key" + i;
- String dataL = (String) jcs.get( keyL );
- if ( dataL != null )
- {
- assertTrue( "Incorrect region detected.", dataL.startsWith(
region ) );
- }
-
- }
-
- //Thread.sleep( 1000 );
-
- //ICacheElement element = new CacheElement( region, "abc", "testdata");
- //service.update( element );
-
- //Thread.sleep( 2500 );
- // could be too mcuh going on right now to get ti through, sot he test
- // might fail.
- //String value2 = (String) jcs.get( "abc" );
- //assertEquals( "Couldn't put laterally, could be too much traffic in
- // queue.", "testdata", value2 );
-
- }
-
- /**
- * @param s string to print
- */
- public static void p( String s )
- {
- if ( isSysOut )
- {
- System.out.println( s );
- }
- else
- {
- //if ( log.isInfoEnabled() )
- //{
- // log.info( s );
- //}
- }
- }
-}
+package org.apache.jcs.auxiliary.lateral.socket.tcp;
+
+/*
+ * 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.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * @author asmuts
+ */
+public class LateralTCPConcurrentRandomTestUtil
+ extends TestCase
+{
+
+ private static boolean isSysOut = false;
+ //private static boolean isSysOut = true;
+
+ /**
+ * Constructor for the TestDiskCache object.
+ *
+ * @param testName
+ */
+ public LateralTCPConcurrentRandomTestUtil( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestTCPLateralCacheConcurrent.ccf" );
+ }
+
+ /**
+ * Randomly adds items to cache, gets them, and removes them. The range
+ * count is more than the size of the memory cache, so items should spool
to
+ * disk.
+ * <p>
+ * @param region
+ * Name of the region to access
+ * @param range
+ * @param numOps
+ * @param testNum
+ *
+ * @exception Exception
+ * If an error occurs
+ */
+ public void runTestForRegion( String region, int range, int numOps, int
testNum )
+ throws Exception
+ {
+ boolean show = true;//false;
+
+ JCS cache = JCS.getInstance( region );
+
+ TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort( 1103 );
+ lattr2.setTransmissionTypeName( "TCP" );
+ lattr2.setTcpServer( "localhost:1102" );
+
+ // this service will put and remove using the lateral to
+ // the cache instance above
+ // the cache thinks it is different since the listenerid is different
+ LateralTCPService service = new LateralTCPService( lattr2 );
+ service.setListenerId( 123456 );
+
+ try
+ {
+ for ( int i = 1; i < numOps; i++ )
+ {
+ Random ran = new Random( i );
+ int n = ran.nextInt( 4 );
+ int kn = ran.nextInt( range );
+ String key = "key" + kn;
+ if ( n == 1 )
+ {
+ ICacheElement element = new CacheElement( region, key,
region + ":data" + i
+ + " junk asdfffffffadfasdfasf " + kn + ":" + n );
+ service.update( element );
+ if ( show )
+ {
+ p( "put " + key );
+ }
+ }
+ /**/
+ else if ( n == 2 )
+ {
+ service.remove( region, key );
+ if ( show )
+ {
+ p( "removed " + key );
+ }
+ }
+ /**/
+ else
+ {
+ // slightly greater chance of get
+ try
+ {
+ Object obj = service.get( region, key );
+ if ( show && obj != null )
+ {
+ p( obj.toString() );
+ }
+ }
+ catch ( Exception e )
+ {
+ // consider failing, some timeouts are expected
+ e.printStackTrace();
+ }
+ }
+
+ if ( i % 100 == 0 )
+ {
+ System.out.println( cache.getStats() );
+ }
+
+ }
+ p( "Finished random cycle of " + numOps );
+ }
+ catch ( Exception e )
+ {
+ p( e.toString() );
+ e.printStackTrace( System.out );
+ throw e;
+ }
+
+ JCS jcs = JCS.getInstance( region );
+ String key = "testKey" + testNum;
+ String data = "testData" + testNum;
+ jcs.put( key, data );
+ String value = (String) jcs.get( key );
+ assertEquals( "Couldn't put normally.", data, value );
+
+ // make sure the items we can find are in the correct region.
+ for ( int i = 1; i < numOps; i++ )
+ {
+ String keyL = "key" + i;
+ String dataL = (String) jcs.get( keyL );
+ if ( dataL != null )
+ {
+ assertTrue( "Incorrect region detected.", dataL.startsWith(
region ) );
+ }
+
+ }
+
+ //Thread.sleep( 1000 );
+
+ //ICacheElement element = new CacheElement( region, "abc", "testdata");
+ //service.update( element );
+
+ //Thread.sleep( 2500 );
+ // could be too mcuh going on right now to get ti through, sot he test
+ // might fail.
+ //String value2 = (String) jcs.get( "abc" );
+ //assertEquals( "Couldn't put laterally, could be too much traffic in
+ // queue.", "testdata", value2 );
+
+ }
+
+ /**
+ * @param s string to print
+ */
+ public static void p( String s )
+ {
+ if ( isSysOut )
+ {
+ System.out.println( s );
+ }
+ else
+ {
+ //if ( log.isInfoEnabled() )
+ //{
+ // log.info( s );
+ //}
+ }
+ }
+}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
Thu May 10 09:03:42 2007
@@ -1,172 +1,191 @@
-package org.apache.jcs.auxiliary.lateral.socket.tcp;
-
-import java.io.Serializable;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * @author asmuts
- */
-public class LateralTCPFilterRemoveHashCodeUnitTest
- extends TestCase
-{
-
- //private static boolean isSysOut = false;
-
- private static boolean isSysOut = true;
-
- /**
- * Constructor for the TestDiskCache object.
- *
- * @param testName
- */
- public LateralTCPFilterRemoveHashCodeUnitTest( String testName )
- {
- super( testName );
- }
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestTCPLateralRemoveFilter.ccf" );
- }
-
- /**
- *
- * @throws Exception
- */
- public void test()
- throws Exception
- {
- this.runTestForRegion( "region1", 200, 1 );
- }
-
- /**
- * This tests issues tons of puts. It also check to see that a key that was
- * put in was removed by the clients remove command.
- *
- * @param region
- * Name of the region to access
- * @param numOps
- * @param testNum
- *
- * @exception Exception
- * If an error occurs
- */
- public void runTestForRegion( String region, int numOps, int testNum )
- throws Exception
- {
-
- //boolean show = true;//false;
-
- JCS cache = JCS.getInstance( region );
-
- Thread.sleep( 100 );
-
- TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1102 );
- lattr2.setTransmissionTypeName( "TCP" );
- lattr2.setTcpServer( "localhost:1110" );
- lattr2.setIssueRemoveOnPut( true );
- // should still try to remove
- lattr2.setAllowPut( false );
-
- // this service will put and remove using the lateral to
- // the cache instance above
- // the cache thinks it is different since the listenerid is different
- LateralTCPService service = new LateralTCPService( lattr2 );
- service.setListenerId( 123456 );
-
- String keyToBeRemovedOnPut = "test1";
-
- String keyToNotBeRemovedOnPut = "test2";
-
- Serializable dataToPassHashCodeCompare = new Serializable()
- {
- private static final long serialVersionUID = 1L;
-
- public int hashCode()
- {
- return 1;
- }
- };
- //String dataToPassHashCodeCompare = "this should be the same and not
- // get removed.";
- //p( "dataToPassHashCodeCompare hashcode = " + +
- // dataToPassHashCodeCompare.hashCode() );
-
- cache.put( keyToBeRemovedOnPut, "this should get removed." );
- ICacheElement element1 = new CacheElement( region,
keyToBeRemovedOnPut, region
- + ":data-this shouldn't get there" );
- service.update( element1 );
-
- cache.put( keyToNotBeRemovedOnPut, dataToPassHashCodeCompare );
- ICacheElement element2 = new CacheElement( region,
keyToNotBeRemovedOnPut, dataToPassHashCodeCompare );
- service.update( element2 );
-
- /*
- * try { for ( int i = 1; i < numOps; i++ ) { Random ran = new Random(
i );
- * int n = ran.nextInt( 4 ); int kn = ran.nextInt( range ); String key
=
- * "key" + kn;
- *
- * ICacheElement element = new CacheElement( region, key, region +
- * ":data" + i + " junk asdfffffffadfasdfasf " + kn + ":" + n );
- * service.update( element ); if ( show ) { p( "put " + key ); }
- *
- * if ( i % 100 == 0 ) { System.out.println( cache.getStats() ); }
- * } p( "Finished cycle of " + numOps ); } catch ( Exception e ) { p(
- * e.toString() ); e.printStackTrace( System.out ); throw e; }
- */
-
- JCS jcs = JCS.getInstance( region );
- String key = "testKey" + testNum;
- String data = "testData" + testNum;
- jcs.put( key, data );
- String value = (String) jcs.get( key );
- assertEquals( "Couldn't put normally.", data, value );
-
- // make sure the items we can find are in the correct region.
- for ( int i = 1; i < numOps; i++ )
- {
- String keyL = "key" + i;
- String dataL = (String) jcs.get( keyL );
- if ( dataL != null )
- {
- assertTrue( "Incorrect region detected.", dataL.startsWith(
region ) );
- }
-
- }
-
- Thread.sleep( 200 );
-
- Object testObj1 = cache.get( keyToBeRemovedOnPut );
- p( "test object1 = " + testObj1 );
- assertNull( "The test object should have been remvoed by a put.",
testObj1 );
-
- Object testObj2 = cache.get( keyToNotBeRemovedOnPut );
- p( "test object2 = " + testObj2 + " hashCode = " );
- if ( testObj2 != null )
- {
- p( "test2 hashcode = " + +testObj2.hashCode() );
- }
- assertNotNull( "This should not have been removed, since the hascode
were the same.", testObj2 );
-
- }
-
- /**
- * @param s String to print
- */
- public static void p( String s )
- {
- if ( isSysOut )
- {
- System.out.println( s );
- }
- }
-}
+package org.apache.jcs.auxiliary.lateral.socket.tcp;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.Serializable;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * @author asmuts
+ */
+public class LateralTCPFilterRemoveHashCodeUnitTest
+ extends TestCase
+{
+
+ //private static boolean isSysOut = false;
+
+ private static boolean isSysOut = true;
+
+ /**
+ * Constructor for the TestDiskCache object.
+ *
+ * @param testName
+ */
+ public LateralTCPFilterRemoveHashCodeUnitTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestTCPLateralRemoveFilter.ccf" );
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void test()
+ throws Exception
+ {
+ this.runTestForRegion( "region1", 200, 1 );
+ }
+
+ /**
+ * This tests issues tons of puts. It also check to see that a key that was
+ * put in was removed by the clients remove command.
+ *
+ * @param region
+ * Name of the region to access
+ * @param numOps
+ * @param testNum
+ *
+ * @exception Exception
+ * If an error occurs
+ */
+ public void runTestForRegion( String region, int numOps, int testNum )
+ throws Exception
+ {
+
+ //boolean show = true;//false;
+
+ JCS cache = JCS.getInstance( region );
+
+ Thread.sleep( 100 );
+
+ TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort( 1102 );
+ lattr2.setTransmissionTypeName( "TCP" );
+ lattr2.setTcpServer( "localhost:1110" );
+ lattr2.setIssueRemoveOnPut( true );
+ // should still try to remove
+ lattr2.setAllowPut( false );
+
+ // this service will put and remove using the lateral to
+ // the cache instance above
+ // the cache thinks it is different since the listenerid is different
+ LateralTCPService service = new LateralTCPService( lattr2 );
+ service.setListenerId( 123456 );
+
+ String keyToBeRemovedOnPut = "test1";
+
+ String keyToNotBeRemovedOnPut = "test2";
+
+ Serializable dataToPassHashCodeCompare = new Serializable()
+ {
+ private static final long serialVersionUID = 1L;
+
+ public int hashCode()
+ {
+ return 1;
+ }
+ };
+ //String dataToPassHashCodeCompare = "this should be the same and not
+ // get removed.";
+ //p( "dataToPassHashCodeCompare hashcode = " + +
+ // dataToPassHashCodeCompare.hashCode() );
+
+ cache.put( keyToBeRemovedOnPut, "this should get removed." );
+ ICacheElement element1 = new CacheElement( region,
keyToBeRemovedOnPut, region
+ + ":data-this shouldn't get there" );
+ service.update( element1 );
+
+ cache.put( keyToNotBeRemovedOnPut, dataToPassHashCodeCompare );
+ ICacheElement element2 = new CacheElement( region,
keyToNotBeRemovedOnPut, dataToPassHashCodeCompare );
+ service.update( element2 );
+
+ /*
+ * try { for ( int i = 1; i < numOps; i++ ) { Random ran = new Random(
i );
+ * int n = ran.nextInt( 4 ); int kn = ran.nextInt( range ); String key
=
+ * "key" + kn;
+ *
+ * ICacheElement element = new CacheElement( region, key, region +
+ * ":data" + i + " junk asdfffffffadfasdfasf " + kn + ":" + n );
+ * service.update( element ); if ( show ) { p( "put " + key ); }
+ *
+ * if ( i % 100 == 0 ) { System.out.println( cache.getStats() ); }
+ * } p( "Finished cycle of " + numOps ); } catch ( Exception e ) { p(
+ * e.toString() ); e.printStackTrace( System.out ); throw e; }
+ */
+
+ JCS jcs = JCS.getInstance( region );
+ String key = "testKey" + testNum;
+ String data = "testData" + testNum;
+ jcs.put( key, data );
+ String value = (String) jcs.get( key );
+ assertEquals( "Couldn't put normally.", data, value );
+
+ // make sure the items we can find are in the correct region.
+ for ( int i = 1; i < numOps; i++ )
+ {
+ String keyL = "key" + i;
+ String dataL = (String) jcs.get( keyL );
+ if ( dataL != null )
+ {
+ assertTrue( "Incorrect region detected.", dataL.startsWith(
region ) );
+ }
+
+ }
+
+ Thread.sleep( 200 );
+
+ Object testObj1 = cache.get( keyToBeRemovedOnPut );
+ p( "test object1 = " + testObj1 );
+ assertNull( "The test object should have been remvoed by a put.",
testObj1 );
+
+ Object testObj2 = cache.get( keyToNotBeRemovedOnPut );
+ p( "test object2 = " + testObj2 + " hashCode = " );
+ if ( testObj2 != null )
+ {
+ p( "test2 hashcode = " + +testObj2.hashCode() );
+ }
+ assertNotNull( "This should not have been removed, since the hascode
were the same.", testObj2 );
+
+ }
+
+ /**
+ * @param s String to print
+ */
+ public static void p( String s )
+ {
+ if ( isSysOut )
+ {
+ System.out.println( s );
+ }
+ }
+}
|