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:13 UTC

[commons-jcs] branch master updated (ae1f134 -> 4d77eeb)

This is an automated email from the ASF dual-hosted git repository.

tv pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git.


    from ae1f134  Remove now obsolete variable
     new dfe1b4e  Fix possible NPE in LateralCache
     new 2e7a0ce  Don't require Serializable
     new 9263fe1  Use same coding patterns
     new 7007eec  Prepare for immutable object
     new 0af926c  Minimize number of deprecation references
     new b743ebb  Deprecate String-methods in favor of Enum-methods
     new 4d77eeb  Minimize deprecation references

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../jcs3/auxiliary/lateral/LateralCache.java       |  58 +++----
 .../auxiliary/lateral/LateralCacheAttributes.java  |   2 +
 .../lateral/LateralElementDescriptor.java          |  64 +++++++
 .../lateral/behavior/ILateralCacheAttributes.java  |   4 +
 .../lateral/socket/tcp/LateralTCPListener.java     |  28 ++-
 .../jcs3/engine/ZombieCacheServiceNonLocal.java    |   2 +-
 .../lateral/LateralCacheNoWaitFacadeUnitTest.java  |  52 +++---
 .../tcp/LateralTCPConcurrentRandomTestUtil.java    |  21 ++-
 .../tcp/LateralTCPDiscoveryListenerUnitTest.java   |  81 ++++-----
 .../LateralTCPFilterRemoveHashCodeUnitTest.java    |  21 ++-
 .../tcp/LateralTCPIssueRemoveOnPutUnitTest.java    |  27 +--
 .../lateral/socket/tcp/TestTCPLateralUnitTest.java | 188 ++++++++-------------
 12 files changed, 267 insertions(+), 281 deletions(-)

[commons-jcs] 01/07: Fix possible NPE in LateralCache

Posted by tv...@apache.org.
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 dfe1b4eeda2b71f2fa9f374f2d8e7de962868f2a
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 17:46:49 2021 +0100

    Fix possible NPE in LateralCache
---
 .../jcs3/auxiliary/lateral/LateralCache.java       | 10 ++-
 .../jcs3/engine/ZombieCacheServiceNonLocal.java    |  2 +-
 .../lateral/LateralCacheNoWaitFacadeUnitTest.java  | 52 +++++---------
 .../tcp/LateralTCPDiscoveryListenerUnitTest.java   | 81 ++++++++--------------
 4 files changed, 54 insertions(+), 91 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java
index 34e9540..0688fde 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java
@@ -77,11 +77,13 @@ public class LateralCache<K, V>
      * Constructor for the LateralCache object
      * <p>
      * @param cattr
+     *
+     * @deprecated Causes NPE
      */
