You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2021/11/22 19:14:18 UTC
[commons-jcs] 05/07: Minimize number of deprecation references
This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 0af926cbb360f8132abcfdf2f350d665086adbe7
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 18:58:09 2021 +0100
Minimize number of deprecation references
---
.../lateral/socket/tcp/TestTCPLateralUnitTest.java | 155 +++++++--------------
1 file changed, 50 insertions(+), 105 deletions(-)
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
index e5a7759..0a85d98 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
@@ -1,10 +1,9 @@
package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
+import java.io.IOException;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.jcs3.engine.control.MockCompositeCacheManager;
-import org.apache.commons.jcs3.utils.timing.SleepUtil;
import org.apache.commons.jcs3.JCS;
import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
import org.apache.commons.jcs3.auxiliary.lateral.LateralCommand;
@@ -14,8 +13,10 @@ import org.apache.commons.jcs3.engine.behavior.ICacheElement;
import org.apache.commons.jcs3.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs3.engine.control.CompositeCache;
import org.apache.commons.jcs3.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs3.engine.control.MockCompositeCacheManager;
import org.apache.commons.jcs3.engine.control.group.GroupAttrName;
import org.apache.commons.jcs3.engine.control.group.GroupId;
+import org.apache.commons.jcs3.utils.timing.SleepUtil;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -46,6 +47,8 @@ import junit.framework.TestCase;
public class TestTCPLateralUnitTest
extends TestCase
{
+ private final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
+
/**
* Test setup
*/
@@ -55,6 +58,35 @@ public class TestTCPLateralUnitTest
JCS.setConfigFilename( "/TestTCPLateralCache.ccf" );
}
+ private <K,V> CompositeCache<K, V> createCache(int port)
+ {
+ final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
+ lattr.setTcpListenerPort(port);
+ lattr.setTransmissionType(LateralCacheAttributes.Type.TCP);
+
+ final CompositeCache<K, V> cache = cacheMgr.getCache( "test" );
+
+ // get the listener started
+ // give it our mock cache manager
+ //LateralTCPListener listener = (LateralTCPListener)
+ LateralTCPListener.getInstance( lattr, cacheMgr );
+
+ return cache;
+ }
+
+ private <K, V> LateralTCPService<K, V> createService(int listenerPort, int serverPort, long listenerId) throws IOException
+ {
+ final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort(listenerPort);
+ lattr2.setTransmissionType(LateralCacheAttributes.Type.TCP);
+ lattr2.setTcpServer("localhost:" + serverPort);
+
+ final LateralTCPService<K, V> service = new LateralTCPService<>( lattr2 );
+ service.setListenerId(listenerId);
+
+ return service;
+ }
+
/**
* Make sure we can send a bunch to the listener. This would be better if we could plugin a Mock
* CacheManger. The listener will instantiate it on its own. We have to configure one before
@@ -70,8 +102,8 @@ public class TestTCPLateralUnitTest
JCS.getInstance( "test" );
final TCPLateralCacheAttributes lac = new TCPLateralCacheAttributes();
- lac.setTransmissionType( LateralCacheAttributes.Type.TCP );
- lac.setTcpServer( "localhost" + ":" + 8111 );
+ lac.setTransmissionType(LateralCacheAttributes.Type.TCP);
+ lac.setTcpServer( "localhost:" + 8111 );
lac.setTcpListenerPort( 8111 );
final ICompositeCacheManager cacheMgr = CompositeCacheManager.getInstance();
@@ -88,9 +120,8 @@ public class TestTCPLateralUnitTest
{
final String message = "adsfasasfasfasdasf";
final CacheElement<String, String> ce = new CacheElement<>( "test", "test", message );
- final LateralElementDescriptor<String, String> led = new LateralElementDescriptor<>( ce );
- led.command = LateralCommand.UPDATE;
- led.requesterId = 1;
+ final LateralElementDescriptor<String, String> led =
+ new LateralElementDescriptor<>(ce, LateralCommand.UPDATE, 1);
lur.send( led );
}
@@ -107,21 +138,9 @@ public class TestTCPLateralUnitTest
throws Exception
{
// VERIFY
- final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
- lattr.setTcpListenerPort( 1101 );
- lattr.setTransmissionTypeName( "TCP" );
- final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
-// System.out.println( "mock cache = " + cacheMgr.getCache( "test" ) );
-
- LateralTCPListener.getInstance( lattr, cacheMgr );
-
- final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1102 );
- lattr2.setTransmissionTypeName( "TCP" );
- lattr2.setTcpServer( "localhost:1101" );
+ createCache(1101);
- final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
- service.setListenerId( 123456 );
+ final LateralTCPService<String, String> service = createService(1102, 1101, 123456);
// DO WORK
final int cnt = 100;
@@ -146,25 +165,10 @@ public class TestTCPLateralUnitTest
throws Exception
{
// SETUP
- // setup a listener
- final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
- lattr.setTcpListenerPort( 1103 );
- final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
- final CompositeCache<String, String> cache = cacheMgr.getCache( "test" );
-// System.out.println( "mock cache = " + cache );
-
- // get the listener started
- // give it our mock cache manager
- //LateralTCPListener listener = (LateralTCPListener)
- LateralTCPListener.getInstance( lattr, cacheMgr );
+ final CompositeCache<String, String> cache = createCache(1103);
// setup a service to talk to the listener started above.
- final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1104 );
- lattr2.setTcpServer( "localhost:1103" );
-
- final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
- service.setListenerId( 123456 );
+ final LateralTCPService<String, String> service = createService(1104, 1103, 123456);
// DO WORK
final ICacheElement<String, String> element = new CacheElement<>( "test", "key", "value1" );
@@ -190,25 +194,9 @@ public class TestTCPLateralUnitTest
public void testSameKeyObjectDifferentValueObject()
throws Exception
{
- final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
- lattr.setTcpListenerPort( 1105 );
- lattr.setTransmissionTypeName( "TCP" );
- final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
- final CompositeCache<String, String> cache = cacheMgr.getCache( "test" );
-// System.out.println( "mock cache = " + cache );
-
- // get the listener started
- // give it our mock cache manager
- //LateralTCPListener listener = (LateralTCPListener)
- LateralTCPListener.getInstance( lattr, cacheMgr );
-
- final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1106 );
- lattr2.setTransmissionTypeName( "TCP" );
- lattr2.setTcpServer( "localhost:1105" );
+ final CompositeCache<String, String> cache = createCache(1105);
- final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
- service.setListenerId( 123456 );
+ final LateralTCPService<String, String> service = createService(1106, 1105, 123456);
// DO WORK
final String key = "key";
@@ -237,28 +225,14 @@ public class TestTCPLateralUnitTest
throws Exception
{
// SETUP
- // setup a listener
- final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
- lattr.setTcpListenerPort( 1107 );
- final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
- final CompositeCache<String, String> cache = cacheMgr.getCache( "test" );
-// System.out.println( "mock cache = " + cache );
-
- // get the listener started
- // give it our mock cache manager
- LateralTCPListener.getInstance( lattr, cacheMgr );
+ final CompositeCache<String, String> cache = createCache(1107);
// add the item to the listeners cache
final ICacheElement<String, String> element = new CacheElement<>( "test", "key", "value1" );
cache.update( element );
// setup a service to talk to the listener started above.
- final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1108 );
- lattr2.setTcpServer( "localhost:1107" );
-
- final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
- service.setListenerId( 123456 );
+ final LateralTCPService<String, String> service = createService(1108, 1107, 123456);
SleepUtil.sleepAtLeast( 300 );
@@ -279,16 +253,7 @@ public class TestTCPLateralUnitTest
public void testGetGroupKeys_SendAndReceived() throws Exception
{
// SETUP
- // setup a listener
- final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
- lattr.setTcpListenerPort( 1150 );
- final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
- final CompositeCache<GroupAttrName<String>, String> cache = cacheMgr.getCache( "test" );
-// System.out.println( "mock cache = " + cache );
-
- // get the listener started
- // give it our mock cache manager
- LateralTCPListener.getInstance( lattr, cacheMgr );
+ final CompositeCache<GroupAttrName<String>, String> cache = createCache(1150);
// add the item to the listeners cache
final GroupAttrName<String> groupKey = new GroupAttrName<>(new GroupId("test", "group"), "key");
@@ -297,13 +262,7 @@ public class TestTCPLateralUnitTest
cache.update( element );
// setup a service to talk to the listener started above.
- final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1151 );
- lattr2.setTcpServer( "localhost:1150" );
-
- final LateralTCPService<GroupAttrName<String>, String> service =
- new LateralTCPService<>( lattr2 );
- service.setListenerId( 123459 );
+ final LateralTCPService<GroupAttrName<String>, String>service = createService(1151, 1150, 123459);
SleepUtil.sleepAtLeast( 500 );
@@ -327,16 +286,7 @@ public class TestTCPLateralUnitTest
throws Exception
{
// SETUP
- // setup a listener
- final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
- lattr.setTcpListenerPort( 1108 );
- final MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
- final CompositeCache<String, Integer> cache = cacheMgr.getCache( "test" );
-// System.out.println( "mock cache = " + cache );
-
- // get the listener started
- // give it our mock cache manager
- LateralTCPListener.getInstance( lattr, cacheMgr );
+ final CompositeCache<String, Integer> cache = createCache(1108);
final String keyprefix1 = "MyPrefix1";
final int numToInsertPrefix1 = 10;
@@ -349,12 +299,7 @@ public class TestTCPLateralUnitTest
}
// setup a service to talk to the listener started above.
- final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1108 );
- lattr2.setTcpServer( "localhost:1108" );
-
- final LateralTCPService<String, Integer> service = new LateralTCPService<>( lattr2 );
- service.setListenerId( 123456 );
+ final LateralTCPService<String, Integer> service = createService(1108, 1108, 123456);
SleepUtil.sleepAtLeast( 300 );