Search in sources :

Example 1 with LoadDistributorTargetSelector

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);
}
Also used : HashMap(java.util.HashMap) LoadDistributorTargetSelector(org.apache.cxf.clustering.LoadDistributorTargetSelector) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) Test(org.junit.Test)

Example 2 with LoadDistributorTargetSelector

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;
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) LoadDistributorTargetSelector(org.apache.cxf.clustering.LoadDistributorTargetSelector) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) ArrayList(java.util.ArrayList)

Example 3 with LoadDistributorTargetSelector

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);
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) LoadDistributorTargetSelector(org.apache.cxf.clustering.LoadDistributorTargetSelector) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) Test(org.junit.Test)

Example 4 with LoadDistributorTargetSelector

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);
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) HashMap(java.util.HashMap) LoadDistributorTargetSelector(org.apache.cxf.clustering.LoadDistributorTargetSelector) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) Test(org.junit.Test)

Example 5 with LoadDistributorTargetSelector

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);
}
Also used : HashMap(java.util.HashMap) LoadDistributorTargetSelector(org.apache.cxf.clustering.LoadDistributorTargetSelector) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) Test(org.junit.Test)

Aggregations

LoadDistributorTargetSelector (org.apache.cxf.clustering.LoadDistributorTargetSelector)5 HashMap (java.util.HashMap)4 ConduitSelector (org.apache.cxf.endpoint.ConduitSelector)4 Test (org.junit.Test)4 WebServiceException (javax.xml.ws.WebServiceException)2 ArrayList (java.util.ArrayList)1 FailoverFeature (org.apache.cxf.clustering.FailoverFeature)1 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)1