Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 43BFFB785 for ; Wed, 18 Jan 2012 22:06:48 +0000 (UTC) Received: (qmail 59379 invoked by uid 500); 18 Jan 2012 22:06:48 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 59326 invoked by uid 500); 18 Jan 2012 22:06:47 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 59319 invoked by uid 99); 18 Jan 2012 22:06:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jan 2012 22:06:47 +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; Wed, 18 Jan 2012 22:06:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 014B223889C5 for ; Wed, 18 Jan 2012 22:06:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1233078 - in /cxf/branches/2.4.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 22:06:25 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120118220626.014B223889C5@eris.apache.org> Author: sergeyb Date: Wed Jan 18 22:06:25 2012 New Revision: 1233078 URL: http://svn.apache.org/viewvc?rev=1233078&view=rev Log: Merged revisions 1233076 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes ................ r1233076 | sergeyb | 2012-01-18 21:54:29 +0000 (Wed, 18 Jan 2012) | 9 lines 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.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Wed Jan 18 22:06:25 2012 @@ -0,0 +1,2 @@ +/cxf/branches/2.5.x-fixes:1233076 +/cxf/trunk:1233075 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java?rev=1233078&r1=1233077&r2=1233078&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java (original) +++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/clustering/RetryStrategy.java Wed Jan 18 22:06:25 2012 @@ -43,6 +43,10 @@ public class RetryStrategy extends Seque public List getAlternateEndpoints(Exchange exchange) { return getEndpoints(exchange, stillTheSameAddress()); } + + protected T getNextAlternate(List 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.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java?rev=1233078&r1=1233077&r2=1233078&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java (original) +++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java Wed Jan 18 22:06:25 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 alternateAddresses = new ArrayList(); + 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 map = new HashMap(); + @Override + protected T getNextAlternate(List 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; + } + } }