Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java Thu May 10 09:03:42 2007
@@ -1,208 +1,227 @@
-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;
-
-/**
- * Tests the issue remove on put fuctionality.
- *
- * @author asmuts
- */
-public class LateralTCPIssueRemoveOnPutUnitTest
- extends TestCase
-{
- private static boolean isSysOut = true;
-
- /**
- * Constructor for the TestDiskCache object.
- *
- * @param testName
- */
- public LateralTCPIssueRemoveOnPutUnitTest( String testName )
- {
- super( testName );
- }
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestTCPLateralIssueRemoveCache.ccf" );
- }
-
- /**
- *
- * @throws Exception
- */
- public void testPutLocalPutRemoteGetBusyVerifyRemoved()
- throws Exception
- {
- this.runTestForRegion( "region1", 1, 200, 1 );
- }
-
- /**
- * Verify that a standard put works.
- *
- * Get the cache configured from a file. Create a tcp service to talk to
- * that cache. Put via the servive. Verify that the cache got the data.
- *
- * @throws Exception
- *
- */
- public void testStandardPut()
- throws Exception
- {
- String region = "region1";
-
- JCS cache = JCS.getInstance( region );
-
- Thread.sleep( 100 );
-
- TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1102 );
- lattr2.setTransmissionTypeName( "TCP" );
- lattr2.setTcpServer( "localhost:1110" );
- lattr2.setIssueRemoveOnPut( false );
- // should still try to remove
- // lattr2.setAllowPut( false );
-
- // Using the lateral, this service will put to and remove from
- // 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_notremoved";
-
- ICacheElement element1 = new CacheElement( region, keyToBeRemovedOnPut, region
- + ":data-this shouldn't get removed, it should get to the cache." );
- service.update( element1 );
-
- Thread.sleep( 1000 );
-
- Object testObj = cache.get( keyToBeRemovedOnPut );
- p( "testStandardPut, test object = " + testObj );
- assertNotNull( "The test object should not have been removed by a put.", testObj );
- }
-
- /**
- * 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 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 );
-
- 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 );
-
- // Using the lateral, this service will put to and remove from
- // 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";
- cache.put( keyToBeRemovedOnPut, "this should get removed." );
-
- ICacheElement element1 = new CacheElement( region, keyToBeRemovedOnPut, region
- + ":data-this shouldn't get there" );
- service.update( element1 );
-
- 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 testObj = cache.get( keyToBeRemovedOnPut );
- p( "runTestForRegion, test object = " + testObj );
- assertNull( "The test object should have been removed by a put.", testObj );
-
- }
-
- /**
- * @param s
- * String to be printed
- */
- 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.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Tests the issue remove on put fuctionality.
+ *
+ * @author asmuts
+ */
+public class LateralTCPIssueRemoveOnPutUnitTest
+ extends TestCase
+{
+ private static boolean isSysOut = true;
+
+ /**
+ * Constructor for the TestDiskCache object.
+ *
+ * @param testName
+ */
+ public LateralTCPIssueRemoveOnPutUnitTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestTCPLateralIssueRemoveCache.ccf" );
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testPutLocalPutRemoteGetBusyVerifyRemoved()
+ throws Exception
+ {
+ this.runTestForRegion( "region1", 1, 200, 1 );
+ }
+
+ /**
+ * Verify that a standard put works.
+ *
+ * Get the cache configured from a file. Create a tcp service to talk to
+ * that cache. Put via the servive. Verify that the cache got the data.
+ *
+ * @throws Exception
+ *
+ */
+ public void testStandardPut()
+ throws Exception
+ {
+ String region = "region1";
+
+ JCS cache = JCS.getInstance( region );
+
+ Thread.sleep( 100 );
+
+ TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort( 1102 );
+ lattr2.setTransmissionTypeName( "TCP" );
+ lattr2.setTcpServer( "localhost:1110" );
+ lattr2.setIssueRemoveOnPut( false );
+ // should still try to remove
+ // lattr2.setAllowPut( false );
+
+ // Using the lateral, this service will put to and remove from
+ // 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_notremoved";
+
+ ICacheElement element1 = new CacheElement( region, keyToBeRemovedOnPut, region
+ + ":data-this shouldn't get removed, it should get to the cache." );
+ service.update( element1 );
+
+ Thread.sleep( 1000 );
+
+ Object testObj = cache.get( keyToBeRemovedOnPut );
+ p( "testStandardPut, test object = " + testObj );
+ assertNotNull( "The test object should not have been removed by a put.", testObj );
+ }
+
+ /**
+ * 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 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 );
+
+ 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 );
+
+ // Using the lateral, this service will put to and remove from
+ // 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";
+ cache.put( keyToBeRemovedOnPut, "this should get removed." );
+
+ ICacheElement element1 = new CacheElement( region, keyToBeRemovedOnPut, region
+ + ":data-this shouldn't get there" );
+ service.update( element1 );
+
+ 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 testObj = cache.get( keyToBeRemovedOnPut );
+ p( "runTestForRegion, test object = " + testObj );
+ assertNull( "The test object should have been removed by a put.", testObj );
+
+ }
+
+ /**
+ * @param s
+ * String to be printed
+ */
+ public static void p( String s )
+ {
+ if ( isSysOut )
+ {
+ System.out.println( s );
+ }
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPNoDeadLockConcurrentTest.java Thu May 10 09:03:42 2007
@@ -1,137 +1,140 @@
-package org.apache.jcs.auxiliary.lateral.socket.tcp;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License")
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import junit.extensions.ActiveTestSuite;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-import org.apache.jcs.engine.control.CompositeCacheManager;
-
-/**
- * Test which exercises the tcp lateral cache. Runs two threads against the
- * same region and two against other regions.
- */
-public class LateralTCPNoDeadLockConcurrentTest
- extends TestCase
-{
- /**
- * Constructor for the TestDiskCache object.
- *
- * @param testName
- */
- public LateralTCPNoDeadLockConcurrentTest( String testName )
- {
- super( testName );
- }
-
- /**
- * Main method passes this test to the text test runner.
- *
- * @param args
- */
- public static void main( String args[] )
- {
- String[] testCaseName = { LateralTCPNoDeadLockConcurrentTest.class.getName() };
- junit.textui.TestRunner.main( testCaseName );
- }
-
- /**
- * A unit test suite for JUnit
- *
- * @return The test suite
- */
- public static Test suite()
- {
-
- System.setProperty( "jcs.auxiliary.LTCP.attributes.PutOnlyMode", "false" );
-
- ActiveTestSuite suite = new ActiveTestSuite();
-
- suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache1" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "region1", 1, 200, 1 );
- }
- } );
-
- suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache2" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "region2", 10000, 12000, 2 );
- }
- } );
-
- suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache3" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "region3", 10000, 12000, 3 );
- }
- } );
-
- suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache4" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "region3", 10000, 13000, 4 );
- }
- } );
-
- suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache5" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "region4", 10000, 11000, 5 );
- }
- } );
-
- return suite;
- }
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestTCPLateralCacheConcurrent.ccf" );
- }
-
- /**
- * Test tearDown. Dispose of the cache.
- */
- public void tearDown()
- {
- try
- {
- CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
- cacheMgr.shutDown();
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- }
-}
+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 junit.extensions.ActiveTestSuite;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.control.CompositeCacheManager;
+
+/**
+ * Test which exercises the tcp lateral cache. Runs two threads against the
+ * same region and two against other regions.
+ */
+public class LateralTCPNoDeadLockConcurrentTest
+ extends TestCase
+{
+ /**
+ * Constructor for the TestDiskCache object.
+ *
+ * @param testName
+ */
+ public LateralTCPNoDeadLockConcurrentTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Main method passes this test to the text test runner.
+ *
+ * @param args
+ */
+ public static void main( String args[] )
+ {
+ String[] testCaseName = { LateralTCPNoDeadLockConcurrentTest.class.getName() };
+ junit.textui.TestRunner.main( testCaseName );
+ }
+
+ /**
+ * A unit test suite for JUnit
+ *
+ * @return The test suite
+ */
+ public static Test suite()
+ {
+
+ System.setProperty( "jcs.auxiliary.LTCP.attributes.PutOnlyMode", "false" );
+
+ ActiveTestSuite suite = new ActiveTestSuite();
+
+ suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache1" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "region1", 1, 200, 1 );
+ }
+ } );
+
+ suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache2" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "region2", 10000, 12000, 2 );
+ }
+ } );
+
+ suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache3" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "region3", 10000, 12000, 3 );
+ }
+ } );
+
+ suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache4" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "region3", 10000, 13000, 4 );
+ }
+ } );
+
+ suite.addTest( new LateralTCPConcurrentRandomTestUtil( "testLateralTCPCache5" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "region4", 10000, 11000, 5 );
+ }
+ } );
+
+ return suite;
+ }
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestTCPLateralCacheConcurrent.ccf" );
+ }
+
+ /**
+ * Test tearDown. Dispose of the cache.
+ */
+ public void tearDown()
+ {
+ try
+ {
+ CompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
+ cacheMgr.shutDown();
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
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 junit.framework.TestCase;
import org.apache.jcs.JCS;
@@ -14,9 +33,9 @@
/**
* Basic unit tests for the sending and receiving portions of the lateral cache.
- *
+ *
* @author Aaron Smuts
- *
+ *
*/
public class TestTCPLateralUnitTest
extends TestCase
@@ -76,7 +95,7 @@
}
/**
- *
+ *
* @throws Exception
*/
public void testReceive()
@@ -98,7 +117,7 @@
//nowait1.update( );
// start the listener
- //LateralTCPListener listener = (LateralTCPListener)
+ //LateralTCPListener listener = (LateralTCPListener)
LateralTCPListener.getInstance( lattr, cacheMgr );
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
@@ -138,7 +157,7 @@
// get the listener started
// give it our mock cache manager
- //LateralTCPListener listener = (LateralTCPListener)
+ //LateralTCPListener listener = (LateralTCPListener)
LateralTCPListener.getInstance( lattr, cacheMgr );
// setup a service to talk to the listener started above.
@@ -164,7 +183,7 @@
assertEquals( "Didn't get the correct object", element2.getVal(), cacheElement.getVal() );
}
-
+
/**
* Send objects with the same key but different values.
* @throws Exception
@@ -180,7 +199,7 @@
// get the listener started
// give it our mock cache manager
- //LateralTCPListener listener = (LateralTCPListener)
+ //LateralTCPListener listener = (LateralTCPListener)
LateralTCPListener.getInstance( lattr, cacheMgr );
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
@@ -206,7 +225,7 @@
System.out.println( "cacheElement = " + cacheElement );
assertEquals( "Didn't get the correct object", element2.getVal(), cacheElement.getVal() );
}
-
+
/**
* Create a listener. Add an element to the listeners cache. Setup a service. Try to get from the service.
* <p>
@@ -223,13 +242,13 @@
// get the listener started
// give it our mock cache manager
- //LateralTCPListener listener = (LateralTCPListener)
+ //LateralTCPListener listener = (LateralTCPListener)
LateralTCPListener.getInstance( lattr, cacheMgr );
// add the item to the listeners cache
ICacheElement element = new CacheElement( "test", "key", "value1" );
cacheMgr.getCache().update( element );
-
+
// setup a service to talk to the listener started above.
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
lattr2.setTcpListenerPort( 1108 );
@@ -246,5 +265,5 @@
System.out.println( "testSendAndReceived, result = " + result );
assertNotNull( "Result should not be null.", result );
assertEquals( "Didn't get the correct object", element.getVal(), result.getVal() );
- }
+ }
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
package org.apache.jcs.auxiliary.lateral.socket.tcp.discovery;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
import java.io.IOException;
import java.io.Serializable;
@@ -10,9 +29,9 @@
/**
* For testing things that need a lateral cache
- *
+ *
* @author Aaron Smuts
- *
+ *
*/
public class MockLateralCache
extends LateralCache
@@ -30,7 +49,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#update(org.apache.jcs.engine.behavior.ICacheElement)
*/
public void update( ICacheElement ce )
@@ -42,7 +61,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#get(java.io.Serializable)
*/
public ICacheElement get( Serializable key )
@@ -54,7 +73,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#remove(java.io.Serializable)
*/
public boolean remove( Serializable key )
@@ -66,7 +85,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#removeAll()
*/
public void removeAll()
@@ -78,7 +97,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#dispose()
*/
public void dispose()
@@ -90,7 +109,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#getSize()
*/
public int getSize()
@@ -101,7 +120,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#getStatus()
*/
public int getStatus()
@@ -112,7 +131,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#getStats()
*/
public String getStats()
@@ -123,7 +142,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICache#getCacheName()
*/
public String getCacheName()
@@ -133,7 +152,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
*/
public int getCacheType()
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java Thu May 10 09:03:42 2007
@@ -1,5 +1,24 @@
package org.apache.jcs.auxiliary.lateral.socket.tcp.discovery;
+/*
+ * 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 junit.framework.TestCase;
@@ -15,9 +34,9 @@
import org.apache.jcs.engine.control.CompositeCacheManager;
/**
- *
+ *
* @author Aaron Smuts
- *
+ *
*/
public class UDPDiscoveryUnitTest
extends TestCase
@@ -52,7 +71,7 @@
* 9. check to see that we got 10 messages
* <p>
* 10. check to see if the testCache1 facade got a nowait.
- *
+ *
* @throws Exception
*/
public void testSimpleUDPDiscovery()
@@ -64,7 +83,7 @@
lac.setTcpServer( "localhost" + ":" + 1111 );
ICompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
-
+
// create the service
UDPDiscoveryService service = new UDPDiscoveryService( lac.getUdpDiscoveryAddr(), lac.getUdpDiscoveryPort(), lac.getTcpListenerPort(), cacheMgr );
service.setTcpLateralCacheAttributes( lac );
@@ -73,7 +92,7 @@
ArrayList noWaits = new ArrayList();
ILateralCacheAttributes attr = new LateralCacheAttributes();
attr.setCacheName( "testCache1" );
-
+
LateralCacheNoWaitFacade lcnwf = new LateralCacheNoWaitFacade( (LateralCacheNoWait[]) noWaits
.toArray( new LateralCacheNoWait[0] ), attr );
@@ -131,7 +150,7 @@
/**
* Verify that the config does not throw any errors.
- *
+ *
* @throws Exception
*/
public void testUDPDiscoveryConfig()
@@ -157,7 +176,7 @@
{
ArrayList noWaits = new ArrayList();
ILateralCacheAttributes attr = new LateralCacheAttributes();
- attr.setCacheName( "testCache1" );
+ attr.setCacheName( "testCache1" );
LateralCacheNoWaitFacade lcnwf = new LateralCacheNoWaitFacade( (LateralCacheNoWait[]) noWaits
.toArray( new LateralCacheNoWait[0] ), attr );
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientMockImpl.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientMockImpl.java Thu May 10 09:03:42 2007
@@ -1,240 +1,250 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache License, Version
- * 2.0 (the "License") you may not use this file except in compliance with the License. You may
- * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- * applicable law or agreed to in writing, software distributed under the License is distributed on
- * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
- * the License for the specific language governing permissions and limitations under the License.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient;
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
-import org.apache.jcs.engine.CacheConstants;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.stats.behavior.IStats;
-
-/**
- * Used for testing the no wait.
- * <p>
- * @author Aaron Smuts
- */
-public class RemoteCacheClientMockImpl
- implements IRemoteCacheClient
-{
- private static final long serialVersionUID = 1L;
-
- private final static Log log = LogFactory.getLog( RemoteCacheClientMockImpl.class );
-
- /**
- * List of ICacheElement objects passed into update.
- */
- public List updateList = new LinkedList();
-
- /**
- * List of key objects passed into remove.
- */
- public List removeList = new LinkedList();
-
- /** status to return. */
- public int status = CacheConstants.STATUS_ALIVE;
-
- /** Can setup values to return from get. values must be ICacheElement */
- public Map getSetupMap = new HashMap();
-
- /**
- * The last service passed to fixCache
- */
- public IRemoteCacheService fixed;
-
- /**
- * Attributes.
- */
- public RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-
- /**
- * Stores the last argument as fixed.
- * <p>
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient#fixCache(org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService)
- */
- public void fixCache( IRemoteCacheService remote )
- {
- fixed = remote;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient#getListenerId()
- */
- public long getListenerId()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient#getListener()
- */
- public IRemoteCacheListener getListener()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * Adds the argument to the updatedList.
- * <p>
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
- */
- public void update( ICacheElement ce )
- throws IOException
- {
- updateList.add( ce );
- }
-
- /**
- * Looks in the getSetupMap for a value.
- * <p>
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#get(java.io.Serializable)
- */
- public ICacheElement get( Serializable key )
- throws IOException
- {
- log.info( "get [" + key + "]" );
- return (ICacheElement) getSetupMap.get( key );
- }
-
- /**
- * Adds the key to the remove list.
- * <p>
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#remove(java.io.Serializable)
- */
- public boolean remove( Serializable key )
- throws IOException
- {
- removeList.add( key );
- return false;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#removeAll()
- */
- public void removeAll()
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#dispose()
- */
- public void dispose()
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getSize()
- */
- public int getSize()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- /**
- * Returns the status setup variable. (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatus()
- */
- public int getStatus()
- {
- return status;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getCacheName()
- */
- public String getCacheName()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
- */
- public Set getGroupKeys( String group )
- throws IOException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
- */
- public IStats getStatistics()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * Returns the setup attributes. By default they are not null.
- * <p>
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getAuxiliaryCacheAttributes()
- */
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return attributes;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICache#getStats()
- */
- public String getStats()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
- */
- public int getCacheType()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService;
+import org.apache.jcs.engine.CacheConstants;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
+/**
+ * Used for testing the no wait.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class RemoteCacheClientMockImpl
+ implements IRemoteCacheClient
+{
+ private static final long serialVersionUID = 1L;
+
+ private final static Log log = LogFactory.getLog( RemoteCacheClientMockImpl.class );
+
+ /**
+ * List of ICacheElement objects passed into update.
+ */
+ public List updateList = new LinkedList();
+
+ /**
+ * List of key objects passed into remove.
+ */
+ public List removeList = new LinkedList();
+
+ /** status to return. */
+ public int status = CacheConstants.STATUS_ALIVE;
+
+ /** Can setup values to return from get. values must be ICacheElement */
+ public Map getSetupMap = new HashMap();
+
+ /**
+ * The last service passed to fixCache
+ */
+ public IRemoteCacheService fixed;
+
+ /**
+ * Attributes.
+ */
+ public RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+
+ /**
+ * Stores the last argument as fixed.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient#fixCache(org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheService)
+ */
+ public void fixCache( IRemoteCacheService remote )
+ {
+ fixed = remote;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient#getListenerId()
+ */
+ public long getListenerId()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient#getListener()
+ */
+ public IRemoteCacheListener getListener()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Adds the argument to the updatedList.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
+ */
+ public void update( ICacheElement ce )
+ throws IOException
+ {
+ updateList.add( ce );
+ }
+
+ /**
+ * Looks in the getSetupMap for a value.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#get(java.io.Serializable)
+ */
+ public ICacheElement get( Serializable key )
+ throws IOException
+ {
+ log.info( "get [" + key + "]" );
+ return (ICacheElement) getSetupMap.get( key );
+ }
+
+ /**
+ * Adds the key to the remove list.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#remove(java.io.Serializable)
+ */
+ public boolean remove( Serializable key )
+ throws IOException
+ {
+ removeList.add( key );
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#removeAll()
+ */
+ public void removeAll()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#dispose()
+ */
+ public void dispose()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getSize()
+ */
+ public int getSize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /**
+ * Returns the status setup variable. (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatus()
+ */
+ public int getStatus()
+ {
+ return status;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getCacheName()
+ */
+ public String getCacheName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
+ */
+ public Set getGroupKeys( String group )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
+ */
+ public IStats getStatistics()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Returns the setup attributes. By default they are not null.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getAuxiliaryCacheAttributes()
+ */
+ public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
+ {
+ return attributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICache#getStats()
+ */
+ public String getStats()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
+ */
+ public int getCacheType()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheClientTester.java Thu May 10 09:03:42 2007
@@ -1,19 +1,22 @@
package org.apache.jcs.auxiliary.remote;
/*
- * Copyright 2002-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.IOException;
@@ -36,7 +39,7 @@
/**
* Description of the Class
- *
+ *
* @author asmuts
* @created January 15, 2002
*/
@@ -61,7 +64,7 @@
/**
* Gets the remoteType attribute of the RemoteCacheClientTest object
- *
+ *
* @return The remoteType value
*/
public int getRemoteType()
@@ -72,7 +75,7 @@
/**
* Constructor for the RemoteCacheClientTest object
- *
+ *
* @param count
* @exception MalformedURLException
* @exception NotBoundException
@@ -86,7 +89,7 @@
/**
* Constructor for the RemoteCacheClientTest object
- *
+ *
* @param count
* @param write
* @param read
@@ -103,7 +106,7 @@
/**
* Constructor for the RemoteCacheClientTest object
- *
+ *
* @param host
* @param port
* @param count
@@ -230,10 +233,10 @@
*/
/**
* The main program for the RemoteCacheClientTest class
- *
+ *
* @param args
* The command line arguments
- * @throws Exception
+ * @throws Exception
*/
public static void main( String[] args )
throws Exception
@@ -270,7 +273,7 @@
/**
* Sets the listenerId attribute of the RemoteCacheClientTest object
- *
+ *
* @param id
* The new listenerId value
*/
@@ -283,7 +286,7 @@
/**
* Gets the listenerId attribute of the RemoteCacheClientTest object
- *
+ *
* @return The listenerId value
*/
public long getListenerId()
@@ -292,7 +295,7 @@
return listenerId;
}
- /** Helper for output, this is an user run test class
+ /** Helper for output, this is an user run test class
* @param s
*/
private static void p( String s )
@@ -314,6 +317,6 @@
throws IOException
{
// TODO Auto-generated method stub
-
+
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerMockImpl.java Thu May 10 09:03:42 2007
@@ -1,123 +1,131 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * For testing.
- * <p>
- * @author Aaron Smuts
- */
-public class RemoteCacheListenerMockImpl
- implements IRemoteCacheListener
-{
- /** Setup the listener id that this will return. */
- private long listenerId;
-
- /** Number of times handlePut was called. */
- public int putCount;
-
- /** List of ICacheElements passed to handlePut. */
- public List putItems = new LinkedList();
-
- /** List of Serializable objects passed to handleRemove. */
- public List removedKeys = new LinkedList();
-
- /** Number of times handleRemote was called. */
- public int removeCount;
-
- /** The type of remote listener */
- public int remoteType = IRemoteCacheAttributes.LOCAL;
-
- public void dispose()
- throws IOException
- {
- // TODO Auto-generated method stub
- }
-
- /**
- * returns the listener id, which can be setup.
- */
- public long getListenerId()
- throws IOException
- {
- return listenerId;
- }
-
- public String getLocalHostAddress()
- throws IOException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * Return the setup remoteType.
- */
- public int getRemoteType()
- throws IOException
- {
- return remoteType;
- }
-
- /**
- * Allows you to setup the listener id.
- */
- public void setListenerId( long id )
- throws IOException
- {
- listenerId = id;
- }
-
- public void handleDispose( String cacheName )
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * This increments the put count and adds the item to the putItem list.
- */
- public void handlePut( ICacheElement item )
- throws IOException
- {
- putCount++;
- this.putItems.add( item );
- }
-
- /**
- * Increments the remove count and adds the key to the removedKeys list.
- */
- public void handleRemove( String cacheName, Serializable key )
- throws IOException
- {
- removeCount++;
- removedKeys.add( key );
- }
-
- public void handleRemoveAll( String cacheName )
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
+import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * For testing.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class RemoteCacheListenerMockImpl
+ implements IRemoteCacheListener
+{
+ /** Setup the listener id that this will return. */
+ private long listenerId;
+
+ /** Number of times handlePut was called. */
+ public int putCount;
+
+ /** List of ICacheElements passed to handlePut. */
+ public List putItems = new LinkedList();
+
+ /** List of Serializable objects passed to handleRemove. */
+ public List removedKeys = new LinkedList();
+
+ /** Number of times handleRemote was called. */
+ public int removeCount;
+
+ /** The type of remote listener */
+ public int remoteType = IRemoteCacheAttributes.LOCAL;
+
+ public void dispose()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * returns the listener id, which can be setup.
+ */
+ public long getListenerId()
+ throws IOException
+ {
+ return listenerId;
+ }
+
+ public String getLocalHostAddress()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Return the setup remoteType.
+ */
+ public int getRemoteType()
+ throws IOException
+ {
+ return remoteType;
+ }
+
+ /**
+ * Allows you to setup the listener id.
+ */
+ public void setListenerId( long id )
+ throws IOException
+ {
+ listenerId = id;
+ }
+
+ public void handleDispose( String cacheName )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * This increments the put count and adds the item to the putItem list.
+ */
+ public void handlePut( ICacheElement item )
+ throws IOException
+ {
+ putCount++;
+ this.putItems.add( item );
+ }
+
+ /**
+ * Increments the remove count and adds the key to the removedKeys list.
+ */
+ public void handleRemove( String cacheName, Serializable key )
+ throws IOException
+ {
+ removeCount++;
+ removedKeys.add( key );
+ }
+
+ public void handleRemoveAll( String cacheName )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheListenerUnitTest.java Thu May 10 09:03:42 2007
@@ -1,94 +1,113 @@
-package org.apache.jcs.auxiliary.remote;
-
-import junit.framework.TestCase;
-
-import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
-import org.apache.jcs.engine.CacheElementSerialized;
-import org.apache.jcs.engine.ElementAttributes;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICacheElementSerialized;
-import org.apache.jcs.engine.behavior.ICompositeCacheManager;
-import org.apache.jcs.engine.behavior.IElementAttributes;
-import org.apache.jcs.engine.behavior.IElementSerializer;
-import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
-import org.apache.jcs.utils.serialization.StandardSerializer;
-
-/**
- * Tests for the remote cache listener.
- * <p>
- * @author Aaron Smuts
- *
- */
-public class RemoteCacheListenerUnitTest
- extends TestCase
-{
- /**
- * Create a RemoteCacheListener with a mock cache manager. Set remove on put to false.
- * Create a serialized element. Call put on the listener.
- * Verify that the deserialized element is in the cache.
- *
- * @throws Exception
- */
- public void testUpdate()
- throws Exception
- {
- IRemoteCacheAttributes irca = new RemoteCacheAttributes();
- irca.setRemoveUponRemotePut( false );
- ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
- RemoteCacheListener listener = new RemoteCacheListener( irca, cacheMgr );
-
- String cacheName = "testName";
- String key = "key";
- String value = "value fdsadf dsafdsa fdsaf dsafdsaf dsafdsaf dsaf dsaf dsaf dsafa dsaf dsaf dsafdsaf";
- IElementAttributes attr = new ElementAttributes();
- attr.setMaxLifeSeconds( 34 );
-
- IElementSerializer elementSerializer = new StandardSerializer();
-
- ICacheElementSerialized element = new CacheElementSerialized( cacheName, key, elementSerializer
- .serialize( value ), attr );
- listener.handlePut( element );
-
- ICacheElement after = cacheMgr.getCache( cacheName ).get( key );
-
- assertNotNull( "Should have a deserialized object.", after );
- assertEquals( "Values should be the same.", value, after.getVal() );
- assertEquals( "Attributes should be the same.", attr.getMaxLifeSeconds(), after
- .getElementAttributes().getMaxLifeSeconds() );
- assertEquals( "Keys should be the same.", key, after.getKey() );
- assertEquals( "Cache name should be the same.", cacheName, after.getCacheName() );
- }
-
- /**
- * Create a RemoteCacheListener with a mock cache manager. Set remove on put to false.
- * Create a serialized element. Call put on the listener.
- * Verify that the deserialized element is in the cache.
- *
- * @throws Exception
- */
- public void testUpdate_RemoveOnPut()
- throws Exception
- {
- IRemoteCacheAttributes irca = new RemoteCacheAttributes();
- irca.setRemoveUponRemotePut( true );
- ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
- RemoteCacheListener listener = new RemoteCacheListener( irca, cacheMgr );
-
- String cacheName = "testName";
- String key = "key";
- String value = "value fdsadf dsafdsa fdsaf dsafdsaf dsafdsaf dsaf dsaf dsaf dsafa dsaf dsaf dsafdsaf";
- IElementAttributes attr = new ElementAttributes();
- attr.setMaxLifeSeconds( 34 );
-
- IElementSerializer elementSerializer = new StandardSerializer();
-
- ICacheElementSerialized element = new CacheElementSerialized( cacheName, key, elementSerializer
- .serialize( value ), attr );
- listener.handlePut( element );
-
- ICacheElement after = cacheMgr.getCache( cacheName ).get( key );
-
- assertNull( "Should not have a deserialized object since remove on put is true.", after );
- }
-
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * 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.remote.behavior.IRemoteCacheAttributes;
+import org.apache.jcs.engine.CacheElementSerialized;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheElementSerialized;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+import org.apache.jcs.engine.behavior.IElementSerializer;
+import org.apache.jcs.engine.control.CompositeCacheManagerMockImpl;
+import org.apache.jcs.utils.serialization.StandardSerializer;
+
+/**
+ * Tests for the remote cache listener.
+ * <p>
+ * @author Aaron Smuts
+ *
+ */
+public class RemoteCacheListenerUnitTest
+ extends TestCase
+{
+ /**
+ * Create a RemoteCacheListener with a mock cache manager. Set remove on put to false.
+ * Create a serialized element. Call put on the listener.
+ * Verify that the deserialized element is in the cache.
+ *
+ * @throws Exception
+ */
+ public void testUpdate()
+ throws Exception
+ {
+ IRemoteCacheAttributes irca = new RemoteCacheAttributes();
+ irca.setRemoveUponRemotePut( false );
+ ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
+ RemoteCacheListener listener = new RemoteCacheListener( irca, cacheMgr );
+
+ String cacheName = "testName";
+ String key = "key";
+ String value = "value fdsadf dsafdsa fdsaf dsafdsaf dsafdsaf dsaf dsaf dsaf dsafa dsaf dsaf dsafdsaf";
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( 34 );
+
+ IElementSerializer elementSerializer = new StandardSerializer();
+
+ ICacheElementSerialized element = new CacheElementSerialized( cacheName, key, elementSerializer
+ .serialize( value ), attr );
+ listener.handlePut( element );
+
+ ICacheElement after = cacheMgr.getCache( cacheName ).get( key );
+
+ assertNotNull( "Should have a deserialized object.", after );
+ assertEquals( "Values should be the same.", value, after.getVal() );
+ assertEquals( "Attributes should be the same.", attr.getMaxLifeSeconds(), after
+ .getElementAttributes().getMaxLifeSeconds() );
+ assertEquals( "Keys should be the same.", key, after.getKey() );
+ assertEquals( "Cache name should be the same.", cacheName, after.getCacheName() );
+ }
+
+ /**
+ * Create a RemoteCacheListener with a mock cache manager. Set remove on put to false.
+ * Create a serialized element. Call put on the listener.
+ * Verify that the deserialized element is in the cache.
+ *
+ * @throws Exception
+ */
+ public void testUpdate_RemoveOnPut()
+ throws Exception
+ {
+ IRemoteCacheAttributes irca = new RemoteCacheAttributes();
+ irca.setRemoveUponRemotePut( true );
+ ICompositeCacheManager cacheMgr = new CompositeCacheManagerMockImpl();
+ RemoteCacheListener listener = new RemoteCacheListener( irca, cacheMgr );
+
+ String cacheName = "testName";
+ String key = "key";
+ String value = "value fdsadf dsafdsa fdsaf dsafdsaf dsafdsaf dsaf dsaf dsaf dsafa dsaf dsaf dsafdsaf";
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( 34 );
+
+ IElementSerializer elementSerializer = new StandardSerializer();
+
+ ICacheElementSerialized element = new CacheElementSerialized( cacheName, key, elementSerializer
+ .serialize( value ), attr );
+ listener.handlePut( element );
+
+ ICacheElement after = cacheMgr.getCache( cacheName ).get( key );
+
+ assertNull( "Should not have a deserialized object since remove on put is true.", after );
+ }
+
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitUnitTest.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/RemoteCacheNoWaitUnitTest.java Thu May 10 09:03:42 2007
@@ -1,172 +1,182 @@
-package org.apache.jcs.auxiliary.remote;
-
-/*
- * 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.engine.CacheConstants;
-import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.behavior.ICacheEventQueue;
-import org.apache.jcs.utils.timing.SleepUtil;
-
-/**
- * Unit tests for the remote cache no wait. The no wait manages a queue on top of the client.
- * <p>
- * @author Aaron Smuts
- */
-public class RemoteCacheNoWaitUnitTest
- extends TestCase
-{
- /**
- * Simply verify that the client gets updated via the no wait.
- * <p>
- * @throws Exception
- */
- public void testUpdate()
- throws Exception
- {
- // SETUP
- RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
- RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
-
- ICacheElement element = new CacheElement( "testUpdate", "key", "value" );
-
- // DO WORK
- noWait.update( element );
-
- SleepUtil.sleepAtLeast( 10 );
-
- // VERIFY
- assertEquals( "Wrong number updated.", 1, client.updateList.size() );
- assertEquals( "Wrong element", element, client.updateList.get( 0 ) );
- }
-
- /**
- * Simply verify that the client get is called from the no wait.
- * <p>
- * @throws Exception
- */
- public void testGet()
- throws Exception
- {
- // SETUP
- RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
- RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
-
- ICacheElement input = new CacheElement( "testUpdate", "key", "value" );
- client.getSetupMap.put( "key", input );
-
- // DO WORK
- ICacheElement result = noWait.get( "key" );
-
- // VERIFY
- assertEquals( "Wrong element", input, result );
- }
-
- /**
- * Simply verify that the client gets updated via the no wait.
- * <p>
- * @throws Exception
- */
- public void testRemove()
- throws Exception
- {
- // SETUP
- RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
- RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
-
- String input = "MyKey";
-
- // DO WORK
- noWait.remove( input );
-
- SleepUtil.sleepAtLeast( 10 );
-
- // VERIFY
- assertEquals( "Wrong number updated.", 1, client.removeList.size() );
- assertEquals( "Wrong key", input, client.removeList.get( 0 ) );
- }
-
- /**
- * Simply verify that the client status is returned in the stats.
- * <p>
- * @throws Exception
- */
- public void testGetStats()
- throws Exception
- {
- // SETUP
- RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
- client.status = CacheConstants.STATUS_ALIVE;
- RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
-
- // DO WORK
- String result = noWait.getStats();
-
- // VERIFY
- assertTrue( "Status should contain 'ALIVE'", result.indexOf( "ALIVE" ) != -1 );
- }
-
- /**
- * Simply verify that we get a status of error if the cache is in error..
- * <p>
- * @throws Exception
- */
- public void testGetStatus_error()
- throws Exception
- {
- // SETUP
- RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
- client.status = CacheConstants.STATUS_ERROR;
- RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
-
- // DO WORK
- int result = noWait.getStatus();
-
- // VERIFY
- assertEquals( "Wrong status", CacheConstants.STATUS_ERROR, result );
- }
-
- /**
- * Simply verify that the serviced supplied to fix is passed onto the client. Verify that the
- * original event queue is destroyed. A new event queue willbe plugged in on fix.
- * <p>
- * @throws Exception
- */
- public void testFixCache()
- throws Exception
- {
- // SETUP
- RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
- client.status = CacheConstants.STATUS_ALIVE;
- RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
-
- RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
-
- ICacheElement element = new CacheElement( "testUpdate", "key", "value" );
-
- // DO WORK
- noWait.update( element );
- SleepUtil.sleepAtLeast( 10 );
- ICacheEventQueue originalQueue = noWait.getCacheEventQueue();
-
- noWait.fixCache( service );
-
- noWait.update( element );
- SleepUtil.sleepAtLeast( 10 );
- ICacheEventQueue newQueue = noWait.getCacheEventQueue();
-
- // VERIFY
- assertEquals( "Wrong status", service, client.fixed );
- assertFalse( "Original queue should not alive", originalQueue.isAlive() );
- assertTrue( "New queue should be alive." + newQueue, newQueue.isAlive() );
- }
-}
+package org.apache.jcs.auxiliary.remote;
+
+/*
+ * 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.engine.CacheConstants;
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICacheEventQueue;
+import org.apache.jcs.utils.timing.SleepUtil;
+
+/**
+ * Unit tests for the remote cache no wait. The no wait manages a queue on top of the client.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class RemoteCacheNoWaitUnitTest
+ extends TestCase
+{
+ /**
+ * Simply verify that the client gets updated via the no wait.
+ * <p>
+ * @throws Exception
+ */
+ public void testUpdate()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
+ RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
+
+ ICacheElement element = new CacheElement( "testUpdate", "key", "value" );
+
+ // DO WORK
+ noWait.update( element );
+
+ SleepUtil.sleepAtLeast( 10 );
+
+ // VERIFY
+ assertEquals( "Wrong number updated.", 1, client.updateList.size() );
+ assertEquals( "Wrong element", element, client.updateList.get( 0 ) );
+ }
+
+ /**
+ * Simply verify that the client get is called from the no wait.
+ * <p>
+ * @throws Exception
+ */
+ public void testGet()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
+ RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
+
+ ICacheElement input = new CacheElement( "testUpdate", "key", "value" );
+ client.getSetupMap.put( "key", input );
+
+ // DO WORK
+ ICacheElement result = noWait.get( "key" );
+
+ // VERIFY
+ assertEquals( "Wrong element", input, result );
+ }
+
+ /**
+ * Simply verify that the client gets updated via the no wait.
+ * <p>
+ * @throws Exception
+ */
+ public void testRemove()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
+ RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
+
+ String input = "MyKey";
+
+ // DO WORK
+ noWait.remove( input );
+
+ SleepUtil.sleepAtLeast( 10 );
+
+ // VERIFY
+ assertEquals( "Wrong number updated.", 1, client.removeList.size() );
+ assertEquals( "Wrong key", input, client.removeList.get( 0 ) );
+ }
+
+ /**
+ * Simply verify that the client status is returned in the stats.
+ * <p>
+ * @throws Exception
+ */
+ public void testGetStats()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
+ client.status = CacheConstants.STATUS_ALIVE;
+ RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
+
+ // DO WORK
+ String result = noWait.getStats();
+
+ // VERIFY
+ assertTrue( "Status should contain 'ALIVE'", result.indexOf( "ALIVE" ) != -1 );
+ }
+
+ /**
+ * Simply verify that we get a status of error if the cache is in error..
+ * <p>
+ * @throws Exception
+ */
+ public void testGetStatus_error()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
+ client.status = CacheConstants.STATUS_ERROR;
+ RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
+
+ // DO WORK
+ int result = noWait.getStatus();
+
+ // VERIFY
+ assertEquals( "Wrong status", CacheConstants.STATUS_ERROR, result );
+ }
+
+ /**
+ * Simply verify that the serviced supplied to fix is passed onto the client. Verify that the
+ * original event queue is destroyed. A new event queue willbe plugged in on fix.
+ * <p>
+ * @throws Exception
+ */
+ public void testFixCache()
+ throws Exception
+ {
+ // SETUP
+ RemoteCacheClientMockImpl client = new RemoteCacheClientMockImpl();
+ client.status = CacheConstants.STATUS_ALIVE;
+ RemoteCacheNoWait noWait = new RemoteCacheNoWait( client );
+
+ RemoteCacheServiceMockImpl service = new RemoteCacheServiceMockImpl();
+
+ ICacheElement element = new CacheElement( "testUpdate", "key", "value" );
+
+ // DO WORK
+ noWait.update( element );
+ SleepUtil.sleepAtLeast( 10 );
+ ICacheEventQueue originalQueue = noWait.getCacheEventQueue();
+
+ noWait.fixCache( service );
+
+ noWait.update( element );
+ SleepUtil.sleepAtLeast( 10 );
+ ICacheEventQueue newQueue = noWait.getCacheEventQueue();
+
+ // VERIFY
+ assertEquals( "Wrong status", service, client.fixed );
+ assertFalse( "Original queue should not alive", originalQueue.isAlive() );
+ assertTrue( "New queue should be alive." + newQueue, newQueue.isAlive() );
+ }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.