cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1233076 - in /cxf/branches/2.5.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
Date Wed, 18 Jan 2012 21:54:29 GMT
Author: sergeyb
Date: Wed Jan 18 21:54:29 2012
New Revision: 1233076

URL: http://svn.apache.org/viewvc?rev=1233076&view=rev
Log:
Merged revisions 1233075 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1233075 | sergeyb | 2012-01-18 21:49:31 +0000 (Wed, 18 Jan 2012) | 1 line
  
  [CXF-3596] Minor fix to RetryStrategy
........

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1233075

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java?rev=1233076&r1=1233075&r2=1233076&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java
Wed Jan 18 21:54:29 2012
@@ -43,6 +43,10 @@ public class RetryStrategy extends Seque
     public List<Endpoint> getAlternateEndpoints(Exchange exchange) {
         return getEndpoints(exchange, stillTheSameAddress());
     }
+    
+    protected <T> T getNextAlternate(List<T> alternates) {
+        return stillTheSameAddress() ? alternates.get(0) : alternates.remove(0);
+    }
 
     protected boolean stillTheSameAddress() {
         if (maxNumberOfRetries == 0) {
@@ -50,15 +54,12 @@ public class RetryStrategy extends Seque
         }
         // let the target selector move to the next address
         // and then stay on the same address for maxNumberOfRetries
-        synchronized (this) {
-            if (++counter <= maxNumberOfRetries) {
-                return true;    
-            } else {
-                counter = 0;
-                return false;
-            }
+        if (++counter <= maxNumberOfRetries) {
+            return true;    
+        } else {
+            counter = 0;
+            return false;
         }
-        
     }
     
 

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java?rev=1233076&r1=1233075&r2=1233076&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
Wed Jan 18 21:54:29 2012
@@ -20,12 +20,15 @@
 package org.apache.cxf.systest.jaxrs.failover;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.clustering.FailoverTargetSelector;
 import org.apache.cxf.clustering.RandomStrategy;
+import org.apache.cxf.clustering.RetryStrategy;
 import org.apache.cxf.clustering.SequentialStrategy;
 import org.apache.cxf.endpoint.ConduitSelector;
 import org.apache.cxf.feature.AbstractFeature;
@@ -153,6 +156,32 @@ public class FailoverTest extends Abstra
             getFeature(false, false, "http://localhost:8182/non-existent"); 
         strategyTest(Server.ADDRESS1, feature, null, null, false, false, false);
     }
+    
+    @Test
+    public void testSequentialStrategyWithRetries() throws Exception {
+        String address = "http://localhost:8182/non-existent";
+        String address2 = "http://localhost:8182/non-existent2";
+        
+        FailoverFeature feature = new FailoverFeature();
+        List<String> alternateAddresses = new ArrayList<String>();
+        alternateAddresses.add(address);
+        alternateAddresses.add(address2);
+        CustomRetryStrategy strategy = new CustomRetryStrategy();
+        strategy.setMaxNumberOfRetries(5);
+        strategy.setAlternateAddresses(alternateAddresses);
+        feature.setStrategy(strategy);
+            
+        BookStore store = getBookStore(address, feature);
+        try {
+            store.getBook("1");
+            fail("Exception expected");
+        } catch (ClientWebApplicationException ex) {
+            assertEquals(10, strategy.getTotalCount());
+            assertEquals(5, strategy.getAddressCount(address));
+            assertEquals(5, strategy.getAddressCount(address2));
+        }
+    }
+    
 
     private FailoverFeature getFeature(boolean custom, boolean random, String ...address)
{
         FailoverFeature feature = new FailoverFeature();
@@ -342,4 +371,30 @@ public class FailoverTest extends Abstra
             return false;
         }
     }
+    
+    private static class CustomRetryStrategy extends RetryStrategy {
+        private int totalCount;
+        private Map<String, Integer> map = new HashMap<String, Integer>(); 
+        @Override
+        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; 
+            }
+            count++;
+            map.put(address, count);
+            return next;
+        }
+        
+        public int getTotalCount() {
+            return totalCount - 2;
+        }
+        
+        public int getAddressCount(String address) {
+            return map.get(address) - 1;
+        }
+    }
 }



Mime
View raw message