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 2015/12/08 03:54:24 UTC

cxf git commit: CXF-6622: Enhance Failover Feature to support Circuit Breakers based implementation. Failover test cases refactorings.

Repository: cxf
Updated Branches:
  refs/heads/master 111d52fd4 -> a21976635


CXF-6622: Enhance Failover Feature to support Circuit Breakers based implementation. Failover test cases refactorings.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a2197663
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2197663
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2197663

Branch: refs/heads/master
Commit: a219766354d6aee53c7f7a4da91f434af552b437
Parents: 111d52f
Author: reta <dr...@gmail.com>
Authored: Mon Dec 7 21:54:10 2015 -0500
Committer: reta <dr...@gmail.com>
Committed: Mon Dec 7 21:54:10 2015 -0500

----------------------------------------------------------------------
 .../CircuitBreakerTargetSelector.java           |  6 +-
 .../clustering/CircuitBreakerFailoverTest.java  | 40 ++++++++++++++
 .../cxf/systest/clustering/FailoverTest.java    |  5 --
 .../systest/clustering/LoadDistributorTest.java | 20 +++++--
 .../clustering/circuit_breaker_failover.xml     | 58 ++++++++++++++++++++
 .../apache/cxf/systest/clustering/failover.xml  |  9 ---
 6 files changed, 117 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a2197663/rt/features/clustering/src/main/java/org/apache/cxf/clustering/CircuitBreakerTargetSelector.java
----------------------------------------------------------------------
diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/CircuitBreakerTargetSelector.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/CircuitBreakerTargetSelector.java
index bf84e20..4872959 100644
--- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/CircuitBreakerTargetSelector.java
+++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/CircuitBreakerTargetSelector.java
@@ -221,7 +221,7 @@ public class CircuitBreakerTargetSelector extends FailoverTargetSelector {
     }
     
     private synchronized CircuitBreaker getCircuitBreaker(final String alternateAddress) {
-        CircuitBreaker circuitBreaker =  NOOP_CIRCUIT_BREAKER;
+        CircuitBreaker circuitBreaker = null;
         
         if (!StringUtils.isEmpty(alternateAddress)) {
             for (Map.Entry<String, CircuitBreaker> entry: circuits.entrySet()) {
@@ -237,6 +237,10 @@ public class CircuitBreakerTargetSelector extends FailoverTargetSelector {
             }
         }
         
+        if (circuitBreaker == null) {
+            circuitBreaker = NOOP_CIRCUIT_BREAKER;
+        }
+        
         return circuitBreaker;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2197663/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/CircuitBreakerFailoverTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/CircuitBreakerFailoverTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/CircuitBreakerFailoverTest.java
new file mode 100644
index 0000000..14ea048
--- /dev/null
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/CircuitBreakerFailoverTest.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.systest.clustering;
+
+import org.junit.Test;
+
+
+/**
+ * Tests failover within a static cluster.
+ */
+public class CircuitBreakerFailoverTest extends FailoverTest {
+    private static final String FAILOVER_CONFIG =
+            "org/apache/cxf/systest/clustering/circuit_breaker_failover.xml";
+
+    protected String getConfig() {
+        return FAILOVER_CONFIG;
+    }
+    
+    @Test
+    public void testDefaultSequentialStrategyWithCircuitBreaker() throws Exception {
+        strategyTest(REPLICA_B, REPLICA_C, REPLICA_E, false);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2197663/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverTest.java
index d548f0b..ccf5b09 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/FailoverTest.java
@@ -335,11 +335,6 @@ public class FailoverTest extends AbstractBusClientServerTestBase {
         strategyTest(REPLICA_A, REPLICA_B, REPLICA_C, true);
     }
     
-    @Test
-    public void testDefaultSequentialStrategyWithCircuitBreaker() throws Exception {
-        strategyTest(REPLICA_B, REPLICA_C, REPLICA_E, false);
-    }
- 
     protected Greeter getGreeter(String type) throws Exception {
         if (REPLICA_A.equals(type)) {
             Greeter g = new ClusteredGreeterService().getReplicatedPortA();

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2197663/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorTest.java
index eea6f4b..39cc5c4 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorTest.java
@@ -47,6 +47,8 @@ public class LoadDistributorTest extends FailoverTest {
             return REPLICA_B;
         } else if (response.endsWith(REPLICA_C)) {
             return REPLICA_C;
+        } else if (response.endsWith(REPLICA_E)) {
+            return REPLICA_E;
         } else {
             return response;
         }
@@ -76,6 +78,7 @@ public class LoadDistributorTest extends FailoverTest {
         startTarget(REPLICA_A);
         startTarget(REPLICA_B);
         startTarget(REPLICA_C);
+        startTarget(REPLICA_E);
         setupGreeter();
 
         // Change the strategy to iterate through the endpoints
@@ -95,12 +98,14 @@ public class LoadDistributorTest extends FailoverTest {
             assertNotNull("expected non-null response", response);
             incrementResponseCount(responseCounts, response);
         }
-        assertEquals(4, (long)responseCounts.get(REPLICA_A));
-        assertEquals(4, (long)responseCounts.get(REPLICA_B));
-        assertEquals(4, (long)responseCounts.get(REPLICA_C));
+        assertEquals(3, (long)responseCounts.get(REPLICA_A));
+        assertEquals(3, (long)responseCounts.get(REPLICA_B));
+        assertEquals(3, (long)responseCounts.get(REPLICA_C));
+        assertEquals(3, (long)responseCounts.get(REPLICA_E));
         stopTarget(REPLICA_A);
         stopTarget(REPLICA_B);
         stopTarget(REPLICA_C);
+        stopTarget(REPLICA_E);
     }
     
     @Test
@@ -136,6 +141,7 @@ public class LoadDistributorTest extends FailoverTest {
         startTarget(REPLICA_A);
         startTarget(REPLICA_B);
         startTarget(REPLICA_C);
+        startTarget(REPLICA_E);
         setupGreeter();
         stopTarget(REPLICA_B);
         ConduitSelector conduitSelector =
@@ -158,12 +164,14 @@ public class LoadDistributorTest extends FailoverTest {
                 incrementResponseCount(responseCounts, "");
             }
         }
-        assertEquals(4, (long)responseCounts.get(REPLICA_A));
+        assertEquals(3, (long)responseCounts.get(REPLICA_A));
         assertEquals(null, responseCounts.get(REPLICA_B));
-        assertEquals(4, (long)responseCounts.get(REPLICA_C));
-        assertEquals(4, (long)responseCounts.get(""));
+        assertEquals(3, (long)responseCounts.get(REPLICA_C));
+        assertEquals(3, (long)responseCounts.get(REPLICA_E));
+        assertEquals(3, (long)responseCounts.get(""));
         stopTarget(REPLICA_A);
         stopTarget(REPLICA_C);
+        stopTarget(REPLICA_E);
     }
     
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2197663/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/circuit_breaker_failover.xml
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/circuit_breaker_failover.xml b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/circuit_breaker_failover.xml
new file mode 100644
index 0000000..454bebf
--- /dev/null
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/circuit_breaker_failover.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+ 
+  http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:clustering="http://cxf.apache.org/clustering" xmlns:http="http://cxf.apache.org/transports/http/configuration" xsi:schemaLocation=" http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/clustering http://cxf.apache.org/schemas/clustering.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+    <bean id="Sequential" class="org.apache.cxf.clustering.SequentialStrategy"/>
+    <bean id="Random" class="org.apache.cxf.clustering.RandomStrategy"/>
+    <jaxws:client name="{http://cxf.apache.org/greeter_control}ReplicatedPortA" createdFromAPI="true">
+        <jaxws:features>
+            <clustering:circuit-breaker-failover/>
+        </jaxws:features>
+    </jaxws:client>
+    <jaxws:client name="{http://cxf.apache.org/greeter_control}ReplicatedPortB" createdFromAPI="true">
+        <jaxws:features>
+            <clustering:circuit-breaker-failover threshold="1" timeout="60000">
+                <clustering:strategy>
+                    <ref bean="Sequential"/>
+                </clustering:strategy>
+            </clustering:circuit-breaker-failover>
+        </jaxws:features>
+    </jaxws:client>
+    <jaxws:client name="{http://cxf.apache.org/greeter_control}ReplicatedPortC" createdFromAPI="true">
+        <jaxws:features>
+            <clustering:circuit-breaker-failover threshold="1" timeout="60000">
+                <clustering:strategy>
+                    <ref bean="Random"/>
+                </clustering:strategy>
+            </clustering:circuit-breaker-failover>
+        </jaxws:features>
+    </jaxws:client>
+    <jaxws:client name="{http://cxf.apache.org/greeter_control}ReplicatedPortE" createdFromAPI="true">
+        <jaxws:features>
+            <clustering:circuit-breaker-failover threshold="1" timeout="60000">
+                <clustering:strategy>
+                    <ref bean="Sequential"/>
+                </clustering:strategy>
+            </clustering:circuit-breaker-failover>
+        </jaxws:features>
+    </jaxws:client>
+    <http:conduit name="http://localhost:.*">
+        <http:client Connection="close"/>
+    </http:conduit>
+</beans>

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2197663/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover.xml
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover.xml b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover.xml
index 7e761e0..089c533 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover.xml
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/failover.xml
@@ -43,15 +43,6 @@
             </clustering:failover>
         </jaxws:features>
     </jaxws:client>
-    <jaxws:client name="{http://cxf.apache.org/greeter_control}ReplicatedPortE" createdFromAPI="true">
-        <jaxws:features>
-            <clustering:circuit-breaker-failover threshold="1" timeout="60000">
-                <clustering:strategy>
-                    <ref bean="Sequential"/>
-                </clustering:strategy>
-            </clustering:circuit-breaker-failover>
-        </jaxws:features>
-    </jaxws:client>
     <http:conduit name="http://localhost:.*">
         <http:client Connection="close"/>
     </http:conduit>