You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by tv...@apache.org on 2007/05/10 18:04:27 UTC
svn commit: r536904 [25/38] - in /jakarta/jcs/trunk: ./
auxiliary-builds/javagroups/
auxiliary-builds/javagroups/src/java/org/apache/jcs/auxiliary/javagroups/
auxiliary-builds/javagroups/src/test/org/apache/jcs/auxiliary/javagroups/
auxiliary-builds/jd...
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSCacheElementRetrievalUnitTest.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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.engine.behavior.ICacheElement;
@@ -22,14 +25,14 @@
/**
* @author Aaron Smuts
- *
+ *
*/
public class JCSCacheElementRetrievalUnitTest
extends TestCase
{
/**
- *
+ *
* @throws Exception
*/
public void testSimpleElementRetrieval()
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSLightLoadUnitTest.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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.Test;
@@ -22,7 +25,7 @@
/**
* Description of the Class
- *
+ *
*/
public class JCSLightLoadUnitTest
extends TestCase
@@ -42,7 +45,7 @@
/**
* Constructor for the TestSimpleLoad object
- *
+ *
* @param testName
* Description of the Parameter
*/
@@ -53,7 +56,7 @@
/**
* Description of the Method
- *
+ *
* @param args
* Description of the Parameter
*/
@@ -65,7 +68,7 @@
/**
* A unit test suite for JUnit
- *
+ *
* @return The test suite
*/
public static Test suite()
@@ -75,7 +78,7 @@
/**
* A unit test for JUnit
- *
+ *
* @exception Exception
* Description of the Exception
*/
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSRemovalSimpleConcurrentTest.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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;
@@ -26,7 +29,7 @@
{
/**
* Constructor for the TestDiskCache object.
- *
+ *
* @param testName
*/
public JCSRemovalSimpleConcurrentTest( String testName )
@@ -46,7 +49,7 @@
/**
* Main method passes this test to the text test runner.
- *
+ *
* @param args
*/
public static void main( String args[] )
@@ -57,7 +60,7 @@
/**
* Verify that 2 level deep hierchical removal works.
- *
+ *
* @throws Exception
*/
public void testTwoDeepRemoval()
@@ -98,7 +101,7 @@
/**
* Verify that 1 level deep hierchical removal works.
- *
+ *
* @throws Exception
*/
public void testSingleDepthRemoval()
@@ -139,7 +142,7 @@
/**
* Verify that clear removes everyting as it should.
- *
+ *
* @throws Exception
*/
public void testClear()
@@ -185,7 +188,7 @@
/**
* Verify that we can clear repeatedly without error.
- *
+ *
* @throws Exception
*/
public void testClearRepeatedlyWithoutError()
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSThrashTest.java Thu May 10 09:03:42 2007
@@ -1,318 +1,337 @@
-package org.apache.jcs;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.engine.stats.behavior.IStatElement;
-import org.apache.jcs.engine.stats.behavior.IStats;
-
-/**
- * This is based on a test that was posted to the user's list:
- *
- * http://www.opensubscriber.com/message/jcs-users@jakarta.apache.org/2435965.html
- *
- */
-public class JCSThrashTest
- extends TestCase
-{
-
- private static final Log LOG = LogFactory.getLog( JCSThrashTest.class.getName() );
-
- /**
- * the cache instance
- */
- protected JCS jcs;
-
- /**
- * @param args
- */
- public static void main( String[] args )
- {
- junit.textui.TestRunner.run( JCSThrashTest.class );
- }
-
- /**
- * @param arg0
- */
- public JCSThrashTest( String arg0 )
- {
- super( arg0 );
- }
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
- JCS.setConfigFilename( "/TestThrash.ccf" );
- jcs = JCS.getInstance( "testcache" );
- }
-
- protected void tearDown()
- throws Exception
- {
- super.tearDown();
- jcs.clear();
- jcs.dispose();
- }
-
- /**
- * Tests adding an entry.
- * @throws Exception
- */
- public void testPut()
- throws Exception
- {
- final String value = "value";
- final String key = "key";
-
- // Make sure the element is not found
- assertEquals( 0, getListSize() );
-
- assertNull( jcs.get( key ) );
-
- jcs.put( key, value );
-
- // Get the element
- LOG.info( "jcs.getStats(): " + jcs.getStatistics() );
- assertEquals( 1, getListSize() );
- assertNotNull( jcs.get( key ) );
- assertEquals( value, jcs.get( key ) );
- }
-
- /**
- * Test elements can be removed from the store
- * @throws Exception
- */
- public void testRemove()
- throws Exception
- {
- jcs.put( "key1", "value1" );
- assertEquals( 1, getListSize() );
-
- jcs.remove( "key1" );
- assertEquals( 0, getListSize() );
-
- jcs.put( "key2", "value2" );
- jcs.put( "key3", "value3" );
- assertEquals( 2, getListSize() );
-
- jcs.remove( "key2" );
- assertEquals( 1, getListSize() );
-
- // Try to remove an object that is not there in the store
- jcs.remove( "key4" );
- assertEquals( 1, getListSize() );
- }
-
- /**
- * This does a bunch of work and then verifies that the memory has not grown by much.
- * Most of the time the amount of memory used after the test is less.
- *
- * @throws Exception
- */
- public void testForMemoryLeaks()
- throws Exception
- {
- long differenceMemoryCache = thrashCache();
- LOG.info( "Memory Difference is: " + differenceMemoryCache );
- assertTrue( differenceMemoryCache < 500000 );
-
- //LOG.info( "Memory Used is: " + measureMemoryUse() );
- }
-
- /**
- * @return
- * @throws Exception
- */
- protected long thrashCache()
- throws Exception
- {
-
- long startingSize = measureMemoryUse();
- LOG.info( "Memory Used is: " + startingSize );
-
- final String value = "value";
- final String key = "key";
-
- // Add the entry
- jcs.put( key, value );
-
- // Create 15 threads that read the keys;
- final List executables = new ArrayList();
- for ( int i = 0; i < 15; i++ )
- {
- final JCSThrashTest.Executable executable = new JCSThrashTest.Executable()
- {
- public void execute()
- throws Exception
- {
- for ( int i = 0; i < 500; i++ )
- {
- final String key = "key" + i;
- jcs.get( key );
- }
- jcs.get( "key" );
- }
- };
- executables.add( executable );
- }
-
- // Create 15 threads that are insert 500 keys with large byte[] as
- // values
- for ( int i = 0; i < 15; i++ )
- {
- final JCSThrashTest.Executable executable = new JCSThrashTest.Executable()
- {
- public void execute()
- throws Exception
- {
-
- // Add a bunch of entries
- for ( int i = 0; i < 500; i++ )
- {
- // Use a random length value
- final String key = "key" + i;
- byte[] value = new byte[10000];
- jcs.put( key, value );
- }
- }
- };
- executables.add( executable );
- }
-
- runThreads( executables );
- jcs.clear();
-
- long finishingSize = measureMemoryUse();
- LOG.info( "Memory Used is: " + finishingSize );
- return finishingSize - startingSize;
- }
-
- /**
- * Runs a set of threads, for a fixed amount of time.
- * @param executables
- * @throws Exception
- */
- protected void runThreads( final List executables )
- throws Exception
- {
-
- final long endTime = System.currentTimeMillis() + 10000;
- final Throwable[] errors = new Throwable[1];
-
- // Spin up the threads
- final Thread[] threads = new Thread[executables.size()];
- for ( int i = 0; i < threads.length; i++ )
- {
- final JCSThrashTest.Executable executable = (JCSThrashTest.Executable) executables.get( i );
- threads[i] = new Thread()
- {
- public void run()
- {
- try
- {
- // Run the thread until the given end time
- while ( System.currentTimeMillis() < endTime )
- {
- executable.execute();
- }
- }
- catch ( Throwable t )
- {
- // Hang on to any errors
- errors[0] = t;
- }
- }
- };
- threads[i].start();
- }
-
- // Wait for the threads to finish
- for ( int i = 0; i < threads.length; i++ )
- {
- threads[i].join();
- }
-
- // Throw any error that happened
- if ( errors[0] != null )
- {
- throw new Exception( "Test thread failed.", errors[0] );
- }
- }
-
- /**
- * Measure memory used by the VM.
- *
- * @return
- * @throws InterruptedException
- */
- protected long measureMemoryUse()
- throws InterruptedException
- {
- System.gc();
- Thread.sleep( 3000 );
- System.gc();
- return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
- }
-
- /**
- * A runnable, that can throw an exception.
- */
- protected interface Executable
- {
- /**
- * Executes this object.
- *
- * @throws Exception
- */
- void execute()
- throws Exception;
- }
-
- /**
- *
- * @return
- */
- private int getListSize()
- {
- final String listSize = "List Size";
- final String lruMemoryCache = "LRU Memory Cache";
- String result = "0";
- IStats istats[] = jcs.getStatistics().getAuxiliaryCacheStats();
- for ( int i = 0; i < istats.length; i++ )
- {
- IStatElement statElements[] = istats[i].getStatElements();
- if ( lruMemoryCache.equals( istats[i].getTypeName() ) )
- {
- for ( int j = 0; j < statElements.length; j++ )
- {
- if ( listSize.equals( statElements[j].getName() ) )
- {
- result = statElements[j].getData();
- }
- }
- }
-
- }
- return Integer.parseInt( result );
- }
-
-// private int getMapSize()
-// {
-// final String listSize = "Map Size";
-// String result = "0";
-// IStatElement statElements[] = jcs.getStatistics().getStatElements();
-// for ( int i = 0; i < statElements.length; i++ )
-// {
-// if ( listSize.equals( statElements[i].getName() ) )
-// {
-// result = statElements[i].getData();
-// }
-// }
-// return Integer.parseInt( result );
-// }
-}
+package org.apache.jcs;
+
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.engine.stats.behavior.IStatElement;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
+/**
+ * This is based on a test that was posted to the user's list:
+ *
+ * http://www.opensubscriber.com/message/jcs-users@jakarta.apache.org/2435965.html
+ *
+ */
+public class JCSThrashTest
+ extends TestCase
+{
+
+ private static final Log LOG = LogFactory.getLog( JCSThrashTest.class.getName() );
+
+ /**
+ * the cache instance
+ */
+ protected JCS jcs;
+
+ /**
+ * @param args
+ */
+ public static void main( String[] args )
+ {
+ junit.textui.TestRunner.run( JCSThrashTest.class );
+ }
+
+ /**
+ * @param arg0
+ */
+ public JCSThrashTest( String arg0 )
+ {
+ super( arg0 );
+ }
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ JCS.setConfigFilename( "/TestThrash.ccf" );
+ jcs = JCS.getInstance( "testcache" );
+ }
+
+ protected void tearDown()
+ throws Exception
+ {
+ super.tearDown();
+ jcs.clear();
+ jcs.dispose();
+ }
+
+ /**
+ * Tests adding an entry.
+ * @throws Exception
+ */
+ public void testPut()
+ throws Exception
+ {
+ final String value = "value";
+ final String key = "key";
+
+ // Make sure the element is not found
+ assertEquals( 0, getListSize() );
+
+ assertNull( jcs.get( key ) );
+
+ jcs.put( key, value );
+
+ // Get the element
+ LOG.info( "jcs.getStats(): " + jcs.getStatistics() );
+ assertEquals( 1, getListSize() );
+ assertNotNull( jcs.get( key ) );
+ assertEquals( value, jcs.get( key ) );
+ }
+
+ /**
+ * Test elements can be removed from the store
+ * @throws Exception
+ */
+ public void testRemove()
+ throws Exception
+ {
+ jcs.put( "key1", "value1" );
+ assertEquals( 1, getListSize() );
+
+ jcs.remove( "key1" );
+ assertEquals( 0, getListSize() );
+
+ jcs.put( "key2", "value2" );
+ jcs.put( "key3", "value3" );
+ assertEquals( 2, getListSize() );
+
+ jcs.remove( "key2" );
+ assertEquals( 1, getListSize() );
+
+ // Try to remove an object that is not there in the store
+ jcs.remove( "key4" );
+ assertEquals( 1, getListSize() );
+ }
+
+ /**
+ * This does a bunch of work and then verifies that the memory has not grown by much.
+ * Most of the time the amount of memory used after the test is less.
+ *
+ * @throws Exception
+ */
+ public void testForMemoryLeaks()
+ throws Exception
+ {
+ long differenceMemoryCache = thrashCache();
+ LOG.info( "Memory Difference is: " + differenceMemoryCache );
+ assertTrue( differenceMemoryCache < 500000 );
+
+ //LOG.info( "Memory Used is: " + measureMemoryUse() );
+ }
+
+ /**
+ * @return
+ * @throws Exception
+ */
+ protected long thrashCache()
+ throws Exception
+ {
+
+ long startingSize = measureMemoryUse();
+ LOG.info( "Memory Used is: " + startingSize );
+
+ final String value = "value";
+ final String key = "key";
+
+ // Add the entry
+ jcs.put( key, value );
+
+ // Create 15 threads that read the keys;
+ final List executables = new ArrayList();
+ for ( int i = 0; i < 15; i++ )
+ {
+ final JCSThrashTest.Executable executable = new JCSThrashTest.Executable()
+ {
+ public void execute()
+ throws Exception
+ {
+ for ( int i = 0; i < 500; i++ )
+ {
+ final String key = "key" + i;
+ jcs.get( key );
+ }
+ jcs.get( "key" );
+ }
+ };
+ executables.add( executable );
+ }
+
+ // Create 15 threads that are insert 500 keys with large byte[] as
+ // values
+ for ( int i = 0; i < 15; i++ )
+ {
+ final JCSThrashTest.Executable executable = new JCSThrashTest.Executable()
+ {
+ public void execute()
+ throws Exception
+ {
+
+ // Add a bunch of entries
+ for ( int i = 0; i < 500; i++ )
+ {
+ // Use a random length value
+ final String key = "key" + i;
+ byte[] value = new byte[10000];
+ jcs.put( key, value );
+ }
+ }
+ };
+ executables.add( executable );
+ }
+
+ runThreads( executables );
+ jcs.clear();
+
+ long finishingSize = measureMemoryUse();
+ LOG.info( "Memory Used is: " + finishingSize );
+ return finishingSize - startingSize;
+ }
+
+ /**
+ * Runs a set of threads, for a fixed amount of time.
+ * @param executables
+ * @throws Exception
+ */
+ protected void runThreads( final List executables )
+ throws Exception
+ {
+
+ final long endTime = System.currentTimeMillis() + 10000;
+ final Throwable[] errors = new Throwable[1];
+
+ // Spin up the threads
+ final Thread[] threads = new Thread[executables.size()];
+ for ( int i = 0; i < threads.length; i++ )
+ {
+ final JCSThrashTest.Executable executable = (JCSThrashTest.Executable) executables.get( i );
+ threads[i] = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ // Run the thread until the given end time
+ while ( System.currentTimeMillis() < endTime )
+ {
+ executable.execute();
+ }
+ }
+ catch ( Throwable t )
+ {
+ // Hang on to any errors
+ errors[0] = t;
+ }
+ }
+ };
+ threads[i].start();
+ }
+
+ // Wait for the threads to finish
+ for ( int i = 0; i < threads.length; i++ )
+ {
+ threads[i].join();
+ }
+
+ // Throw any error that happened
+ if ( errors[0] != null )
+ {
+ throw new Exception( "Test thread failed.", errors[0] );
+ }
+ }
+
+ /**
+ * Measure memory used by the VM.
+ *
+ * @return
+ * @throws InterruptedException
+ */
+ protected long measureMemoryUse()
+ throws InterruptedException
+ {
+ System.gc();
+ Thread.sleep( 3000 );
+ System.gc();
+ return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+ }
+
+ /**
+ * A runnable, that can throw an exception.
+ */
+ protected interface Executable
+ {
+ /**
+ * Executes this object.
+ *
+ * @throws Exception
+ */
+ void execute()
+ throws Exception;
+ }
+
+ /**
+ *
+ * @return
+ */
+ private int getListSize()
+ {
+ final String listSize = "List Size";
+ final String lruMemoryCache = "LRU Memory Cache";
+ String result = "0";
+ IStats istats[] = jcs.getStatistics().getAuxiliaryCacheStats();
+ for ( int i = 0; i < istats.length; i++ )
+ {
+ IStatElement statElements[] = istats[i].getStatElements();
+ if ( lruMemoryCache.equals( istats[i].getTypeName() ) )
+ {
+ for ( int j = 0; j < statElements.length; j++ )
+ {
+ if ( listSize.equals( statElements[j].getName() ) )
+ {
+ result = statElements[j].getData();
+ }
+ }
+ }
+
+ }
+ return Integer.parseInt( result );
+ }
+
+// private int getMapSize()
+// {
+// final String listSize = "Map Size";
+// String result = "0";
+// IStatElement statElements[] = jcs.getStatistics().getStatElements();
+// for ( int i = 0; i < statElements.length; i++ )
+// {
+// if ( listSize.equals( statElements[i].getName() ) )
+// {
+// result = statElements[i].getData();
+// }
+// }
+// return Integer.parseInt( result );
+// }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSUniTest.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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.Test;
@@ -28,7 +31,7 @@
/**
* Simple test for the JCS class.
- *
+ *
* @version $Id$
*/
public class JCSUniTest
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/JCSvsHashtablePerformanceTest.java Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
package org.apache.jcs;
+/*
+ * 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.Hashtable;
import junit.framework.Test;
@@ -15,7 +34,7 @@
* of magnitude of the java.util.Hashtable.
* <p>
* Currenlty JCS is un 2x a hashtable for gets, and under 1.2x for puts.
- *
+ *
*/
public class JCSvsHashtablePerformanceTest
extends TestCase
@@ -41,7 +60,7 @@
/**
* A unit test suite for JUnit
- *
+ *
* @return The test suite
*/
public static Test suite()
@@ -51,7 +70,7 @@
/**
* A unit test for JUnit
- *
+ *
* @exception Exception
* Description of the Exception
*/
@@ -76,7 +95,7 @@
}
/**
- *
+ *
*/
public void doWork()
{
@@ -188,4 +207,4 @@
test.doWork();
}
-}
\ No newline at end of file
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java Thu May 10 09:03:42 2007
@@ -1,26 +1,29 @@
package org.apache.jcs;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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;
/**
* Simple methods to be run by active test suites that test removal.
- *
+ *
*/
public class RemovalTestUtil
extends TestCase
@@ -28,7 +31,7 @@
/**
* Constructor for the TestSimpleLoad object
- *
+ *
* @param testName
* Description of the Parameter
*/
@@ -40,10 +43,10 @@
/**
* Adds elements in the range specified and then removes them using the
* categorical or substring removal method.
- *
- * @param start
- * @param end
- *
+ *
+ * @param start
+ * @param end
+ *
* @exception Exception
* Description of the Exception
*/
@@ -81,7 +84,7 @@
/**
* Put items in the cache in this key range. Can be used to verify that
* concurrent operations are not effected by things like hierchical removal.
- *
+ *
* @param start
* int
* @param end
@@ -111,7 +114,7 @@
/**
* Just get from start to end.
- *
+ *
* @param start
* int
* @param end
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/TestTCPLateralCache.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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;
@@ -23,7 +26,7 @@
/**
* Test which exercises the indexed disk cache. This one uses three different
* regions for thre threads.
- *
+ *
* @version $Id$
*/
public class TestTCPLateralCache
@@ -37,7 +40,7 @@
/**
* Constructor for the TestDiskCache object.
- *
+ *
* @param testName
*/
public TestTCPLateralCache( String testName )
@@ -47,7 +50,7 @@
/**
* Main method passes this test to the text test runner.
- *
+ *
* @param args
*/
public static void main( String args[] )
@@ -58,7 +61,7 @@
/**
* A unit test suite for JUnit
- *
+ *
* @return The test suite
*/
public static Test suite()
@@ -104,10 +107,10 @@
/**
* 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
*/
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/ZeroSizeCacheUnitTest.java Thu May 10 09:03:42 2007
@@ -1,77 +1,96 @@
-package org.apache.jcs;
-
-import junit.framework.TestCase;
-
-/**
- *
- * @author Aaron Smuts
- *
- */
-public class ZeroSizeCacheUnitTest
- extends TestCase
-{
-
- private static int items = 20000;
-
- /**
- * Test setup
- */
- public void setUp()
- throws Exception
- {
- JCS.setConfigFilename( "/TestZeroSizeCache.ccf" );
- JCS.getInstance( "testCache1" );
- }
-
- /**
- * Verify that a 0 size cache does not result in errors. You should be able
- * to disable a region this way.
- * @throws Exception
- *
- */
- public void testPutGetRemove()
- throws Exception
- {
- JCS jcs = JCS.getInstance( "testCache1" );
-
- for ( int i = 0; i <= items; i++ )
- {
- jcs.put( i + ":key", "data" + i );
- }
-
- // all the gets should be null
- for ( int i = items; i >= 0; i-- )
- {
- String res = (String) jcs.get( i + ":key" );
- if ( res == null )
- {
- assertNull( "[" + i + ":key] should be null", res );
- }
- }
-
- // test removal, should be no exceptions
- jcs.remove( "300:key" );
-
- // allow the shrinker to run
- Thread.sleep( 500 );
-
- // do it again.
- for ( int i = 0; i <= items; i++ )
- {
- jcs.put( i + ":key", "data" + i );
- }
-
- for ( int i = items; i >= 0; i-- )
- {
- String res = (String) jcs.get( i + ":key" );
- if ( res == null )
- {
- assertNull( "[" + i + ":key] should be null", res );
- }
- }
-
- System.out.println( jcs.getStats() );
-
- }
-
-}
+package org.apache.jcs;
+
+/*
+ * 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;
+
+/**
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class ZeroSizeCacheUnitTest
+ extends TestCase
+{
+
+ private static int items = 20000;
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ throws Exception
+ {
+ JCS.setConfigFilename( "/TestZeroSizeCache.ccf" );
+ JCS.getInstance( "testCache1" );
+ }
+
+ /**
+ * Verify that a 0 size cache does not result in errors. You should be able
+ * to disable a region this way.
+ * @throws Exception
+ *
+ */
+ public void testPutGetRemove()
+ throws Exception
+ {
+ JCS jcs = JCS.getInstance( "testCache1" );
+
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // all the gets should be null
+ for ( int i = items; i >= 0; i-- )
+ {
+ String res = (String) jcs.get( i + ":key" );
+ if ( res == null )
+ {
+ assertNull( "[" + i + ":key] should be null", res );
+ }
+ }
+
+ // test removal, should be no exceptions
+ jcs.remove( "300:key" );
+
+ // allow the shrinker to run
+ Thread.sleep( 500 );
+
+ // do it again.
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ for ( int i = items; i >= 0; i-- )
+ {
+ String res = (String) jcs.get( i + ":key" );
+ if ( res == null )
+ {
+ assertNull( "[" + i + ":key] should be null", res );
+ }
+ }
+
+ System.out.println( jcs.getStats() );
+
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java Thu May 10 09:03:42 2007
@@ -1,238 +1,257 @@
-package org.apache.jcs.access;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.access.exception.CacheException;
-import org.apache.jcs.access.exception.ObjectExistsException;
-import org.apache.jcs.engine.CompositeCacheAttributes;
-import org.apache.jcs.engine.ElementAttributes;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
-import org.apache.jcs.engine.behavior.IElementAttributes;
-
-/**
- * Tests the methods of the cache access class from which the class JCS extends.
- *
- * @author Aaron Smuts
- *
- */
-public class CacheAccessUnitTest
- extends TestCase
-{
-
- /**
- * Verify that we get an object exists exception if the item is in the
- * cache.
- *
- */
- public void testPutSafe()
- {
-
- CacheAccess access = null;
- try
- {
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
- }
- catch ( CacheException e )
- {
- fail( "Shouldn't have received an error." + e.getMessage() );
- }
-
- String key = "mykey";
- String value = "myvalue";
-
- try
- {
- access.put( key, value );
- }
- catch ( CacheException e )
- {
- fail( "Should have been able to put " + e.getMessage() );
- }
- String returnedValue1 = (String) access.get( key );
- assertEquals( "Wrong value returned.", value, returnedValue1 );
-
- try
- {
- access.putSafe( key, "someothervalue" );
- fail( "We should have received an eception since this key is alredy in the cache." );
- }
- catch ( CacheException e )
- {
- // e.printStackTrace();
- // expected
- assertTrue( "Wrong type of exception.", e instanceof ObjectExistsException );
- assertTrue( "Should have the key in the error message.", e.getMessage().indexOf( "[" + key + "]" ) != -1 );
- }
-
- String returnedValue2 = (String) access.get( key );
- assertEquals( "Wrong value returned. Shoudl still be the original.", value, returnedValue2 );
- }
-
- /**
- * Try to put a null key and verify that we get an exception.
- *
- */
- public void testPutNullKey()
- {
-
- CacheAccess access = null;
- try
- {
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
- }
- catch ( CacheException e )
- {
- fail( "Shouldn't have received an error." + e.getMessage() );
- }
-
- String key = null;
- String value = "myvalue";
-
- try
- {
- access.put( key, value );
- fail( "Should not have been able to put a null key." );
- }
- catch ( CacheException e )
- {
- // expected
- assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
- }
- }
-
- /**
- * Try to put a null value and verify that we get an exception.
- *
- */
- public void testPutNullValue()
- {
-
- CacheAccess access = null;
- try
- {
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
- }
- catch ( CacheException e )
- {
- fail( "Shouldn't have received an error." + e.getMessage() );
- }
-
- String key = "myKey";
- String value = null;
-
- try
- {
- access.put( key, value );
- fail( "Should not have been able to put a null object." );
- }
- catch ( CacheException e )
- {
- // expected
- assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
- }
- }
-
- /**
- * Verify that elements that go in the region after this call takethe new
- * attributes.
- *
- * @throws Exception
- *
- */
- public void testSetDefaultElementAttributes()
- throws Exception
- {
-
- CacheAccess access = null;
-
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
-
- long maxLife = 9876;
- IElementAttributes attr = new ElementAttributes();
- attr.setMaxLifeSeconds( maxLife );
-
- access.setDefaultElementAttributes( attr );
-
- assertEquals( "Wrong element attributes.", attr.getMaxLifeSeconds(), access.getDefaultElementAttributes()
- .getMaxLifeSeconds() );
-
- String key = "mykey";
- String value = "myvalue";
-
- access.put( key, value );
-
- ICacheElement element = access.getCacheElement( key );
-
- assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes()
- .getMaxLifeSeconds() );
- }
-
- /**
- * Verify that we can get a region using the define region method.
- *
- * @throws Exception
- *
- */
- public void testRegionDefiniton()
- throws Exception
- {
- CacheAccess access = CacheAccess.defineRegion( "test" );
- assertNotNull( "We should have an access class", access );
- }
-
- /**
- * Verify that we can get a region using the define region method with cache attributes.
- *
- * @throws Exception
- *
- */
- public void testRegionDefinitonWithAttributes()
- throws Exception
- {
- ICompositeCacheAttributes ca = new CompositeCacheAttributes();
-
- long maxIdleTime = 8765;
- ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
-
- CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
- assertNotNull( "We should have an access class", access );
-
- ICompositeCacheAttributes ca2 = access.getCacheAttributes();
- assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
- }
-
- /**
- * Verify that we can get a region using the define region method with cache attributes and elemetn attributes.
- *
- * @throws Exception
- *
- */
- public void testRegionDefinitonWithBothAttributes()
- throws Exception
- {
- ICompositeCacheAttributes ca = new CompositeCacheAttributes();
-
- long maxIdleTime = 8765;
- ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
-
- long maxLife = 9876;
- IElementAttributes attr = new ElementAttributes();
- attr.setMaxLifeSeconds( maxLife );
-
- CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
- assertNotNull( "We should have an access class", access );
-
- ICompositeCacheAttributes ca2 = access.getCacheAttributes();
- assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
- }
-
-}
+package org.apache.jcs.access;
+
+/*
+ * 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.access.exception.CacheException;
+import org.apache.jcs.access.exception.ObjectExistsException;
+import org.apache.jcs.engine.CompositeCacheAttributes;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+
+/**
+ * Tests the methods of the cache access class from which the class JCS extends.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class CacheAccessUnitTest
+ extends TestCase
+{
+
+ /**
+ * Verify that we get an object exists exception if the item is in the
+ * cache.
+ *
+ */
+ public void testPutSafe()
+ {
+
+ CacheAccess access = null;
+ try
+ {
+ access = CacheAccess.getAccess( "test" );
+
+ assertNotNull( "We should have an access class", access );
+ }
+ catch ( CacheException e )
+ {
+ fail( "Shouldn't have received an error." + e.getMessage() );
+ }
+
+ String key = "mykey";
+ String value = "myvalue";
+
+ try
+ {
+ access.put( key, value );
+ }
+ catch ( CacheException e )
+ {
+ fail( "Should have been able to put " + e.getMessage() );
+ }
+ String returnedValue1 = (String) access.get( key );
+ assertEquals( "Wrong value returned.", value, returnedValue1 );
+
+ try
+ {
+ access.putSafe( key, "someothervalue" );
+ fail( "We should have received an eception since this key is alredy in the cache." );
+ }
+ catch ( CacheException e )
+ {
+ // e.printStackTrace();
+ // expected
+ assertTrue( "Wrong type of exception.", e instanceof ObjectExistsException );
+ assertTrue( "Should have the key in the error message.", e.getMessage().indexOf( "[" + key + "]" ) != -1 );
+ }
+
+ String returnedValue2 = (String) access.get( key );
+ assertEquals( "Wrong value returned. Shoudl still be the original.", value, returnedValue2 );
+ }
+
+ /**
+ * Try to put a null key and verify that we get an exception.
+ *
+ */
+ public void testPutNullKey()
+ {
+
+ CacheAccess access = null;
+ try
+ {
+ access = CacheAccess.getAccess( "test" );
+
+ assertNotNull( "We should have an access class", access );
+ }
+ catch ( CacheException e )
+ {
+ fail( "Shouldn't have received an error." + e.getMessage() );
+ }
+
+ String key = null;
+ String value = "myvalue";
+
+ try
+ {
+ access.put( key, value );
+ fail( "Should not have been able to put a null key." );
+ }
+ catch ( CacheException e )
+ {
+ // expected
+ assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
+ }
+ }
+
+ /**
+ * Try to put a null value and verify that we get an exception.
+ *
+ */
+ public void testPutNullValue()
+ {
+
+ CacheAccess access = null;
+ try
+ {
+ access = CacheAccess.getAccess( "test" );
+
+ assertNotNull( "We should have an access class", access );
+ }
+ catch ( CacheException e )
+ {
+ fail( "Shouldn't have received an error." + e.getMessage() );
+ }
+
+ String key = "myKey";
+ String value = null;
+
+ try
+ {
+ access.put( key, value );
+ fail( "Should not have been able to put a null object." );
+ }
+ catch ( CacheException e )
+ {
+ // expected
+ assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
+ }
+ }
+
+ /**
+ * Verify that elements that go in the region after this call takethe new
+ * attributes.
+ *
+ * @throws Exception
+ *
+ */
+ public void testSetDefaultElementAttributes()
+ throws Exception
+ {
+
+ CacheAccess access = null;
+
+ access = CacheAccess.getAccess( "test" );
+
+ assertNotNull( "We should have an access class", access );
+
+ long maxLife = 9876;
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( maxLife );
+
+ access.setDefaultElementAttributes( attr );
+
+ assertEquals( "Wrong element attributes.", attr.getMaxLifeSeconds(), access.getDefaultElementAttributes()
+ .getMaxLifeSeconds() );
+
+ String key = "mykey";
+ String value = "myvalue";
+
+ access.put( key, value );
+
+ ICacheElement element = access.getCacheElement( key );
+
+ assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes()
+ .getMaxLifeSeconds() );
+ }
+
+ /**
+ * Verify that we can get a region using the define region method.
+ *
+ * @throws Exception
+ *
+ */
+ public void testRegionDefiniton()
+ throws Exception
+ {
+ CacheAccess access = CacheAccess.defineRegion( "test" );
+ assertNotNull( "We should have an access class", access );
+ }
+
+ /**
+ * Verify that we can get a region using the define region method with cache attributes.
+ *
+ * @throws Exception
+ *
+ */
+ public void testRegionDefinitonWithAttributes()
+ throws Exception
+ {
+ ICompositeCacheAttributes ca = new CompositeCacheAttributes();
+
+ long maxIdleTime = 8765;
+ ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
+
+ CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
+ assertNotNull( "We should have an access class", access );
+
+ ICompositeCacheAttributes ca2 = access.getCacheAttributes();
+ assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
+ }
+
+ /**
+ * Verify that we can get a region using the define region method with cache attributes and elemetn attributes.
+ *
+ * @throws Exception
+ *
+ */
+ public void testRegionDefinitonWithBothAttributes()
+ throws Exception
+ {
+ ICompositeCacheAttributes ca = new CompositeCacheAttributes();
+
+ long maxIdleTime = 8765;
+ ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
+
+ long maxLife = 9876;
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( maxLife );
+
+ CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
+ assertNotNull( "We should have an access class", access );
+
+ ICompositeCacheAttributes ca2 = access.getCacheAttributes();
+ assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/access/SystemPropetyUnitTest.java Thu May 10 09:03:42 2007
@@ -1,63 +1,82 @@
-package org.apache.jcs.access;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.engine.control.CompositeCacheManager;
-
-/**
- * This test is for the system property usage in configuration values.
- *
- * @author Aaron Smuts
- *
- */
-public class SystemPropetyUnitTest
- extends TestCase
-{
-
- /**
- * Verify that we use a system property for a ${FOO} string in a value.
- *
- * @throws Exception
- *
- */
- public void testSystemPropertyInValueDelimeter()
- throws Exception
- {
-
- int maxMemory = 1234;
- System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
- System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_MAX_SIZE", String.valueOf( maxMemory ) );
-
- JCS.setConfigFilename( "/TestSystemProperties.ccf" );
-
- JCS cache = JCS.getInstance( "test1" );
- assertEquals( "We should have used the system property for the memory size", maxMemory, cache
- .getCacheAttributes().getMaxObjects() );
-
- }
-
- /**
- * Verify that we use a system property for a ${FOO} string in a value. We
- * define a propety in the cache.ccf file, but we do not have it as a system
- * property. The default value should be used, if one exists.
- *
- * @throws Exception
- *
- */
- public void testSystemPropertyMissingInValueDelimeter()
- throws Exception
- {
- System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
-
- CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance();
- mgr.configure( "/TestSystemProperties.ccf" );
-
- JCS cache = JCS.getInstance( "missing" );
- // TODO check against the actual default def
- assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes()
- .getMaxObjects() );
-
- }
-
-}
+package org.apache.jcs.access;
+
+/*
+ * 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.engine.control.CompositeCacheManager;
+
+/**
+ * This test is for the system property usage in configuration values.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class SystemPropetyUnitTest
+ extends TestCase
+{
+
+ /**
+ * Verify that we use a system property for a ${FOO} string in a value.
+ *
+ * @throws Exception
+ *
+ */
+ public void testSystemPropertyInValueDelimeter()
+ throws Exception
+ {
+
+ int maxMemory = 1234;
+ System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
+ System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_MAX_SIZE", String.valueOf( maxMemory ) );
+
+ JCS.setConfigFilename( "/TestSystemProperties.ccf" );
+
+ JCS cache = JCS.getInstance( "test1" );
+ assertEquals( "We should have used the system property for the memory size", maxMemory, cache
+ .getCacheAttributes().getMaxObjects() );
+
+ }
+
+ /**
+ * Verify that we use a system property for a ${FOO} string in a value. We
+ * define a propety in the cache.ccf file, but we do not have it as a system
+ * property. The default value should be used, if one exists.
+ *
+ * @throws Exception
+ *
+ */
+ public void testSystemPropertyMissingInValueDelimeter()
+ throws Exception
+ {
+ System.getProperties().setProperty( "MY_SYSTEM_PROPERTY_DISK_DIR", "system_set" );
+
+ CompositeCacheManager mgr = CompositeCacheManager.getUnconfiguredInstance();
+ mgr.configure( "/TestSystemProperties.ccf" );
+
+ JCS cache = JCS.getInstance( "missing" );
+ // TODO check against the actual default def
+ assertEquals( "We should have used the default property for the memory size", 100, cache.getCacheAttributes()
+ .getMaxObjects() );
+
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs.access;
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * 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
*
- * 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
*
- * 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.
+ * 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.BufferedReader;
@@ -34,9 +37,9 @@
/**
* Allows the user to run common cache commands from the command line for a test
* cache.
- *
+ *
* This also provide basic methods for use in unit tests.
- *
+ *
*/
public class TestCacheAccess
{
@@ -48,7 +51,7 @@
/**
* Construct and initialize the cachecontrol based on the config file.
- *
+ *
*/
public TestCacheAccess()
{
@@ -629,7 +632,7 @@
/**
* Test harness.
- *
+ *
* @param args
* The command line arguments
*/
@@ -651,7 +654,7 @@
/**
* Gets multiple items from the cache with keys of the form key1, key2, key3
* up to key[num].
- *
+ *
* @param num
* int
*/
@@ -688,7 +691,7 @@
/**
* Puts multiple items into the cache.
- *
+ *
* @param num
* int
*/
@@ -712,7 +715,7 @@
/**
* Removes multiple items from the cache.
- *
+ *
* @param num
* int
*/
@@ -738,7 +741,7 @@
* The random method performs numOps number of operations. The operations
* will be a mix of puts, gets, and removes. The key range will be from 0 to
* range.
- *
+ *
* @param range
* int The end of the key range.
* @param numOps
@@ -807,7 +810,7 @@
/**
* Sets the region to be used by test methods.
- *
+ *
* @param name
* String -- Name of region
*/
@@ -830,7 +833,7 @@
* The tester will print to the console if isSysOut is true, else it will
* log. It is false by default. When run via the main method, isSysOut will
* be set to true
- *
+ *
* @param s
* String to print or log
*/
@@ -880,7 +883,7 @@
/**
* Gets the attributeNames attribute of the TestCacheAccess class
- *
+ *
* @param groupName
*/
public void getAttributeNames( String groupName )
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java Thu May 10 09:03:42 2007
@@ -1,142 +1,161 @@
-package org.apache.jcs.admin;
-
-import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Test the admin bean that is used by the JCSAdmin.jsp
- *
- * @author Aaron Smuts
- *
- */
-public class AdminBeanUnitTest
- extends TestCase
-{
-
- /**
- * Create a test region and then verify that we get it from the list.
- *
- * @throws Exception
- *
- */
- public void testGetRegionInfo()
- throws Exception
- {
- String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
-
- cache.put( "key", "value" );
-
- JCSAdminBean admin = new JCSAdminBean();
-
- List regions = admin.buildCacheInfo();
-
- boolean foundRegion = false;
-
- Iterator it = regions.iterator();
- while ( it.hasNext() )
- {
- CacheRegionInfo info = (CacheRegionInfo) it.next();
- System.out.println( info );
-
- if ( info.getCache().getCacheName().equals( regionName ) )
- {
- foundRegion = true;
-
- assertTrue( "Byte count should be greater than 5.", info.getByteCount() > 5 );
-
- assertNotNull( "Should have stats.", info.getStats() );
- }
- }
-
- assertTrue( "Should have found the region we just created.", foundRegion );
- }
-
- /**
- * Put a value in a region and verify that it shows up.
- *
- * @throws Exception
- */
- public void testGetElementForRegionInfo()
- throws Exception
- {
- String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
-
- // clear the region
- cache.clear();
-
- String key = "myKey";
- cache.put( key, "value" );
-
- JCSAdminBean admin = new JCSAdminBean();
-
- List elements = admin.buildElementInfo( regionName );
-
- assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
-
- CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
- System.out.println( elementInfo );
- assertEquals( "Wrong key.", key, elementInfo.getKey() );
- }
-
- /**
- * Remove an item via the remove method.
- *
- * @throws Exception
- */
- public void testRemove()
- throws Exception
- {
- JCSAdminBean admin = new JCSAdminBean();
-
- String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
-
- // clear the region
- cache.clear();
- admin.clearRegion( regionName );
-
- String key = "myKey";
- cache.put( key, "value" );
-
- List elements = admin.buildElementInfo( regionName );
-
- assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
-
- CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
-
- assertEquals( "Wrong key.", key, elementInfo.getKey() );
-
- admin.removeItem( regionName, key );
-
- List elements2 = admin.buildElementInfo( regionName );
- assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
- }
-
- /**
- * Add an item toa region. Cal clear all and verify that it doesn't exist.
- *
- * @throws Exception
- */
- public void testClearAll()
- throws Exception
- {
- JCSAdminBean admin = new JCSAdminBean();
-
- String regionName = "myRegion";
- JCS cache = JCS.getInstance( regionName );
-
- String key = "myKey";
- cache.put( key, "value" );
-
- admin.clearAllRegions();
-
- List elements2 = admin.buildElementInfo( regionName );
- assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
- }
-}
+package org.apache.jcs.admin;
+
+/*
+ * 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.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/**
+ * Test the admin bean that is used by the JCSAdmin.jsp
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class AdminBeanUnitTest
+ extends TestCase
+{
+
+ /**
+ * Create a test region and then verify that we get it from the list.
+ *
+ * @throws Exception
+ *
+ */
+ public void testGetRegionInfo()
+ throws Exception
+ {
+ String regionName = "myRegion";
+ JCS cache = JCS.getInstance( regionName );
+
+ cache.put( "key", "value" );
+
+ JCSAdminBean admin = new JCSAdminBean();
+
+ List regions = admin.buildCacheInfo();
+
+ boolean foundRegion = false;
+
+ Iterator it = regions.iterator();
+ while ( it.hasNext() )
+ {
+ CacheRegionInfo info = (CacheRegionInfo) it.next();
+ System.out.println( info );
+
+ if ( info.getCache().getCacheName().equals( regionName ) )
+ {
+ foundRegion = true;
+
+ assertTrue( "Byte count should be greater than 5.", info.getByteCount() > 5 );
+
+ assertNotNull( "Should have stats.", info.getStats() );
+ }
+ }
+
+ assertTrue( "Should have found the region we just created.", foundRegion );
+ }
+
+ /**
+ * Put a value in a region and verify that it shows up.
+ *
+ * @throws Exception
+ */
+ public void testGetElementForRegionInfo()
+ throws Exception
+ {
+ String regionName = "myRegion";
+ JCS cache = JCS.getInstance( regionName );
+
+ // clear the region
+ cache.clear();
+
+ String key = "myKey";
+ cache.put( key, "value" );
+
+ JCSAdminBean admin = new JCSAdminBean();
+
+ List elements = admin.buildElementInfo( regionName );
+
+ assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
+
+ CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
+ System.out.println( elementInfo );
+ assertEquals( "Wrong key.", key, elementInfo.getKey() );
+ }
+
+ /**
+ * Remove an item via the remove method.
+ *
+ * @throws Exception
+ */
+ public void testRemove()
+ throws Exception
+ {
+ JCSAdminBean admin = new JCSAdminBean();
+
+ String regionName = "myRegion";
+ JCS cache = JCS.getInstance( regionName );
+
+ // clear the region
+ cache.clear();
+ admin.clearRegion( regionName );
+
+ String key = "myKey";
+ cache.put( key, "value" );
+
+ List elements = admin.buildElementInfo( regionName );
+
+ assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
+
+ CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
+
+ assertEquals( "Wrong key.", key, elementInfo.getKey() );
+
+ admin.removeItem( regionName, key );
+
+ List elements2 = admin.buildElementInfo( regionName );
+ assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
+ }
+
+ /**
+ * Add an item toa region. Cal clear all and verify that it doesn't exist.
+ *
+ * @throws Exception
+ */
+ public void testClearAll()
+ throws Exception
+ {
+ JCSAdminBean admin = new JCSAdminBean();
+
+ String regionName = "myRegion";
+ JCS cache = JCS.getInstance( regionName );
+
+ String key = "myKey";
+ cache.put( key, "value" );
+
+ admin.clearAllRegions();
+
+ List elements2 = admin.buildElementInfo( regionName );
+ assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java Thu May 10 09:03:42 2007
@@ -1,55 +1,74 @@
-package org.apache.jcs.admin;
-
-import junit.framework.TestCase;
-
-/**
- * Tests for the counting only output stream.
- *
- * @author Aaron Smuts
- *
- */
-public class CountingStreamUnitTest
- extends TestCase
-{
-
- /**
- * Write a single byte and verify the count.
- *
- * @throws Exception
- */
- public void testSingleByte() throws Exception
- {
- CountingOnlyOutputStream out = new CountingOnlyOutputStream();
- out.write( 1 );
- assertEquals( "Wrong number of bytes written.", 1, out.getCount() );
- out.write( 1 );
- assertEquals( "Wrong number of bytes written.", 2, out.getCount() );
- }
-
- /**
- * This should count the size of the array.
- *
- * @throws Exception
- */
- public void testByteArray() throws Exception
- {
- CountingOnlyOutputStream out = new CountingOnlyOutputStream();
- byte[] array = new byte[]{1,2,3,4,5};
- out.write( array );
- assertEquals( "Wrong number of bytes written.", array.length, out.getCount() );
- }
-
- /**
- * This should count the len -- the tird arg
- *
- * @throws Exception
- */
- public void testByteArrayLenCount() throws Exception
- {
- CountingOnlyOutputStream out = new CountingOnlyOutputStream();
- byte[] array = new byte[]{1,2,3,4,5};
- int len = 3;
- out.write( array, 0, len );
- assertEquals( "Wrong number of bytes written.", len, out.getCount() );
- }
-}
+package org.apache.jcs.admin;
+
+/*
+ * 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;
+
+/**
+ * Tests for the counting only output stream.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class CountingStreamUnitTest
+ extends TestCase
+{
+
+ /**
+ * Write a single byte and verify the count.
+ *
+ * @throws Exception
+ */
+ public void testSingleByte() throws Exception
+ {
+ CountingOnlyOutputStream out = new CountingOnlyOutputStream();
+ out.write( 1 );
+ assertEquals( "Wrong number of bytes written.", 1, out.getCount() );
+ out.write( 1 );
+ assertEquals( "Wrong number of bytes written.", 2, out.getCount() );
+ }
+
+ /**
+ * This should count the size of the array.
+ *
+ * @throws Exception
+ */
+ public void testByteArray() throws Exception
+ {
+ CountingOnlyOutputStream out = new CountingOnlyOutputStream();
+ byte[] array = new byte[]{1,2,3,4,5};
+ out.write( array );
+ assertEquals( "Wrong number of bytes written.", array.length, out.getCount() );
+ }
+
+ /**
+ * This should count the len -- the tird arg
+ *
+ * @throws Exception
+ */
+ public void testByteArrayLenCount() throws Exception
+ {
+ CountingOnlyOutputStream out = new CountingOnlyOutputStream();
+ byte[] array = new byte[]{1,2,3,4,5};
+ int len = 3;
+ out.write( array, 0, len );
+ assertEquals( "Wrong number of bytes written.", len, out.getCount() );
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org