commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1719092 [2/2] - in /commons/proper/jcs/trunk/commons-jcs-core/src: main/java/org/apache/commons/jcs/access/ main/java/org/apache/commons/jcs/auxiliary/disk/ main/java/org/apache/commons/jcs/auxiliary/disk/block/ main/java/org/apache/common...
Date Thu, 10 Dec 2015 15:07:31 GMT
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheUnitTest.java?rev=1719092&r1=1719091&r2=1719092&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheUnitTest.java
Thu Dec 10 15:07:30 2015
@@ -19,7 +19,11 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.util.HashSet;
+import java.util.Map;
+
 import junit.framework.TestCase;
+
 import org.apache.commons.jcs.auxiliary.MockCacheEventLogger;
 import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
 import org.apache.commons.jcs.engine.CacheElement;
@@ -28,17 +32,32 @@ import org.apache.commons.jcs.engine.beh
 import org.apache.commons.jcs.engine.behavior.ICacheElementSerialized;
 import org.apache.commons.jcs.utils.serialization.SerializationConversionUtil;
 
-import java.util.HashSet;
-import java.util.Map;
-
 /**
  * Unit Tests for the Remote Cache.
  */
 public class RemoteCacheUnitTest
     extends TestCase
 {
+    private IRemoteCacheAttributes cattr;
+    private MockRemoteCacheService<String, String> service;
+    private MockRemoteCacheListener<String, String> listener;
+    private RemoteCacheMonitor monitor;
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        cattr = new RemoteCacheAttributes();
+        service = new MockRemoteCacheService<String, String>();
+        listener = new MockRemoteCacheListener<String, String>();
+        monitor = new RemoteCacheMonitor();
+    }
+
     /**
-     * Verify that the remote service update method is called. The remote cache serializes
the obect
+     * Verify that the remote service update method is called. The remote cache serializes
the object
      * first.
      * <p>
      * @throws Exception
@@ -48,12 +67,9 @@ public class RemoteCacheUnitTest
     {
         // SETUP
         long listenerId = 123;
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
         listener.setListenerId( listenerId );
 
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         String cacheName = "testUpdate";
 
@@ -80,13 +96,10 @@ public class RemoteCacheUnitTest
         throws Exception
     {
         // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
         ZombieCacheServiceNonLocal<String, String> zombie = new ZombieCacheServiceNonLocal<String,
String>( 10 );
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
 
         // set the zombie
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, zombie, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, zombie, listener, monitor );
 
         String cacheName = "testUpdate";
 
@@ -113,12 +126,7 @@ public class RemoteCacheUnitTest
     public void testUpdate_simple()
         throws Exception
     {
-        // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -141,12 +149,7 @@ public class RemoteCacheUnitTest
     public void testGet_simple()
         throws Exception
     {
-        // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -167,12 +170,7 @@ public class RemoteCacheUnitTest
     public void testGetMultiple_simple()
         throws Exception
     {
-        // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -193,12 +191,7 @@ public class RemoteCacheUnitTest
     public void testRemove_simple()
         throws Exception
     {
-        // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -219,12 +212,7 @@ public class RemoteCacheUnitTest
     public void testRemoveAll_simple()
         throws Exception
     {
-        // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -247,11 +235,8 @@ public class RemoteCacheUnitTest
     {
         // SETUP
         String pattern = "adsfasdfasd.?";
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
 
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -273,12 +258,7 @@ public class RemoteCacheUnitTest
     public void testDispose_simple()
         throws Exception
     {
-        // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );
@@ -300,11 +280,7 @@ public class RemoteCacheUnitTest
         throws Exception
     {
         // SETUP
-        IRemoteCacheAttributes cattr = new RemoteCacheAttributes();
-        MockRemoteCacheService<String, String> service = new MockRemoteCacheService<String,
String>();
-        MockRemoteCacheListener<String, String> listener = null;
-
-        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, listener );
+        RemoteCache<String, String> remoteCache = new RemoteCache<String, String>(
cattr, service, null, monitor );
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
         remoteCache.setCacheEventLogger( cacheEventLogger );

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtilsUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtilsUnitTest.java?rev=1719092&r1=1719091&r2=1719092&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtilsUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtilsUnitTest.java
Thu Dec 10 15:07:30 2015
@@ -51,21 +51,15 @@ public class RemoteUtilsUnitTest
 
     public void testParseServerAndPort()
     {
-        RemoteCacheAttributes rca = new RemoteCacheAttributes();
+        RemoteLocation loc = RemoteLocation.parseServerAndPort("server1:1234");
+        assertEquals("server1", loc.getHost());
+        assertEquals(1234, loc.getPort());
 
-        RemoteUtils.parseServerAndPort("server1:1234", rca);
-        assertEquals("server1", rca.getRemoteHost());
-        assertEquals(1234, rca.getRemotePort());
+        loc = RemoteLocation.parseServerAndPort("  server2  :  4567  ");
+        assertEquals("server2", loc.getHost());
+        assertEquals(4567, loc.getPort());
 
-        RemoteUtils.parseServerAndPort("  server2  :  4567  ", rca);
-        assertEquals("server2", rca.getRemoteHost());
-        assertEquals(4567, rca.getRemotePort());
-
-        rca.setRemoteHost("");
-        rca.setRemotePort(0);
-        // Should not change anything
-        RemoteUtils.parseServerAndPort("server2  :  port", rca);
-        assertEquals("", rca.getRemoteHost());
-        assertEquals(0, rca.getRemotePort());
+        loc = RemoteLocation.parseServerAndPort("server2  :  port");
+        assertNull(loc);
     }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/TestRemoteCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/TestRemoteCache.java?rev=1719092&r1=1719091&r2=1719092&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/TestRemoteCache.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/TestRemoteCache.java
Thu Dec 10 15:07:30 2015
@@ -20,6 +20,7 @@ package org.apache.commons.jcs.auxiliary
  */
 
 import junit.framework.TestCase;
