You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2022/09/30 12:13:45 UTC

[cxf] branch 3.5.x-fixes updated (d39f491f43 -> f9860867c5)

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

reta pushed a change to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


    from d39f491f43 Recording .gitmergeinfo Changes
     new 1274883279 CXF-8712 One-off issue with retries (#954)
     new f9860867c5  CXF-8712: One-off issue with retries (fixing the test cases)

The 2 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:
 .../cxf/clustering/AbstractStaticFailoverStrategy.java     | 12 ++++++++----
 .../main/java/org/apache/cxf/clustering/RetryStrategy.java |  7 ++++++-
 .../java/org/apache/cxf/clustering/SequentialStrategy.java |  2 +-
 .../cxf/systest/jaxrs/failover/AbstractFailoverTest.java   | 14 ++++++++------
 4 files changed, 23 insertions(+), 12 deletions(-)


[cxf] 02/02: CXF-8712: One-off issue with retries (fixing the test cases)

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit f9860867c5645e092dcae8c57b969f047fc23a21
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Thu Sep 29 20:32:41 2022 -0400

     CXF-8712: One-off issue with retries (fixing the test cases)
    
    (cherry picked from commit 03e0b6549334173feb73d3d96477d72f9378d8c5)
---
 .../src/main/java/org/apache/cxf/clustering/RetryStrategy.java        | 2 +-
 .../org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
index e8e3ec235a..8e823bb7ce 100644
--- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
+++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
@@ -44,7 +44,7 @@ public class RetryStrategy extends SequentialStrategy {
     @Override
     protected <T> T getNextAlternate(List<T> alternates) {
         // is the amount of retries for the first alternate already exceeded?
-        if (!stillTheSameAddress()) {
+        if (!stillTheSameAddress() && !alternates.isEmpty()) {
             alternates.remove(0);
         }
         return alternates.isEmpty() ? null : alternates.get(0);
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
index e5ffb25ce4..8c1c3cd9b4 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
@@ -377,7 +377,7 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
                 String address = (String)next;
                 Integer count = map.get(address);
                 if (count == null) {
-                    count = 0;
+                    count = map.isEmpty() ? 1 /* count first call */ : 0;
                 }
                 count++;
                 map.put(address, count);
@@ -390,7 +390,7 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
         }
 
         public int getAddressCount(String address) {
-            return map.get(address);
+            return map.get(address) - 1;
         }
     }
 }


[cxf] 01/02: CXF-8712 One-off issue with retries (#954)

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 12748832794740067e14f68c6d9036d34504e432
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Sep 29 22:32:07 2022 +0200

    CXF-8712 One-off issue with retries (#954)
    
    * CXF-8712 One-off issue with retries
    
    Immediately switch to the next alternate (address or endpoint) if the
    current one has already exceeded the maxNumberOfRetries
    
    * fix counter in CustomRetryStrategy
    
    * clarify null return value on SequentialStrategy.getNextAlternate(...)
    
    properly deal with null return value in AbstractStaticFailoverStrategy
---
 .../cxf/clustering/AbstractStaticFailoverStrategy.java   | 12 ++++++++----
 .../java/org/apache/cxf/clustering/RetryStrategy.java    |  7 ++++++-
 .../org/apache/cxf/clustering/SequentialStrategy.java    |  2 +-
 .../cxf/systest/jaxrs/failover/AbstractFailoverTest.java | 16 +++++++++-------
 4 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
index 09755dd8f6..69002a3246 100644
--- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
+++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
@@ -73,12 +73,14 @@ public abstract class AbstractStaticFailoverStrategy implements FailoverStrategy
      * Select one of the alternate addresses for a retried invocation.
      *
      * @param alternates a List of alternate addresses if available
-     * @return the selected address
+     * @return the selected address or {@code null} if no alternate address is available
      */
     public String selectAlternateAddress(List<String> alternates) {
         String selected = null;
         if (alternates != null && !alternates.isEmpty()) {
             selected = getNextAlternate(alternates);
+        }
+        if (selected != null) {
             Level level = getLogLevel();
             if (LOG.isLoggable(level)) {
                 LOG.log(level,
@@ -105,18 +107,20 @@ public abstract class AbstractStaticFailoverStrategy implements FailoverStrategy
      * Select one of the alternate endpoints for a retried invocation.
      *
      * @param alternates a List of alternate endpoints if available
-     * @return the selected endpoint
+     * @return the selected endpoint or {@code null} if no alternate endpoint is available
      */
     public Endpoint selectAlternateEndpoint(List<Endpoint> alternates) {
         Endpoint selected = null;
         if (alternates != null && !alternates.isEmpty()) {
             selected = getNextAlternate(alternates);
+        } 
+        if (selected != null) {
             Level level = getLogLevel();
             if (LOG.isLoggable(level)) {
                 LOG.log(level,
                         "FAILING_OVER_TO_ALTERNATE_ENDPOINT",
-                         new Object[] {selected.getEndpointInfo().getName(),
-                                       selected.getEndpointInfo().getAddress()});
+                        new Object[] {selected.getEndpointInfo().getName(),
+                                selected.getEndpointInfo().getAddress()});
             }
         } else {
             LOG.warning("NO_ALTERNATE_TARGETS_REMAIN");
diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
index 727bbdc025..e8e3ec235a 100644
--- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
+++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
@@ -41,8 +41,13 @@ public class RetryStrategy extends SequentialStrategy {
         return getEndpoints(exchange, stillTheSameAddress());
     }
 
+    @Override
     protected <T> T getNextAlternate(List<T> alternates) {
-        return stillTheSameAddress() ? alternates.get(0) : alternates.remove(0);
+        // is the amount of retries for the first alternate already exceeded?
+        if (!stillTheSameAddress()) {
+            alternates.remove(0);
+        }
+        return alternates.isEmpty() ? null : alternates.get(0);
     }
 
     protected boolean stillTheSameAddress() {
diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java
index 6ef077c276..4c2e685ac9 100644
--- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java
+++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/SequentialStrategy.java
@@ -32,7 +32,7 @@ public class SequentialStrategy extends AbstractStaticFailoverStrategy {
      * Get next alternate endpoint.
      *
      * @param alternates non-empty List of alternate endpoints
-     * @return
+     * @return the next endpoint or {@code null} in case there are no more alternates
      */
     protected <T> T getNextAlternate(List<T> alternates) {
         return alternates.remove(0);
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
index 4e5822d784..e5ffb25ce4 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
@@ -373,13 +373,15 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
         protected <T> T getNextAlternate(List<T> alternates) {
             totalCount++;
             T next = super.getNextAlternate(alternates);
-            String address = (String)next;
-            Integer count = map.get(address);
-            if (count == null) {
-                count = 0;
+            if (next != null) {
+                String address = (String)next;
+                Integer count = map.get(address);
+                if (count == null) {
+                    count = 0;
+                }
+                count++;
+                map.put(address, count);
             }
-            count++;
-            map.put(address, count);
             return next;
         }
 
@@ -388,7 +390,7 @@ public abstract class AbstractFailoverTest extends AbstractBusClientServerTestBa
         }
 
         public int getAddressCount(String address) {
-            return map.get(address) - 1;
+            return map.get(address);
         }
     }
 }