use of org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature in project cxf by apache.
the class CircuitBreakerFailoverTest method testSequentialStrategyWithElapsingCircuitBreakerTimeout.
@Test
public void testSequentialStrategyWithElapsingCircuitBreakerTimeout() throws Throwable {
FailoverFeature feature = customizeFeature(new CircuitBreakerFailoverFeature(1, 3000), false, "http://localhost:" + NON_PORT + "/non-existent", "http://localhost:" + NON_PORT + "/non-existent2");
final BookStore bookStore = getBookStore("http://localhost:" + NON_PORT + "/non-existent", feature);
// should reset all circuit breakers and the URLs could be tried again.
for (int i = 0; i < 2; ++i) {
try {
bookStore.getBook(1);
fail("Exception expected");
} catch (ProcessingException ex) {
if (!(ex.getCause() instanceof IOException)) {
throw ex.getCause();
}
}
// Let's wait a bit more than circuit breaker timeout
Thread.sleep(4000);
}
}
use of org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature 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);
}
Aggregations