use of org.apache.cxf.clustering.LoadDistributorTargetSelector in project cxf by apache.
the class LoadDistributorTest method testDistributedSequentialStrategyWithFailover.
@Test
public void testDistributedSequentialStrategyWithFailover() throws Exception {
startTarget(REPLICA_A);
startTarget(REPLICA_B);
startTarget(REPLICA_C);
setupGreeter();
stopTarget(REPLICA_B);
ConduitSelector conduitSelector = ClientProxy.getClient(greeter).getConduitSelector();
if (conduitSelector instanceof LoadDistributorTargetSelector) {
((LoadDistributorTargetSelector) conduitSelector).setStrategy(new LoadDistributorStaticStrategy());
} else {
fail("unexpected conduit selector: " + conduitSelector);
}
Map<String, Integer> responseCounts = new HashMap<>();
for (int i = 0; i < 12; ++i) {
String response = greeter.greetMe("fred");
assertNotNull("expected non-null response", response);
incrementResponseCount(responseCounts, response);
}
assertTrue((long) responseCounts.get(REPLICA_A) > 0);
assertTrue((long) responseCounts.get(REPLICA_C) > 0);
assertEquals(12, responseCounts.get(REPLICA_A) + responseCounts.get(REPLICA_C));
stopTarget(REPLICA_A);
stopTarget(REPLICA_C);
}
use of org.apache.cxf.clustering.LoadDistributorTargetSelector in project cxf by apache.
the class LoadDistributorTest method getFeature.
private FailoverFeature getFeature(String... address) {
FailoverFeature feature = new FailoverFeature();
List<String> alternateAddresses = new ArrayList<>();
for (String s : address) {
alternateAddresses.add(s);
}
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
LoadDistributorTargetSelector selector = new LoadDistributorTargetSelector();
selector.setFailover(false);
feature.setTargetSelector(selector);
return feature;
}
use of org.apache.cxf.clustering.LoadDistributorTargetSelector in project cxf by apache.
the class LoadDistributorAddressOverrideTest method testDistributedSequentialStrategyWithoutFailover.
@Test
public void testDistributedSequentialStrategyWithoutFailover() throws Exception {
startTarget(REPLICA_A);
startTarget(REPLICA_C);
setupGreeterA();
verifyStrategy(greeter, SequentialStrategy.class, 3);
ConduitSelector conduitSelector = ClientProxy.getClient(greeter).getConduitSelector();
if (conduitSelector instanceof LoadDistributorTargetSelector) {
((LoadDistributorTargetSelector) conduitSelector).setFailover(false);
} else {
fail("unexpected conduit selector: " + conduitSelector);
}
Map<String, Integer> responseCounts = new HashMap<>();
for (int i = 0; i < 12; ++i) {
try {
String response = greeter.greetMe("fred");
assertNotNull("expected non-null response", response);
incrementResponseCount(responseCounts, response);
} catch (WebServiceException ex) {
incrementResponseCount(responseCounts, "");
}
}
assertEquals(4, (long) responseCounts.get(REPLICA_A));
assertEquals(null, responseCounts.get(REPLICA_B));
assertEquals(4, (long) responseCounts.get(REPLICA_C));
assertEquals(4, (long) responseCounts.get(""));
verifyCurrentEndpoint(REPLICA_C);
stopTarget(REPLICA_A);
stopTarget(REPLICA_C);
}
use of org.apache.cxf.clustering.LoadDistributorTargetSelector in project cxf by apache.
the class LoadDistributorTest method testDistributedSequentialStrategyWithoutFailover.
@Test
public void testDistributedSequentialStrategyWithoutFailover() throws Exception {
startTarget(REPLICA_A);
startTarget(REPLICA_B);
startTarget(REPLICA_C);
startTarget(REPLICA_E);
setupGreeter();
stopTarget(REPLICA_B);
ConduitSelector conduitSelector = ClientProxy.getClient(greeter).getConduitSelector();
if (conduitSelector instanceof LoadDistributorTargetSelector) {
((LoadDistributorTargetSelector) conduitSelector).setStrategy(new LoadDistributorStaticStrategy());
((LoadDistributorTargetSelector) conduitSelector).setFailover(false);
} else {
fail("unexpected conduit selector: " + conduitSelector);
}
Map<String, Integer> responseCounts = new HashMap<>();
for (int i = 0; i < 12; ++i) {
try {
String response = greeter.greetMe("fred");
assertNotNull("expected non-null response", response);
incrementResponseCount(responseCounts, response);
} catch (WebServiceException ex) {
incrementResponseCount(responseCounts, "");
}
}
assertEquals(3, (long) responseCounts.get(REPLICA_A));
assertEquals(null, responseCounts.get(REPLICA_B));
assertEquals(3, (long) responseCounts.get(REPLICA_C));
assertEquals(3, (long) responseCounts.get(REPLICA_E));
assertEquals(3, (long) responseCounts.get(""));
stopTarget(REPLICA_A);
stopTarget(REPLICA_C);
stopTarget(REPLICA_E);
}
use of org.apache.cxf.clustering.LoadDistributorTargetSelector in project cxf by apache.
the class LoadDistributorTest method testDistributedSequentialStrategy.
@Test
public void testDistributedSequentialStrategy() throws Exception {
startTarget(REPLICA_A);
startTarget(REPLICA_B);
startTarget(REPLICA_C);
startTarget(REPLICA_E);
setupGreeter();
// Change the strategy to iterate through the endpoints
ConduitSelector conduitSelector = ClientProxy.getClient(greeter).getConduitSelector();
if (conduitSelector instanceof LoadDistributorTargetSelector) {
((LoadDistributorTargetSelector) conduitSelector).setStrategy(new LoadDistributorStaticStrategy());
} else {
fail("unexpected conduit selector: " + conduitSelector);
}
Map<String, Integer> responseCounts = new HashMap<>();
for (int i = 0; i < 12; ++i) {
String response = greeter.greetMe("fred");
assertNotNull("expected non-null response", response);
incrementResponseCount(responseCounts, response);
}
assertEquals(3, (long) responseCounts.get(REPLICA_A));
assertEquals(3, (long) responseCounts.get(REPLICA_B));
assertEquals(3, (long) responseCounts.get(REPLICA_C));
assertEquals(3, (long) responseCounts.get(REPLICA_E));
stopTarget(REPLICA_A);
stopTarget(REPLICA_B);
stopTarget(REPLICA_C);
stopTarget(REPLICA_E);
}
Aggregations