+    @Deprecated
     public LateralCache( final ILateralCacheAttributes cattr )
     {
-        this.cacheName = cattr.getCacheName();
-        this.lateralCacheAttributes = cattr;
+        this(cattr, null, null);
     }
 
     /**
@@ -240,10 +242,6 @@ public class LateralCache<K, V>
     {
         log.debug( "Disposing of lateral cache" );
 
-        ///* HELP: This section did nothing but generate compilation warnings.
-        // TODO: may limit this functionality. It is dangerous.
-        // asmuts -- Added functionality to help with warnings. I'm not getting
-        // any.
         try
         {
             lateralCacheService.dispose( this.lateralCacheAttributes.getCacheName() );
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/ZombieCacheServiceNonLocal.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/ZombieCacheServiceNonLocal.java
index 6f6c098..8c16847 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/ZombieCacheServiceNonLocal.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/ZombieCacheServiceNonLocal.java
@@ -69,8 +69,8 @@ public class ZombieCacheServiceNonLocal<K, V>
      */
     public ZombieCacheServiceNonLocal( final int maxQueueSize )
     {
+        this();
         this.maxQueueSize = maxQueueSize;
-        queue = new ConcurrentLinkedQueue<>();
     }
 
     /**
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java
index fc4b589..5bc0b19 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java
@@ -3,7 +3,8 @@ package org.apache.commons.jcs3.auxiliary.lateral;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.jcs3.auxiliary.lateral.behavior.ILateralCacheAttributes;
+import org.apache.commons.jcs3.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes;
+import org.apache.commons.jcs3.engine.ZombieCacheServiceNonLocal;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -32,20 +33,29 @@ import junit.framework.TestCase;
 public class LateralCacheNoWaitFacadeUnitTest
     extends TestCase
 {
-    /**
-     * Verify that we can remove an item.
-     */
-    public void testAddThenRemoveNoWait_InList()
+    private LateralCacheNoWaitFacade<String, String> facade;
+    private LateralCache<String, String> cache;
+
+    @Override
+    protected void setUp() throws Exception
     {
         // SETUP
         List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
+        TCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes();
         cattr.setCacheName( "testCache1" );
+        cattr.setTcpServer("localhost:7890");
 
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
 
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
-        final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
+        facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        cache = new LateralCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null);
+    }
+
+    /**
+     * Verify that we can remove an item.
+     */
+    public void testAddThenRemoveNoWait_InList()
+    {
+        LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
 
         // DO WORK
         facade.addNoWait( noWait );
@@ -66,14 +76,6 @@ public class LateralCacheNoWaitFacadeUnitTest
      */
     public void testAddThenRemoveNoWait_InListSize2()
     {
-        // SETUP
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
-
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
         final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
         noWait.setIdentityKey("1234");
         final LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<>( cache );
@@ -102,14 +104,6 @@ public class LateralCacheNoWaitFacadeUnitTest
      */
     public void testAdd_InList()
     {
-        // SETUP
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
-
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
         final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
 
         // DO WORK
@@ -126,14 +120,6 @@ public class LateralCacheNoWaitFacadeUnitTest
      */
     public void testAddThenRemoveNoWait_NotInList()
     {
-        // SETUP
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( "testCache1" );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
-
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
         final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
 
         // DO WORK
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java
index be7615d..4a2a60f 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java
@@ -4,11 +4,10 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.jcs3.auxiliary.lateral.LateralCache;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
 import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheNoWait;
 import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheNoWaitFacade;
-import org.apache.commons.jcs3.auxiliary.lateral.behavior.ILateralCacheAttributes;
 import org.apache.commons.jcs3.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes;
+import org.apache.commons.jcs3.engine.ZombieCacheServiceNonLocal;
 import org.apache.commons.jcs3.engine.behavior.IElementSerializer;
 import org.apache.commons.jcs3.engine.control.CompositeCacheManager;
 import org.apache.commons.jcs3.engine.logging.MockCacheEventLogger;
@@ -70,6 +69,24 @@ public class LateralTCPDiscoveryListenerUnitTest
                 cacheEventLogger, elementSerializer );
     }
 
+    private LateralCacheNoWaitFacade<String, String> setupFacade(final String cacheName)
+    {
+        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
+        final ITCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes();
+        cattr.setCacheName( cacheName );
+
+        return new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+    }
+
+    private LateralCacheNoWait<String, String> setupNoWait(final String cacheName)
+    {
+        final ITCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes();
+        cattr.setCacheName( cacheName );
+
+        final LateralCache<String, String> cache = new LateralCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null);
+        return new LateralCacheNoWait<>( cache );
+    }
+
     /**
      * Add a no wait facade.
      */
@@ -77,12 +94,7 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testAddNoWaitFacade_NotInList";
-
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName);
 
         // DO WORK
         listener.addNoWaitFacade( cacheName, facade );
@@ -98,16 +110,10 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testAddNoWaitFacade_FacadeInList";
-
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName);
         listener.addNoWaitFacade( cacheName, facade );
 
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
-        final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
+        final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName);
 
         // DO WORK
         final boolean result = listener.addNoWait( noWait );
@@ -123,11 +129,7 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testAddNoWaitFacade_FacadeInList";
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
-        final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
+        final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName);
 
         // DO WORK
         final boolean result = listener.addNoWait( noWait );
@@ -143,11 +145,7 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testRemoveNoWaitFacade_FacadeNotInList";
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
-        final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
+        final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName);
 
         // DO WORK
         final boolean result = listener.removeNoWait( noWait );
@@ -163,16 +161,10 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testAddNoWaitFacade_FacadeInList";
-
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName);
         listener.addNoWaitFacade( cacheName, facade );
 
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
-        final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
+        final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName);
 
         // DO WORK
         final boolean result = listener.removeNoWait( noWait );
@@ -188,16 +180,10 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testRemoveNoWaitFacade_FacadeInListNoWaitIs";
-
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new LateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName);
         listener.addNoWaitFacade( cacheName, facade );
 
-        final LateralCache<String, String> cache = new LateralCache<>( cattr );
-        final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache );
+        final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName);
         listener.addNoWait( noWait );
 
         // DO WORK
