logo       


svn commit: r437083 - /jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/: msg#00066

Subject: svn commit: r437083 - /jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
Author: asmuts
Date: Fri Aug 25 21:59:44 2006
New Revision: 437083

URL: http://svn.apache.org/viewvc?rev=437083&view=rev
Log:
adding unit test

Modified:
    
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java

Modified: 
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java?rev=437083&r1=437082&r2=437083&view=diff
==============================================================================
--- 
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
 (original)
+++ 
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
 Fri Aug 25 21:59:44 2006
@@ -13,6 +13,7 @@
 
 import org.apache.jcs.auxiliary.AuxiliaryCache;
 import org.apache.jcs.auxiliary.remote.RemoteCacheAttributes;
+import org.apache.jcs.auxiliary.remote.RemoteCacheListenerMockImpl;
 import org.apache.jcs.auxiliary.remote.RemoteCacheManager;
 import org.apache.jcs.engine.CacheElement;
 import org.apache.jcs.engine.behavior.ICacheElement;
@@ -27,6 +28,16 @@
 public class BasicRemoteCacheClientServerUnitTest
     extends TestCase
 {
+    RemoteCacheServer server = null;
+
+    /**
+     * Starts the server. This is not in a setup, since the server is slow to 
kill right now.
+     */
+    public BasicRemoteCacheClientServerUnitTest()
+    {
+        String configFile = "TestRemoteCacheClientServer.ccf";
+        server = RemoteCacheServerStartupUtil.startServerUsingProperties( 
configFile );
+    }
 
     /**
      * Verify that we can start the remote cache server. Send an item to the 
remote. Verify that the
@@ -44,9 +55,6 @@
         throws Exception
     {
         // SETUP
-        String configFile = "TestRemoteCacheClientServer.ccf";
-        RemoteCacheServer server = 
RemoteCacheServerStartupUtil.startServerUsingProperties( configFile );
-
         CompositeCacheManagerMockImpl compositeCacheManager = new 
CompositeCacheManagerMockImpl();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
@@ -59,19 +67,144 @@
         AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
 
         // DO WORK
+        int numPutsPrior = server.getPutCount();
+        ICacheElement element = new CacheElement( regionName, "key", "value" );
+        cache.update( element );
+        SleepUtil.sleepAtLeast( 50 );
+
+        // VERIFY
+        System.out.println( server.getStats() );
+        assertEquals( "Wrong number of puts", 1, server.getPutCount() - 
numPutsPrior );
+
+        // DO WORK
+        ICacheElement result = cache.get( "key" );
+
+        // VERIFY
+        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+    }
+
+    /**
+     * Verify that we can remove an item via the remote server.
+     * <p>
+     * @throws Exception
+     */
+    public void testPutRemove()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new 
CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = 
RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testPutRemove";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
         ICacheElement element = new CacheElement( regionName, "key", "value" );
         cache.update( element );
         SleepUtil.sleepAtLeast( 50 );
 
         // VERIFY
         System.out.println( server.getStats() );
-        assertEquals( "Wrong number of puts", 1, server.getPutCount() );
+        assertEquals( "Wrong number of puts", 1, server.getPutCount() - 
numPutsPrior );
 
         // DO WORK
         ICacheElement result = cache.get( "key" );
 
         // VERIFY
         assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+
+        // DO WORK
+        cache.remove( "key" );
+        SleepUtil.sleepAtLeast( 50 );
+        ICacheElement resultAfterRemote = cache.get( "key" );
+
+        // VERIFY
+        assertNull( "Element resultAfterRemote should be null.", 
resultAfterRemote );
+    }
+
+    /**
+     * Register a listener with the server. Send an update. Verify that the 
listener received it.
+     * @throws Exception
+     */
+    public void testPutAndListen()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new 
CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = 
RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testPutAndListen";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        RemoteCacheListenerMockImpl listener = new 
RemoteCacheListenerMockImpl();
+        server.addCacheListener( regionName, listener );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
+        ICacheElement element = new CacheElement( regionName, "key", "value" );
+        cache.update( element );
+        SleepUtil.sleepAtLeast( 50 );
+
+        // VERIFY
+        try
+        {
+            System.out.println( server.getStats() );
+            assertEquals( "Wrong number of puts", 1, server.getPutCount() - 
numPutsPrior );
+            assertEquals( "Wrong number of puts to listener.", 1, 
listener.putCount );
+        }
+        finally
+        {
+            // remove from all regions.
+            server.removeCacheListener( listener );
+        }
     }
 
+    /**
+     * Register a listener with the server. Send an update. Verify that the 
listener received it.
+     * @throws Exception
+     */
+    public void testPutaMultipleAndListen()
+        throws Exception
+    {
+        // SETUP
+        CompositeCacheManagerMockImpl compositeCacheManager = new 
CompositeCacheManagerMockImpl();
+
+        RemoteCacheAttributes attributes = new RemoteCacheAttributes();
+        attributes.setRemoteHost( "localhost" );
+        attributes.setLocalPort( 1202 );
+        attributes.setRemotePort( 1101 );
+
+        RemoteCacheManager remoteCacheManager = 
RemoteCacheManager.getInstance( attributes, compositeCacheManager );
+        String regionName = "testPutAndListen";
+        AuxiliaryCache cache = remoteCacheManager.getCache( regionName );
+
+        RemoteCacheListenerMockImpl listener = new 
RemoteCacheListenerMockImpl();
+        server.addCacheListener( regionName, listener );
+
+        // DO WORK
+        int numPutsPrior = server.getPutCount();
+        int numToPut = 100;
+        for ( int i = 0; i < numToPut; i++ )
+        {
+            ICacheElement element = new CacheElement( regionName, "key" + 1, 
"value" + i );
+            cache.update( element );
+        }
+        SleepUtil.sleepAtLeast( 500 );
+
+        // VERIFY
+        System.out.println( server.getStats() );
+        assertEquals( "Wrong number of puts", numToPut, server.getPutCount() - 
numPutsPrior );
+        assertEquals( "Wrong number of puts to listener.", numToPut, 
listener.putCount );
+    }
 }


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe