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 2020/05/22 22:10:38 UTC

[cxf] branch master updated: Added test case for JAXRS Failover with retry strategy

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

reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new fecff33  Added test case for JAXRS Failover with retry strategy
fecff33 is described below

commit fecff33ca0c3cbc2d98fb72e78eebbbce1534f3e
Author: reta <dr...@gmail.com>
AuthorDate: Fri May 22 18:10:17 2020 -0400

    Added test case for JAXRS Failover with retry strategy
---
 .../systest/jaxrs/failover/FailoverBookStore.java  | 11 ++++++++++
 .../jaxrs/failover/FailoverWebClientTest.java      | 24 ++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverBookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverBookStore.java
index 29b5432..f573943 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverBookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverBookStore.java
@@ -23,6 +23,7 @@ package org.apache.cxf.systest.jaxrs.failover;
 import javax.ws.rs.GET;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.Path;
+import javax.ws.rs.ServiceUnavailableException;
 
 import org.apache.cxf.systest.jaxrs.Book;
 
@@ -33,6 +34,7 @@ import org.apache.cxf.systest.jaxrs.Book;
 public class FailoverBookStore {
 
     private int counter;
+    private int unavailableCounter;
 
     @GET
     @Path("/")
@@ -44,4 +46,13 @@ public class FailoverBookStore {
         return new Book("root", 124L);
     }
 
+    
+    @GET
+    @Path("/unavailable")
+    public Book getBookRootUnavailable() {
+        if (unavailableCounter++ < 4) {
+            throw new ServiceUnavailableException();
+        }
+        return new Book("root", 124L);
+    }
 }
\ No newline at end of file
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
index 8a05b20..7aae794 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
@@ -20,11 +20,14 @@
 package org.apache.cxf.systest.jaxrs.failover;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
 import org.apache.cxf.clustering.FailoverFeature;
+import org.apache.cxf.clustering.RetryStrategy;
 import org.apache.cxf.clustering.SequentialStrategy;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.systest.jaxrs.Book;
@@ -89,5 +92,26 @@ public class FailoverWebClientTest extends AbstractBusClientServerTestBase {
         assertEquals("http://localhost:" + PORT3 + "/bookstore",
                      webClient.getBaseURI().toString());
     }
+    
+    @Test
+    public void testRetryFailover() throws Exception {
+        String address = "http://localhost:" + PORT1 + "/bookstore/unavailable";
+
+        final FailoverFeature feature = new FailoverFeature();
+        RetryStrategy strategy = new RetryStrategy();
+        strategy.setAlternateAddresses(Arrays.asList(address));
+        strategy.setMaxNumberOfRetries(5);
+        feature.setStrategy(strategy);
 
+        final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress(address);
+        bean.setFeatures(Arrays.asList(feature));
+        bean.setServiceClass(FailoverBookStore.class);
+        WebClient webClient = bean.createWebClient();
+        
+        final Book b = webClient.get(Book.class);
+        assertEquals(124L, b.getId());
+        assertEquals("root", b.getName());
+        assertEquals(address, webClient.getBaseURI().toString());
+    }
 }
\ No newline at end of file