@@ -214,7 +200,6 @@ public class LateralTCPDiscoveryListenerUnitTest
     {
         // SETUP
         final String cacheName = "testAddDiscoveredService_FacadeInList_NoWaitNot";
-
         final ArrayList<String> cacheNames = new ArrayList<>();
         cacheNames.add( cacheName );
 
@@ -232,10 +217,7 @@ public class LateralTCPDiscoveryListenerUnitTest
         cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait);
         cacheMgr.registryFacPut(factory);
 
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new TCPLateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName);
         listener.addNoWaitFacade( cacheName, facade );
 
         // DO WORK
@@ -270,10 +252,7 @@ public class LateralTCPDiscoveryListenerUnitTest
         cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait);
         cacheMgr.registryFacPut(factory);
 
-        List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>();
-        final ILateralCacheAttributes cattr = new TCPLateralCacheAttributes();
-        cattr.setCacheName( cacheName );
-        final LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr );
+        final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName);
         listener.addNoWaitFacade( cacheName, facade );
         listener.addDiscoveredService( service );
 

[commons-jcs] 02/07: Don't require Serializable

Posted by tv...@apache.org.
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 2e7a0ce72d7357c52a95cde88b3b73df4d61028b
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 17:48:54 2021 +0100

    Don't require Serializable
---
 .../lateral/socket/tcp/LateralTCPListener.java     | 28 ++++++++++------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java
index 7cf7a9b..babe75e 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPListener.java
@@ -22,7 +22,6 @@ package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.Serializable;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -98,10 +97,10 @@ public class LateralTCPListener<K, V>
     private long listenerId = CacheInfo.listenerId;
 
     /** is this shut down? */
-    private AtomicBoolean shutdown;
+    private final AtomicBoolean shutdown = new AtomicBoolean();
 
     /** is this terminated? */
-    private AtomicBoolean terminated;
+    private final AtomicBoolean terminated = new AtomicBoolean();
 
     /**
      * Gets the instance attribute of the LateralCacheTCPListener class.
@@ -110,12 +109,11 @@ public class LateralTCPListener<K, V>
      * @param cacheMgr
      * @return The instance value
      */
