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();
}
}
}
}
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());
}
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());
}
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);
}
Aggregations