Search in sources :

Example 26 with FailoverFeature

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

the class CircuitBreakerFailoverTest method testSequentialStrategyUnavailableAlternatives.

@Test(expected = FailoverFailedException.class)
public void testSequentialStrategyUnavailableAlternatives() throws Exception {
    FailoverFeature feature = getFeature(false, "http://localhost:" + NON_PORT + "/non-existent", "http://localhost:" + NON_PORT + "/non-existent2");
    final BookStore bookStore = getBookStore("http://localhost:" + NON_PORT + "/non-existent", feature);
    // Second iteration should not call any URL as all targets are not available.
    for (int i = 0; i < 2; ++i) {
        try {
            bookStore.getBook(1);
            fail("Exception expected");
        } catch (ProcessingException ex) {
            if (ex.getCause() instanceof FailoverFailedException) {
                throw (FailoverFailedException) ex.getCause();
            }
        }
    }
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) FailoverFailedException(org.apache.cxf.clustering.FailoverFailedException) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 27 with FailoverFeature

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

the class FailoverWebClientTest method testFailover.

@Test
public void testFailover() throws Exception {
    String address = "http://localhost:" + PORT1 + "/bookstore";
    FailoverFeature failoverFeature = new FailoverFeature();
    SequentialStrategy strategy = new SequentialStrategy();
    List<String> addresses = new ArrayList<>();
    addresses.add("http://localhost:" + PORT2 + "/bookstore");
    addresses.add("http://localhost:" + PORT3 + "/bookstore");
    strategy.setAlternateAddresses(addresses);
    failoverFeature.setStrategy(strategy);
    WebClient webClient = WebClient.create(address, null, Collections.singletonList(failoverFeature), null).accept("application/xml");
    // Should hit PORT1
    Book b = webClient.get(Book.class);
    assertEquals(124L, b.getId());
    assertEquals("root", b.getName());
    assertEquals("http://localhost:" + PORT1 + "/bookstore", webClient.getBaseURI().toString());
    // Should failover to PORT2
    webClient.get(Book.class);
    assertEquals(124L, b.getId());
    assertEquals("root", b.getName());
    assertEquals("http://localhost:" + PORT2 + "/bookstore", webClient.getBaseURI().toString());
    // Should failover to PORT3
    webClient.get(Book.class);
    assertEquals(124L, b.getId());
    assertEquals("root", b.getName());
    assertEquals("http://localhost:" + PORT3 + "/bookstore", webClient.getBaseURI().toString());
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Book(org.apache.cxf.systest.jaxrs.Book) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 28 with FailoverFeature

use of org.apache.cxf.clustering.FailoverFeature 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)

Example 29 with FailoverFeature

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

the class FailoverTest method testSequentialStrategyWithCustomTargetSelector2.

@Test
public void testSequentialStrategyWithCustomTargetSelector2() throws Exception {
    FailoverFeature feature = getCustomFeature(true, false, Server.ADDRESS2, Server.ADDRESS3);
    strategyTest("resolver://info", feature, Server.ADDRESS3, null, false, false, true);
}
Also used : FailoverFeature(org.apache.cxf.clustering.FailoverFeature) Test(org.junit.Test)

Aggregations

FailoverFeature (org.apache.cxf.clustering.FailoverFeature)29 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)7 CircuitBreakerFailoverFeature (org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature)7 RandomStrategy (org.apache.cxf.clustering.RandomStrategy)4 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)4 WebClient (org.apache.cxf.jaxrs.client.WebClient)4 ProcessingException (javax.ws.rs.ProcessingException)3 Book (org.apache.cxf.systest.jaxrs.Book)3 BookStore (org.apache.cxf.systest.jaxrs.BookStore)3 URL (java.net.URL)2 RetryStrategy (org.apache.cxf.clustering.RetryStrategy)2 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)2 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)2 IOException (java.io.IOException)1 List (java.util.List)1 Response (javax.ws.rs.core.Response)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1