+
 import org.apache.commons.jcs.JCS;
 import org.apache.commons.jcs.access.CacheAccess;
 import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
@@ -104,10 +105,9 @@ public class TestRemoteCache
         ICompositeCacheManager cacheMgr = new MockCompositeCacheManager();
 
         RemoteCacheAttributes rca = new RemoteCacheAttributes();
-        rca.setRemoteHost( "localhost" );
-        rca.setRemotePort( 1101 );
+        rca.setRemoteLocation( "localhost", 1101 );
 
-        RemoteCacheManager mgr = RemoteCacheManager.getInstance( rca, cacheMgr, new MockCacheEventLogger(),
new MockElementSerializer() );
+        RemoteCacheManager mgr = RemoteCacheFactory.getManager( rca, cacheMgr, new MockCacheEventLogger(),
new MockElementSerializer() );
         AuxiliaryCache<String, String> cache = mgr.getCache( "testCache" );
 
         int numMes = 100;

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java?rev=1719092&r1=1719091&r2=1719092&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
Thu Dec 10 15:07:30 2015
@@ -19,10 +19,16 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.util.Enumeration;
+
 import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
 import org.apache.commons.jcs.auxiliary.MockCacheEventLogger;
 import org.apache.commons.jcs.auxiliary.remote.MockRemoteCacheListener;
 import org.apache.commons.jcs.auxiliary.remote.RemoteCacheAttributes;
+import org.apache.commons.jcs.auxiliary.remote.RemoteCacheFactory;
 import org.apache.commons.jcs.auxiliary.remote.RemoteCacheManager;
 import org.apache.commons.jcs.engine.CacheElement;
 import org.apache.commons.jcs.engine.CacheStatus;