+    @SuppressWarnings("unchecked") // Need to cast because of common map for all instances
     public static <K, V> LateralTCPListener<K, V>
         getInstance( final ITCPLateralCacheAttributes ilca, final ICompositeCacheManager cacheMgr )
     {
-        @SuppressWarnings("unchecked") // Need to cast because of common map for all instances
-        final
-        LateralTCPListener<K, V> ins = (LateralTCPListener<K, V>) instances.computeIfAbsent(
+        return (LateralTCPListener<K, V>) instances.computeIfAbsent(
                 String.valueOf( ilca.getTcpListenerPort() ),
                 k -> {
                     final LateralTCPListener<K, V> newIns = new LateralTCPListener<>( ilca );
@@ -127,8 +125,6 @@ public class LateralTCPListener<K, V>
 
                     return newIns;
                 });
-
-        return ins;
     }
 
     /**
@@ -152,8 +148,8 @@ public class LateralTCPListener<K, V>
             final int port = getTcpLateralCacheAttributes().getTcpListenerPort();
             final String host = getTcpLateralCacheAttributes().getTcpListenerHost();
 
-            terminated = new AtomicBoolean(false);
-            shutdown = new AtomicBoolean(false);
+            terminated.set(false);
+            shutdown.set(false);
 
             serializer = new StandardSerializer();
 
@@ -610,7 +606,7 @@ public class LateralTCPListener<K, V>
                         log.debug( "receiving LateralElementDescriptor from another led = {0}",
                                 led );
 
-                        Serializable obj = handleElement(led);
+                        Object obj = handleElement(led);
                         if (obj != null)
                         {
                             OutputStream os = socket.getOutputStream();
@@ -658,7 +654,7 @@ public class LateralTCPListener<K, V>
                 log.debug( "receiving LateralElementDescriptor from another led = {0}",
                         led );
 
-                Serializable obj = handleElement(led);
+                Object obj = handleElement(led);
                 if (obj != null)
                 {
                     serializer.serializeTo(obj, socketChannel);
@@ -691,11 +687,11 @@ public class LateralTCPListener<K, V>
      * @return a possible response
      * @throws IOException
      */
-    private Serializable handleElement(final LateralElementDescriptor<K, V> led) throws IOException
+    private Object handleElement(final LateralElementDescriptor<K, V> led) throws IOException
     {
         final String cacheName = led.ce.getCacheName();
         final K key = led.ce.getKey();
-        Serializable obj = null;
+        Object obj = null;
 
         switch (led.command)
         {
@@ -736,11 +732,11 @@ public class LateralTCPListener<K, V>
                 break;
 
             case GET_MATCHING:
-                obj = (Serializable) handleGetMatching( cacheName, (String) key );
+                obj = handleGetMatching( cacheName, (String) key );
                 break;
 
             case GET_KEYSET:
-                obj = (Serializable) handleGetKeySet(cacheName);
+                obj = handleGetKeySet(cacheName);
                 break;
 
             default: break;

[commons-jcs] 03/07: Use same coding patterns

Posted by tv...@apache.org.
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 9263fe12c953bb70961cf16ad11a07e23da97b96
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 17:57:53 2021 +0100

    Use same coding patterns
---
 .../jcs3/auxiliary/lateral/LateralCache.java       | 48 +++++++++++-----------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java
index 0688fde..d4055e2 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCache.java
@@ -124,19 +124,19 @@ public class LateralCache<K, V>
     {
         ICacheElement<K, V> obj = null;
 
-        if ( this.lateralCacheAttributes.getPutOnlyMode() )
+        if ( !this.lateralCacheAttributes.getPutOnlyMode() )
         {
-            return null;
-        }
-        try
-        {
-            obj = lateralCacheService.get( cacheName, key );
-        }
-        catch ( final Exception e )
-        {
-            log.error( e );
-            handleException( e, "Failed to get [" + key + "] from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+            try
+            {
+                obj = lateralCacheService.get( cacheName, key );
+            }
+            catch ( final Exception e )
+            {
+                log.error( e );
+                handleException( e, "Failed to get [" + key + "] from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+            }
         }
+
         return obj;
     }
 
@@ -150,20 +150,22 @@ public class LateralCache<K, V>
     protected Map<K, ICacheElement<K, V>> processGetMatching( final String pattern )
         throws IOException
     {
-        if ( this.lateralCacheAttributes.getPutOnlyMode() )
-        {
-            return Collections.emptyMap();
-        }
-        try
-        {
-            return lateralCacheService.getMatching( cacheName, pattern );
-        }
-        catch ( final IOException e )
+        Map<K, ICacheElement<K, V>> map = Collections.emptyMap();
+
+        if ( !this.lateralCacheAttributes.getPutOnlyMode() )
         {
-            log.error( e );
-            handleException( e, "Failed to getMatching [" + pattern + "] from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
-            return Collections.emptyMap();
+            try
+            {
+                return lateralCacheService.getMatching( cacheName, pattern );
+            }
+            catch ( final IOException e )
+            {
+                log.error( e );
+                handleException( e, "Failed to getMatching [" + pattern + "] from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+            }
         }
+
+        return map;
     }
 
     /**

[commons-jcs] 04/07: Prepare for immutable object

Posted by tv...@apache.org.
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 7007eec0f064a1dfd71e482054683482788a6d48
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 18:57:32 2021 +0100

    Prepare for immutable object
---
 .../lateral/LateralElementDescriptor.java          | 64 ++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralElementDescriptor.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralElementDescriptor.java
index 102975f..8a421e7 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralElementDescriptor.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralElementDescriptor.java
@@ -52,6 +52,7 @@ public class LateralElementDescriptor<K, V>
     public int valHashCode = -1;
 
     /** Constructor for the LateralElementDescriptor object */
+    @Deprecated // Not used
     public LateralElementDescriptor()
     {
     }
@@ -67,6 +68,69 @@ public class LateralElementDescriptor<K, V>
     }
 
     /**
+     * Constructor for the LateralElementDescriptor object
+     * <p>
+     * @param ce ICacheElement&lt;K, V&gt; payload
+     * @param command operation requested by the client
+     */
+    public LateralElementDescriptor( final ICacheElement<K, V> ce, LateralCommand command)
+    {
+        this(ce);
+        this.command = command;
+    }
+
+    /**
+     * Constructor for the LateralElementDescriptor object
+     * <p>
+     * @param ce ICacheElement&lt;K, V&gt; payload
+     * @param command operation requested by the client
+     * @param requesterId id of the the source of the request
+     */
+    public LateralElementDescriptor( final ICacheElement<K, V> ce, LateralCommand command, long requesterId)
+    {
+        this(ce, command);
+        this.requesterId = requesterId;
+    }
+
+    /**
+     * Return payload
+     *
+     * @return the ce
+     */
+    public ICacheElement<K, V> getPayload()
+    {
+        return ce;
+    }
+
+    /**
+     * Return id of the the source of the request
+     *
+     * @return the requesterId
+     */
+    public long getRequesterId()
+    {
+        return requesterId;
+    }
+
+    /**
+     * Return operation requested by the client
+     *
+     * @return the command
+     */
+    public LateralCommand getCommand()
+    {
+        return command;
+    }
+
+    /**
+     * @return the valHashCode
+     */
+    public int getValHashCode()
+    {
+        return valHashCode;
+    }
+
+    /**
      * @return String, all the important values that can be configured
      */
     @Override

[commons-jcs] 05/07: Minimize number of deprecation references

Posted by tv...@apache.org.
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 );
 

[commons-jcs] 07/07: Minimize deprecation references

Posted by tv...@apache.org.
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 4d77eeb72a594decd8dfffdc81a24a57da07016b
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 20:13:32 2021 +0100

    Minimize deprecation references
---
 .../tcp/LateralTCPConcurrentRandomTestUtil.java    | 20 ++++++-----
 .../LateralTCPFilterRemoveHashCodeUnitTest.java    | 20 ++++++-----
 .../tcp/LateralTCPIssueRemoveOnPutUnitTest.java    | 24 +++++++------
 .../lateral/socket/tcp/TestTCPLateralUnitTest.java | 41 +++++++++++-----------
 4 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
index af6b200..fe24cd2 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
@@ -1,5 +1,14 @@
 package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 
+import java.util.Random;
+
+import org.apache.commons.jcs3.JCS;
+import org.apache.commons.jcs3.access.CacheAccess;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.commons.jcs3.engine.CacheElement;
+import org.apache.commons.jcs3.engine.behavior.ICacheElement;
+import org.apache.commons.jcs3.utils.serialization.StandardSerializer;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,14 +30,6 @@ package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 
 import junit.framework.TestCase;
 
-import java.util.Random;
-
-import org.apache.commons.jcs3.JCS;
-import org.apache.commons.jcs3.access.CacheAccess;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
-import org.apache.commons.jcs3.engine.CacheElement;
-import org.apache.commons.jcs3.engine.behavior.ICacheElement;
-
 /**
  * @author Aaron Smuts
  */
@@ -87,7 +88,8 @@ public class LateralTCPConcurrentRandomTestUtil
         // this service will put and remove using the lateral to
         // the cache instance above
         // the cache thinks it is different since the listenerid is different
-        final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
+        final LateralTCPService<String, String> service =
+                new LateralTCPService<>(lattr2,  new StandardSerializer());
         service.setListenerId( 123456 );
 
         try
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
index 6e9abd7..4732cf6 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
@@ -1,5 +1,14 @@
 package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 
+import java.io.Serializable;
+
+import org.apache.commons.jcs3.JCS;
+import org.apache.commons.jcs3.access.CacheAccess;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.commons.jcs3.engine.CacheElement;
+import org.apache.commons.jcs3.engine.behavior.ICacheElement;
+import org.apache.commons.jcs3.utils.serialization.StandardSerializer;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,14 +30,6 @@ package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 
 import junit.framework.TestCase;
 
-import java.io.Serializable;
-
-import org.apache.commons.jcs3.JCS;
-import org.apache.commons.jcs3.access.CacheAccess;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
-import org.apache.commons.jcs3.engine.CacheElement;
-import org.apache.commons.jcs3.engine.behavior.ICacheElement;
-
 /**
  * @author Aaron Smuts
  */
@@ -101,7 +102,8 @@ public class LateralTCPFilterRemoveHashCodeUnitTest
         // this service will put and remove using the lateral to
         // the cache instance above
         // the cache thinks it is different since the listenerid is different
-        final LateralTCPService<String, Serializable> service = new LateralTCPService<>( lattr2 );
+        final LateralTCPService<String, Serializable> service =
+                new LateralTCPService<>(lattr2,  new StandardSerializer());
         service.setListenerId( 123456 );
 
         final String keyToBeRemovedOnPut = "test1";
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
index 9ae8606..6ff8ee6 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
@@ -1,5 +1,14 @@
 package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 
+import java.util.Random;
+
+import org.apache.commons.jcs3.JCS;
+import org.apache.commons.jcs3.access.CacheAccess;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.commons.jcs3.engine.CacheElement;
+import org.apache.commons.jcs3.engine.behavior.ICacheElement;
+import org.apache.commons.jcs3.utils.serialization.StandardSerializer;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,14 +30,6 @@ package org.apache.commons.jcs3.auxiliary.lateral.socket.tcp;
 
 import junit.framework.TestCase;
 
-import java.util.Random;
-
-import org.apache.commons.jcs3.JCS;
-import org.apache.commons.jcs3.access.CacheAccess;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
-import org.apache.commons.jcs3.engine.CacheElement;
-import org.apache.commons.jcs3.engine.behavior.ICacheElement;
-
 /**
  * Tests the issue remove on put fuctionality.
  * @author asmuts
@@ -98,7 +99,8 @@ public class LateralTCPIssueRemoveOnPutUnitTest
         // Using the lateral, this service will put to and remove from
         // the cache instance above.
         // The cache thinks it is different since the listenerid is different
-        final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
+        final LateralTCPService<String, String> service =
+                new LateralTCPService<>(lattr2,  new StandardSerializer());
         service.setListenerId( 123456 );
 
         final String keyToBeRemovedOnPut = "test1_notremoved";
@@ -127,7 +129,6 @@ public class LateralTCPIssueRemoveOnPutUnitTest
     public void runTestForRegion( final String region, final int range, final int numOps, final int testNum )
         throws Exception
     {
-
         final boolean show = false;
 
         final CacheAccess<String, String> cache = JCS.getInstance( region );
@@ -145,7 +146,8 @@ public class LateralTCPIssueRemoveOnPutUnitTest
         // Using the lateral, this service will put to and remove from
         // the cache instance above.
         // The cache thinks it is different since the listenerid is different
-        final LateralTCPService<String, String> service = new LateralTCPService<>( lattr2 );
+        final LateralTCPService<String, String> service =
+                new LateralTCPService<>( lattr2,  new StandardSerializer());
         service.setListenerId( 123456 );
 
         final String keyToBeRemovedOnPut = "test1";
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 0a85d98..d69f8ea 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,23 +1,5 @@
 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.JCS;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralCommand;
-import org.apache.commons.jcs3.auxiliary.lateral.LateralElementDescriptor;
-import org.apache.commons.jcs3.engine.CacheElement;
-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
  * or more contributor license agreements.  See the NOTICE file
@@ -37,6 +19,25 @@ import org.apache.commons.jcs3.utils.timing.SleepUtil;
  * under the License.
  */
 
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.jcs3.JCS;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCommand;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralElementDescriptor;
+import org.apache.commons.jcs3.engine.CacheElement;
+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.serialization.StandardSerializer;
+import org.apache.commons.jcs3.utils.timing.SleepUtil;
+
 import junit.framework.TestCase;
 
 /**
@@ -81,7 +82,7 @@ public class TestTCPLateralUnitTest
         lattr2.setTransmissionType(LateralCacheAttributes.Type.TCP);
         lattr2.setTcpServer("localhost:" + serverPort);
 
-        final LateralTCPService<K, V> service = new LateralTCPService<>( lattr2 );
+        final LateralTCPService<K, V> service = new LateralTCPService<>(lattr2,  new StandardSerializer());
         service.setListenerId(listenerId);
 
         return service;
@@ -112,7 +113,7 @@ public class TestTCPLateralUnitTest
         final LateralTCPListener<String, String> listener = LateralTCPListener.getInstance( lac, cacheMgr );
 
         // send to the listener
-        final LateralTCPSender lur = new LateralTCPSender( lac );
+        final LateralTCPSender lur = new LateralTCPSender(lac,  new StandardSerializer());
 
         // DO WORK
         final int numMes = 10;

[commons-jcs] 06/07: Deprecate String-methods in favor of Enum-methods

Posted by tv...@apache.org.
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 b743ebbc66308e2d0708b8aef610bd1aab40eeb8
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Nov 22 20:05:10 2021 +0100

    Deprecate String-methods in favor of Enum-methods
---
 .../commons/jcs3/auxiliary/lateral/LateralCacheAttributes.java       | 2 ++
 .../jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java     | 4 ++++
 .../lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java       | 3 ++-
 .../lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java   | 3 ++-
 .../lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java       | 5 +++--
 5 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheAttributes.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheAttributes.java
index c25655e..9956b07 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheAttributes.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/LateralCacheAttributes.java
@@ -191,6 +191,7 @@ public class LateralCacheAttributes
      * @param val The new transmissionTypeName value
      */
     @Override
+    @Deprecated
     public void setTransmissionTypeName( final String val )
     {
         this.transmissionType = Type.valueOf(val);
@@ -201,6 +202,7 @@ public class LateralCacheAttributes
      * @return The transmissionTypeName value
      */
     @Override
+    @Deprecated
     public String getTransmissionTypeName()
     {
         return this.transmissionType.toString();
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java
index 02ff5ae..93fece0 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/lateral/behavior/ILateralCacheAttributes.java
@@ -152,14 +152,18 @@ public interface ILateralCacheAttributes
      * Sets the transmissionTypeName attribute of the ILateralCacheAttributes object
      * <p>
      * @param val The new transmissionTypeName value
+     * @deprecated Use setTransmissionType()
      */
+    @Deprecated
     void setTransmissionTypeName( String val );
 
     /**
      * Gets the transmissionTypeName attribute of the ILateralCacheAttributes object
      * <p>
      * @return The transmissionTypeName value
+     * @deprecated Use getTransmissionType
      */
+    @Deprecated
     String getTransmissionTypeName();
 
     /**
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
index b6ba254..af6b200 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
@@ -25,6 +25,7 @@ import java.util.Random;
 
 import org.apache.commons.jcs3.JCS;
 import org.apache.commons.jcs3.access.CacheAccess;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
 import org.apache.commons.jcs3.engine.CacheElement;
 import org.apache.commons.jcs3.engine.behavior.ICacheElement;
 
@@ -80,7 +81,7 @@ public class LateralTCPConcurrentRandomTestUtil
 
         final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
         lattr2.setTcpListenerPort( 1103 );
-        lattr2.setTransmissionTypeName( "TCP" );
+        lattr2.setTransmissionType(LateralCacheAttributes.Type.TCP);
         lattr2.setTcpServer( "localhost:1102" );
 
         // this service will put and remove using the lateral to
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
index 4eec002..6e9abd7 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
@@ -25,6 +25,7 @@ import java.io.Serializable;
 
 import org.apache.commons.jcs3.JCS;
 import org.apache.commons.jcs3.access.CacheAccess;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
 import org.apache.commons.jcs3.engine.CacheElement;
 import org.apache.commons.jcs3.engine.behavior.ICacheElement;
 
@@ -91,7 +92,7 @@ public class LateralTCPFilterRemoveHashCodeUnitTest
 
         final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
         lattr2.setTcpListenerPort( 1102 );
-        lattr2.setTransmissionTypeName( "TCP" );
+        lattr2.setTransmissionType(LateralCacheAttributes.Type.TCP);
         lattr2.setTcpServer( "localhost:" + serverPort );
         lattr2.setIssueRemoveOnPut( true );
         // should still try to remove
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
index 88bb9ad..9ae8606 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs3/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
@@ -25,6 +25,7 @@ import java.util.Random;
 
 import org.apache.commons.jcs3.JCS;
 import org.apache.commons.jcs3.access.CacheAccess;
+import org.apache.commons.jcs3.auxiliary.lateral.LateralCacheAttributes;
 import org.apache.commons.jcs3.engine.CacheElement;
 import org.apache.commons.jcs3.engine.behavior.ICacheElement;
 
@@ -88,7 +89,7 @@ public class LateralTCPIssueRemoveOnPutUnitTest
 
         final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
         lattr2.setTcpListenerPort( 1102 );
-        lattr2.setTransmissionTypeName( "TCP" );
+        lattr2.setTransmissionType(LateralCacheAttributes.Type.TCP);
         lattr2.setTcpServer( "localhost:" + serverPort );
         lattr2.setIssueRemoveOnPut( false );
         // should still try to remove
@@ -135,7 +136,7 @@ public class LateralTCPIssueRemoveOnPutUnitTest
 
         final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
         lattr2.setTcpListenerPort( 1102 );
-        lattr2.setTransmissionTypeName( "TCP" );
+        lattr2.setTransmissionType(LateralCacheAttributes.Type.TCP);
         lattr2.setTcpServer( "localhost:" + serverPort );
         lattr2.setIssueRemoveOnPut( true );
         // should still try to remove