commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1591080 - in /commons/proper/jcs/trunk/commons-jcs-core: ./ src/main/java/org/apache/commons/jcs/io/ src/test/java/org/apache/commons/jcs/auxiliary/remote/server/ src/test/java/org/apache/commons/jcs/engine/
Date Tue, 29 Apr 2014 20:08:25 GMT
Author: tv
Date: Tue Apr 29 20:08:25 2014
New Revision: 1591080

URL: http://svn.apache.org/r1591080
Log:
Apply patch from JCS-120

Modified:
    commons/proper/jcs/trunk/commons-jcs-core/   (props changed)
    commons/proper/jcs/trunk/commons-jcs-core/pom.xml
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/remote/server/BasicRemoteCacheClientServerUnitTest.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/ElementAttributesUtils.java

Propchange: commons/proper/jcs/trunk/commons-jcs-core/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Apr 29 20:08:25 2014
@@ -4,3 +4,5 @@ target
 .classpath
 .project
 
+
+.settings

Modified: commons/proper/jcs/trunk/commons-jcs-core/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/pom.xml?rev=1591080&r1=1591079&r2=1591080&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/pom.xml (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/pom.xml Tue Apr 29 20:08:25 2014
@@ -1,3 +1,4 @@
+<?xml version="1.0"?>
 <!--
 
    Licensed to the Apache Software Foundation (ASF) under one or more
@@ -26,7 +27,6 @@
     <version>2.0-SNAPSHOT</version>
   </parent>
 
-  <groupId>org.apache.commons</groupId>
   <artifactId>commons-jcs-core</artifactId>
   <packaging>jar</packaging>
   <version>2.0-SNAPSHOT</version>
@@ -81,7 +81,7 @@
     </dependency>
     <dependency>
       <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
+      <artifactId>hamcrest-library</artifactId>
       <scope>test</scope>
     </dependency>
 
@@ -116,19 +116,6 @@
       <artifactId>servlet-api</artifactId>
       <optional>true</optional>
     </dependency>
-
-    <!-- to debug tcks -->
-    <dependency>
-      <groupId>javax.cache</groupId>
-      <artifactId>cache-tests</artifactId>
-      <classifier>tests</classifier>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>javax.cache</groupId>
-      <artifactId>cache-tests</artifactId>
-      <scope>test</scope>
-    </dependency>
   </dependencies>
 
   <build>

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java?rev=1591080&r1=1591079&r2=1591080&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
Tue Apr 29 20:08:25 2014
@@ -1,3 +1,21 @@
+/*
+ * 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.
+ */
 package org.apache.commons.jcs.io;
 
 import java.io.IOException;

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=1591080&r1=1591079&r2=1591080&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
Tue Apr 29 20:08:25 2014
@@ -19,10 +19,7 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
-import java.net.InetAddress;
-
-import junit.framework.TestCase;
-
+import org.apache.commons.jcs.JCS;
 import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
 import org.apache.commons.jcs.auxiliary.MockCacheEventLogger;
 import org.apache.commons.jcs.auxiliary.remote.MockRemoteCacheListener;
@@ -35,228 +32,254 @@ import org.apache.commons.jcs.engine.con
 import org.apache.commons.jcs.engine.control.MockElementSerializer;
 import org.apache.commons.jcs.utils.net.HostNameUtil;
 import org.apache.commons.jcs.utils.timing.SleepUtil;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.rmi.server.ServerNotActiveException;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * These tests startup the remote server and make requests to it.
- * <p>
+ * <p/>
+ *
  * @author Aaron Smuts
  */
-public class BasicRemoteCacheClientServerUnitTest
-    extends TestCase
-{
-    /** Server instance to use in the tests. */
-    private RemoteCacheServer<String, String> server = null;
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class BasicRemoteCacheClientServerUnitTest extends Assert {
+    /**
+     * Server instance to use in the tests.
+     */
+    private static RemoteCacheServer<String, String> server = null;
 
-    /** the remote server port */
-    private final int remotePort;
+    /**
+     * the remote server port
+     */
+    private static int remotePort;
+
+    private static final Lock lock = new ReentrantLock();
 
     /**
      * Starts the server. This is not in a setup, since the server is slow to kill right
now.
      */
-    public BasicRemoteCacheClientServerUnitTest()
-    {
+    @BeforeClass
+    public static void setup() {
         String configFile = "TestRemoteCacheClientServer.ccf";
-        server = RemoteCacheServerStartupUtil.startServerUsingProperties( configFile );
+        server = RemoteCacheServerStartupUtil.startServerUsingProperties(configFile);
         remotePort = server.remoteCacheServerAttributes.getRemotePort();
     }
 
+    @AfterClass
+    public static void stop() throws IOException, ServerNotActiveException {
+        server.shutdown("localhost", remotePort);
+    }
+
     /**
      * Verify that we can start the remote cache server. Send an item to the remote. Verify
that the
      * remote put count goes up. If we go through JCS, the manager will be shared and we
will get
      * into an endless loop. We will use a mock cache manager instead.
-     * <p>
+     * <p/>
      * The remote server uses the real JCS. We can verify that items are added to JCS behind
the
      * server by calling get. We cannot access it directly via JCS since it is serialized.
-     * <p>
+     * <p/>
      * This test uses a mock injected client to test a normal server.
-     * <p>
+     * <p/>
+     *
      * @throws Exception
      */
-    public void testSinglePut()
-        throws Exception
-    {
+    @Test
+    public void test1SinglePut()
+            throws Exception {
         // SETUP
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( remotePort );
+        attributes.setRemoteHost("localhost");
+        attributes.setLocalPort(1202);
+        attributes.setRemotePort(remotePort);
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer() );
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
         String regionName = "testSinglePut";
-        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache( regionName
);
+        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
         // DO WORK
         int numPutsPrior = server.getPutCount();
-        ICacheElement<String, String> element = new CacheElement<String, String>(
regionName, "key", "value" );
-        cache.update( element );
-        SleepUtil.sleepAtLeast( 200 );
+        ICacheElement<String, String> element = new CacheElement<String, String>(regionName,
"key", "value");
+        cache.update(element);
+        SleepUtil.sleepAtLeast(200);
 
         // VERIFY
         try {
             assertEquals("Cache is alive", CacheStatus.ALIVE, cache.getStatus());
-            assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior
);
+            assertEquals("Wrong number of puts", 1, server.getPutCount() - numPutsPrior);
         } catch (junit.framework.AssertionFailedError e) {
-            System.out.println( cache.getStats() );
-            System.out.println( server.getStats() );
+            System.out.println(cache.getStats());
+            System.out.println(server.getStats());
             throw e;
         }
 
         // DO WORK
-        ICacheElement<String, String> result = cache.get( "key" );
+        ICacheElement<String, String> result = cache.get("key");
 
         // VERIFY
-        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+        assertEquals("Wrong element.", element.getVal(), result.getVal());
     }
 
     /**
      * Verify that we can remove an item via the remote server.
-     * <p>
+     * <p/>
+     *
      * @throws Exception
      */
-    public void testPutRemove()
-        throws Exception
-    {
+    @Test
+    public void test2PutRemove()
+            throws Exception {
         // SETUP
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( remotePort );
+        attributes.setRemoteHost("localhost");
+        attributes.setLocalPort(1202);
+        attributes.setRemotePort(remotePort);
 
         MockCacheEventLogger cacheEventLogger = new MockCacheEventLogger();
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes,
compositeCacheManager, cacheEventLogger, null );
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, cacheEventLogger, null);
         String regionName = "testPutRemove";
-        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache( regionName
);
+        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
         // DO WORK
         int numPutsPrior = server.getPutCount();
-        ICacheElement<String, String> element = new CacheElement<String, String>(
regionName, "key", "value" );
-        cache.update( element );
-        SleepUtil.sleepAtLeast( 50 );
+        ICacheElement<String, String> element = new CacheElement<String, String>(regionName,
"key", "value");
+        cache.update(element);
+        SleepUtil.sleepAtLeast(50);
 
         // VERIFY
         try {
             assertEquals("Cache is alive", CacheStatus.ALIVE, cache.getStatus());
-            assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior
);
+            assertEquals("Wrong number of puts", 1, server.getPutCount() - numPutsPrior);
         } catch (junit.framework.AssertionFailedError e) {
-            System.out.println( cache.getStats() );
-            System.out.println( server.getStats() );
+            System.out.println(cache.getStats());
+            System.out.println(server.getStats());
             throw e;
         }
 
         // DO WORK
-        ICacheElement<String, String> result = cache.get( "key" );
+        ICacheElement<String, String> result = cache.get("key");
 
         // VERIFY
-        assertEquals( "Wrong element.", element.getVal(), result.getVal() );
+        assertEquals("Wrong element.", element.getVal(), result.getVal());
 
         // DO WORK
-        cache.remove( "key" );
-        SleepUtil.sleepAtLeast( 200 );
-        ICacheElement<String, String> resultAfterRemote = cache.get( "key" );
+        cache.remove("key");
+        SleepUtil.sleepAtLeast(200);
+        ICacheElement<String, String> resultAfterRemote = cache.get("key");
 
         // VERIFY
-        assertNull( "Element resultAfterRemote should be null.", resultAfterRemote );
+        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
-    {
+    @Test
+    public void test3PutAndListen()
+            throws Exception {
         // SETUP
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( remotePort );
+        attributes.setRemoteHost("localhost");
+        attributes.setLocalPort(1202);
+        attributes.setRemotePort(remotePort);
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer() );
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
         String regionName = "testPutAndListen";
-        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache( regionName
);
+        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
         MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-        server.addCacheListener( regionName, listener );
+        server.addCacheListener(regionName, listener);
 
         // DO WORK
         int numPutsPrior = server.getPutCount();
-        ICacheElement<String, String> element = new CacheElement<String, String>(
regionName, "key", "value" );
-        cache.update( element );
-        SleepUtil.sleepAtLeast( 50 );
+        ICacheElement<String, String> element = new CacheElement<String, String>(regionName,
"key", "value");
+        cache.update(element);
+        SleepUtil.sleepAtLeast(50);
 
         // VERIFY
-        try
-        {
+        try {
             assertEquals("Cache is alive", CacheStatus.ALIVE, cache.getStatus());
-            assertEquals( "Wrong number of puts", 1, server.getPutCount() - numPutsPrior
);
-            assertEquals( "Wrong number of puts to listener.", 1, listener.putCount );
+            assertEquals("Wrong number of puts", 1, server.getPutCount() - numPutsPrior);
+            assertEquals("Wrong number of puts to listener.", 1, listener.putCount);
         } catch (junit.framework.AssertionFailedError e) {
-            System.out.println( cache.getStats() );
-            System.out.println( server.getStats() );
+            System.out.println(cache.getStats());
+            System.out.println(server.getStats());
             throw e;
-        }
-        finally
-        {
+        } finally {
             // remove from all regions.
-            server.removeCacheListener( listener );
+            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
-    {
+    @Test
+    public void test4PutaMultipleAndListen()
+            throws Exception {
         // SETUP
         MockCompositeCacheManager compositeCacheManager = new MockCompositeCacheManager();
 
         RemoteCacheAttributes attributes = new RemoteCacheAttributes();
-        attributes.setRemoteHost( "localhost" );
-        attributes.setLocalPort( 1202 );
-        attributes.setRemotePort( remotePort );
+        attributes.setRemoteHost("localhost");
+        attributes.setLocalPort(1202);
+        attributes.setRemotePort(remotePort);
 
-        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance( attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer() );
+        RemoteCacheManager remoteCacheManager = RemoteCacheManager.getInstance(attributes,
compositeCacheManager, new MockCacheEventLogger(), new MockElementSerializer());
         String regionName = "testPutaMultipleAndListen";
-        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache( regionName
);
+        AuxiliaryCache<String, String> cache = remoteCacheManager.getCache(regionName);
 
         MockRemoteCacheListener<String, String> listener = new MockRemoteCacheListener<String,
String>();
-        server.addCacheListener( regionName, listener );
+        server.addCacheListener(regionName, listener);
 
         // DO WORK
         int numPutsPrior = server.getPutCount();
         int numToPut = 100;
-        for ( int i = 0; i < numToPut; i++ )
-        {
-            ICacheElement<String, String> element = new CacheElement<String, String>(
regionName, "key" + 1, "value" + i );
-            cache.update( element );
+        for (int i = 0; i < numToPut; i++) {
+            ICacheElement<String, String> element = new CacheElement<String, String>(regionName,
"key" + 1, "value" + i);
+            cache.update(element);
         }
-        SleepUtil.sleepAtLeast( 500 );
+        SleepUtil.sleepAtLeast(500);
 
         // VERIFY
         try {
             assertEquals("Cache is alive", CacheStatus.ALIVE, cache.getStatus());
-            assertEquals( "Wrong number of puts", numToPut, server.getPutCount() - numPutsPrior
);
-            assertEquals( "Wrong number of puts to listener.", numToPut, listener.putCount
);
+            assertEquals("Wrong number of puts", numToPut, server.getPutCount() - numPutsPrior);
+            assertEquals("Wrong number of puts to listener.", numToPut, listener.putCount);
         } catch (junit.framework.AssertionFailedError e) {
-            System.out.println( cache.getStats() );
-            System.out.println( server.getStats() );
+            System.out.println(cache.getStats());
+            System.out.println(server.getStats());
             throw e;
         }
     }
 
+    @Test
     public void testLocalHost() throws Exception {
         final InetAddress byName = InetAddress.getByName("localhost");
-        assertTrue("Expected localhost ("+byName.getHostAddress()+") to be a loopback address",
byName.isLoopbackAddress());
+        assertTrue("Expected localhost (" + byName.getHostAddress() + ") to be a loopback
address", byName.isLoopbackAddress());
         final InetAddress localHost = HostNameUtil.getLocalHostLANAddress();
-        assertTrue("Expected getLocalHostLANAddress() ("+localHost+") to return a site local
address", localHost.isSiteLocalAddress());
+        assertTrue("Expected getLocalHostLANAddress() (" + localHost + ") to return a site
local address", localHost.isSiteLocalAddress());
     }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/ElementAttributesUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/ElementAttributesUtils.java?rev=1591080&r1=1591079&r2=1591080&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/ElementAttributesUtils.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/engine/ElementAttributesUtils.java
Tue Apr 29 20:08:25 2014
@@ -1,3 +1,21 @@
+/*
+ * 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.
+ */
 package org.apache.commons.jcs.engine;
 
 /**



Mime
View raw message