Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7AFB110DA4 for ; Tue, 29 Apr 2014 20:08:58 +0000 (UTC) Received: (qmail 88266 invoked by uid 500); 29 Apr 2014 20:08:54 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 88198 invoked by uid 500); 29 Apr 2014 20:08:54 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 88156 invoked by uid 99); 29 Apr 2014 20:08:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2014 20:08:52 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Apr 2014 20:08:49 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D0DEC238889B; Tue, 29 Apr 2014 20:08:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: tv@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140429200825.D0DEC238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + - - javax.cache - cache-tests - tests - test - - - javax.cache - cache-tests - test - 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. - *

+ *

+ * * @author Aaron Smuts */ -public class BasicRemoteCacheClientServerUnitTest - extends TestCase -{ - /** Server instance to use in the tests. */ - private RemoteCacheServer server = null; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class BasicRemoteCacheClientServerUnitTest extends Assert { + /** + * Server instance to use in the tests. + */ + private static RemoteCacheServer 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. - *

+ *

* 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. - *

+ *

* This test uses a mock injected client to test a normal server. - *

+ *

+ * * @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 cache = remoteCacheManager.getCache( regionName ); + AuxiliaryCache cache = remoteCacheManager.getCache(regionName); // DO WORK int numPutsPrior = server.getPutCount(); - ICacheElement element = new CacheElement( regionName, "key", "value" ); - cache.update( element ); - SleepUtil.sleepAtLeast( 200 ); + ICacheElement element = new CacheElement(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 result = cache.get( "key" ); + ICacheElement 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. - *

+ *

+ * * @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 cache = remoteCacheManager.getCache( regionName ); + AuxiliaryCache cache = remoteCacheManager.getCache(regionName); // DO WORK int numPutsPrior = server.getPutCount(); - ICacheElement element = new CacheElement( regionName, "key", "value" ); - cache.update( element ); - SleepUtil.sleepAtLeast( 50 ); + ICacheElement element = new CacheElement(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 result = cache.get( "key" ); + ICacheElement 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 resultAfterRemote = cache.get( "key" ); + cache.remove("key"); + SleepUtil.sleepAtLeast(200); + ICacheElement 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 cache = remoteCacheManager.getCache( regionName ); + AuxiliaryCache cache = remoteCacheManager.getCache(regionName); MockRemoteCacheListener listener = new MockRemoteCacheListener(); - server.addCacheListener( regionName, listener ); + server.addCacheListener(regionName, listener); // DO WORK int numPutsPrior = server.getPutCount(); - ICacheElement element = new CacheElement( regionName, "key", "value" ); - cache.update( element ); - SleepUtil.sleepAtLeast( 50 ); + ICacheElement element = new CacheElement(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 cache = remoteCacheManager.getCache( regionName ); + AuxiliaryCache cache = remoteCacheManager.getCache(regionName); MockRemoteCacheListener listener = new MockRemoteCacheListener(); - 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 element = new CacheElement( regionName, "key" + 1, "value" + i ); - cache.update( element ); + for (int i = 0; i < numToPut; i++) { + ICacheElement element = new CacheElement(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; /**