use of org.apache.cxf.clustering.SequentialStrategy 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);
}
use of org.apache.cxf.clustering.SequentialStrategy 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);
}
use of org.apache.cxf.clustering.SequentialStrategy 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());
}
use of org.apache.cxf.clustering.SequentialStrategy in project cxf by apache.
the class LoadDistributorTest method testSingleAltAddress.
@Test
public void testSingleAltAddress() throws Exception {
LoadDistributorFeature feature = new LoadDistributorFeature();
List<String> alternateAddresses = new ArrayList<>();
alternateAddresses.add(Server.ADDRESS2);
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
BookStore bookStore = getBookStore(Server.ADDRESS1, feature);
Book book = bookStore.getBook("123");
assertEquals("unexpected id", 123L, book.getId());
book = bookStore.getBook("123");
assertEquals("unexpected id", 123L, book.getId());
}
use of org.apache.cxf.clustering.SequentialStrategy 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);
}
Aggregations