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