Search in sources :

Example 1 with RetryStrategy

use of org.apache.cxf.clustering.RetryStrategy in project cxf by apache.

the class FailoverWebClientTest method testCircuitBreakerRetryFailover.

@Test
public void testCircuitBreakerRetryFailover() throws Exception {
    String address = "http://localhost:" + PORT1 + "/bookstore/unavailable";
    final CircuitBreakerFailoverFeature feature = new CircuitBreakerFailoverFeature();
    feature.setThreshold(5);
    RetryStrategy strategy = new RetryStrategy();
    strategy.setMaxNumberOfRetries(5);
    strategy.setDelayBetweenRetries(1000);
    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());
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) Book(org.apache.cxf.systest.jaxrs.Book) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) RetryStrategy(org.apache.cxf.clustering.RetryStrategy) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 2 with RetryStrategy

use of org.apache.cxf.clustering.RetryStrategy in project cxf by apache.

the class FailoverWebClientTest method testRetryFailover.

@Test
public void testRetryFailover() throws Exception {
    String address = "http://localhost:" + PORT1 + "/bookstore/unavailable";
    final FailoverFeature feature = new FailoverFeature();
    RetryStrategy strategy = new RetryStrategy();
    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());
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) Book(org.apache.cxf.systest.jaxrs.Book) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) RetryStrategy(org.apache.cxf.clustering.RetryStrategy) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 3 with RetryStrategy

use of org.apache.cxf.clustering.RetryStrategy in project cxf by apache.

the class FailoverWebClientTest method testRetryFailoverAlternateAddresses.

@Test
public void testRetryFailoverAlternateAddresses() throws Exception {
    String address = "http://localhost:" + AbstractFailoverTest.NON_PORT + "/bookstore/unavailable";
    final FailoverFeature feature = new FailoverFeature();
    RetryStrategy strategy = new RetryStrategy();
    strategy.setAlternateAddresses(Arrays.asList("http://localhost:" + PORT1 + "/bookstore/unavailable"));
    strategy.setMaxNumberOfRetries(5);
    strategy.setDelayBetweenRetries(500);
    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("http://localhost:" + PORT1 + "/bookstore/unavailable", webClient.getBaseURI().toString());
}
Also used : JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) Book(org.apache.cxf.systest.jaxrs.Book) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) RetryStrategy(org.apache.cxf.clustering.RetryStrategy) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

RetryStrategy (org.apache.cxf.clustering.RetryStrategy)3 CircuitBreakerFailoverFeature (org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature)3 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)3 WebClient (org.apache.cxf.jaxrs.client.WebClient)3 Book (org.apache.cxf.systest.jaxrs.Book)3 Test (org.junit.Test)3 FailoverFeature (org.apache.cxf.clustering.FailoverFeature)2