Search in sources :

Example 1 with FailoverFeature

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

the class FailoverTest method testFailoverFeature.

@org.junit.Test
public void testFailoverFeature() throws Exception {
    URL busFile = FailoverTest.class.getResource("cxf-client.xml");
    FailoverFeature feature = new FailoverFeature();
    SequentialStrategy strategy = new SequentialStrategy();
    List<String> addresses = new ArrayList<>();
    addresses.add("http://localhost:" + PORT2 + "/doubleit/services");
    strategy.setAlternateAddresses(addresses);
    feature.setStrategy(strategy);
    String address = "http://localhost:" + PORT1 + "/doubleit/services";
    WebClient client = WebClient.create(address, null, Collections.singletonList(feature), busFile.toString());
    client = client.type("application/xml");
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    // First call is successful to PORT1
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
    // Second call fails over to PORT2
    response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Number(org.apache.coheigea.cxf.failover.common.Number) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 2 with FailoverFeature

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

the class JaxwsAsyncFailOverTest method testUseFailOverOnClient.

@Test
public void testUseFailOverOnClient() throws Exception {
    List<String> serviceList = new ArrayList<>();
    serviceList.add("http://localhost:" + PORT + "/SoapContext/GreeterPort");
    RandomStrategy strategy = new RandomStrategy();
    strategy.setAlternateAddresses(serviceList);
    FailoverFeature ff = new FailoverFeature();
    ff.setStrategy(strategy);
    // setup the feature by using JAXWS front-end API
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    // set a fake address to kick off the failover feature
    factory.setAddress("http://localhost:" + PORT2 + "/SoapContext/GreeterPort");
    factory.getFeatures().add(ff);
    factory.setServiceClass(Greeter.class);
    Greeter proxy = factory.create(Greeter.class);
    Response<GreetMeResponse> response = proxy.greetMeAsync("cxf");
    int waitCount = 0;
    while (!response.isDone() && waitCount < 15) {
        Thread.sleep(1000);
        waitCount++;
    }
    assertTrue("Response still not received.", response.isDone());
}
Also used : RandomStrategy(org.apache.cxf.clustering.RandomStrategy) Greeter(org.apache.cxf.greeter_control.Greeter) ArrayList(java.util.ArrayList) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) GreetMeResponse(org.apache.cxf.greeter_control.types.GreetMeResponse) Test(org.junit.Test)

Example 3 with FailoverFeature

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

the class AbstractFailoverTest method testSequentialStrategyWithServerException.

@Test(expected = InternalServerErrorException.class)
public void testSequentialStrategyWithServerException() throws Exception {
    FailoverFeature feature = getFeature(false, Server.ADDRESS2, Server.ADDRESS3);
    strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, true, false, false);
}
Also used : FailoverFeature(org.apache.cxf.clustering.FailoverFeature) Test(org.junit.Test)

Example 4 with FailoverFeature

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

the class AbstractFailoverTest method testSequentialStrategyWithRetries.

@Test
public void testSequentialStrategyWithRetries() throws Exception {
    String address = "http://localhost:" + NON_PORT + "/non-existent";
    String address2 = "http://localhost:" + NON_PORT + "/non-existent2";
    CustomRetryStrategy strategy = new CustomRetryStrategy();
    strategy.setMaxNumberOfRetries(5);
    strategy.setAlternateAddresses(Arrays.asList(address, address2));
    FailoverFeature feature = new FailoverFeature();
    feature.setStrategy(strategy);
    BookStore store = getBookStore(address, feature);
    try {
        store.getBook("1");
        fail("Exception expected");
    } catch (ProcessingException ex) {
        assertEquals(10, strategy.getTotalCount());
        assertEquals(5, strategy.getAddressCount(address));
        assertEquals(5, strategy.getAddressCount(address2));
    }
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 5 with FailoverFeature

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

the class AbstractFailoverTest method testSequentialStrategyWithDiffBaseAddresses.

@Test
public void testSequentialStrategyWithDiffBaseAddresses() throws Exception {
    FailoverFeature feature = getFeature(false, Server.ADDRESS3, null);
    strategyTest(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2, false, false, false);
}
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