@@ -38,11 +44,6 @@ import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
 
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.util.Enumeration;
-
 /**
  * These tests startup the remote server and make requests to it.
  * <p/>
@@ -58,6 +59,11 @@ public class BasicRemoteCacheClientServe
     private static RemoteCacheServer<String, String> server = null;
 
     /**
+     * Factory instance to use in the tests.
+     */
+    private static RemoteCacheFactory factory = null;
+
+    /**
      * the remote server port
      */
     private static int remotePort;
@@ -85,7 +91,7 @@ public class BasicRemoteCacheClientServe
                     boolean loopbackAddress = inetAddr.isLoopbackAddress();
                     boolean siteLocalAddress = inetAddr.isSiteLocalAddress();
                     System.out.println("Found: "+ inetAddr +
-                            " isLoopback: " + loopbackAddress + 
+                            " isLoopback: " + loopbackAddress +
                             " isSiteLocal: " + siteLocalAddress +
                             ((!loopbackAddress && siteLocalAddress) ? " *" : ""));
                 }
@@ -96,7 +102,9 @@ public class BasicRemoteCacheClientServe
         // end of debug
         String configFile = "TestRemoteCacheClientServer.ccf";
         server = RemoteCacheServerStartupUtil.startServerUsingProperties(configFile);
-        remotePort = server.remoteCacheServerAttributes.getRemotePort();
+        factory = new RemoteCacheFactory();
+        factory.initialize();
+        remotePort = server.remoteCacheServerAttributes.getRemoteLocation().getPort();
     }
 
     @AfterClass
@@ -133,11 +141,10 @@ public class BasicRemoteCacheClientServe
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost("localhost");
+        attributes.setRemoteLocation("localhost", remotePort);
         attributes.setLocalPort(1202);
-        attributes.setRemotePort(remotePort);
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
+        RemoteCacheManager remoteCacheManager = RemoteCacheFactory.getManager(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
         String regionName = "testSinglePut";
         AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
@@ -181,13 +188,12 @@ public class BasicRemoteCacheClientServe
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost("localhost");
+        attributes.setRemoteLocation("localhost", remotePort);
         attributes.setLocalPort(1202);
-        attributes.setRemotePort(remotePort);
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, cacheEventLogger, null);
+        RemoteCacheManager remoteCacheManager = RemoteCacheFactory.getManager(attributes,
compositeCacheManager, cacheEventLogger, null);
         String regionName = "testPutRemove";
         AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
@@ -238,11 +244,10 @@ public class BasicRemoteCacheClientServe
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost("localhost");
+        attributes.setRemoteLocation("localhost", remotePort);
         attributes.setLocalPort(1202);
-        attributes.setRemotePort(remotePort);
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
+        RemoteCacheManager remoteCacheManager = RemoteCacheFactory.getManager(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
         String regionName = "testPutAndListen";
         AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
@@ -288,11 +293,10 @@ public class BasicRemoteCacheClientServe
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost("localhost");
+        attributes.setRemoteLocation("localhost", remotePort);
         attributes.setLocalPort(1202);
-        attributes.setRemotePort(remotePort);
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
+        RemoteCacheManager remoteCacheManager = RemoteCacheFactory.getManager(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
         String regionName = "testPutaMultipleAndListen";
         AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapUnitTest.java?rev=1719092&r1=1719091&r2=1719092&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapUnitTest.java
Thu Dec 10 15:07:30 2015
@@ -19,12 +19,12 @@ package org.apache.commons.jcs.utils.str
  * under the License.
  */
 
-import junit.framework.TestCase;
-
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
+import junit.framework.TestCase;
+
 /**
  * Basic unit tests for the LRUMap
  *
@@ -125,7 +125,7 @@ public class LRUMapUnitTest
         // check minimal correctness
         for (Entry<String, String> data : entries)
         {
-            assertTrue( "Data is wrong.", data.getValue().toString().indexOf( "data:") !=
-1  );
+            assertTrue( "Data is wrong.", data.getValue().indexOf( "data:") != -1  );
         }
     }
 



Mime
View raw message