Search in sources :

Example 1 with Number

use of org.apache.coheigea.cxf.failover.common.Number 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 Number

use of org.apache.coheigea.cxf.failover.common.Number in project testcases by coheigea.

the class FailoverTest method testCircuitBreaker.

@org.junit.Test
public void testCircuitBreaker() throws Exception {
    URL busFile = FailoverTest.class.getResource("cxf-client.xml");
    CircuitBreakerFailoverFeature feature = new CircuitBreakerFailoverFeature();
    feature.setThreshold(2);
    SequentialStrategy strategy = new SequentialStrategy();
    strategy.setDelayBetweenRetries(3000L);
    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) CircuitBreakerFailoverFeature(org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 3 with Number

use of org.apache.coheigea.cxf.failover.common.Number in project testcases by coheigea.

the class DoubleItService method doubleIt.

@POST
@Produces("application/xml")
@Consumes("application/xml")
public Number doubleIt(Number numberToDouble) {
    Number newNumber = new Number();
    newNumber.setDescription(numberToDouble.getDescription());
    newNumber.setNumber(numberToDouble.getNumber() * 2);
    return newNumber;
}
Also used : Number(org.apache.coheigea.cxf.failover.common.Number) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 4 with Number

use of org.apache.coheigea.cxf.failover.common.Number in project testcases by coheigea.

the class DoubleItService method doubleIt.

@POST
@Produces("application/xml")
@Consumes("application/xml")
public Number doubleIt(Number numberToDouble) {
    counter++;
    if (counter % 2 == 0) {
        throw new NotFoundException("Error");
    }
    Number newNumber = new Number();
    newNumber.setDescription(numberToDouble.getDescription());
    newNumber.setNumber(numberToDouble.getNumber() * 2);
    return newNumber;
}
Also used : Number(org.apache.coheigea.cxf.failover.common.Number) NotFoundException(javax.ws.rs.NotFoundException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 5 with Number

use of org.apache.coheigea.cxf.failover.common.Number in project testcases by coheigea.

the class LoadBalancerTest method testLoadBalancerFeature.

@org.junit.Test
public void testLoadBalancerFeature() throws Exception {
    URL busFile = LoadBalancerTest.class.getResource("cxf-client.xml");
    LoadDistributorFeature feature = new LoadDistributorFeature();
    SequentialStrategy strategy = new SequentialStrategy();
    List<String> addresses = new ArrayList<>();
    addresses.add("http://localhost:" + PORT1 + "/doubleit/services");
    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 is successful 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) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Aggregations

Number (org.apache.coheigea.cxf.failover.common.Number)5 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)3 WebClient (org.apache.cxf.jaxrs.client.WebClient)3 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 CircuitBreakerFailoverFeature (org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature)2 NotFoundException (javax.ws.rs.NotFoundException)1 FailoverFeature (org.apache.cxf.clustering.FailoverFeature)1 LoadDistributorFeature (org.apache.cxf.clustering.LoadDistributorFeature)1