Search in sources :

Example 16 with ConduitSelector

use of org.apache.cxf.endpoint.ConduitSelector 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 17 with ConduitSelector

use of org.apache.cxf.endpoint.ConduitSelector 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

ConduitSelector (org.apache.cxf.endpoint.ConduitSelector)17 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 FailoverTargetSelector (org.apache.cxf.clustering.FailoverTargetSelector)4 LoadDistributorTargetSelector (org.apache.cxf.clustering.LoadDistributorTargetSelector)4 ConduitSelectorHolder (org.apache.cxf.endpoint.ConduitSelectorHolder)3 WebServiceException (javax.xml.ws.WebServiceException)2 DeferredConduitSelector (org.apache.cxf.endpoint.DeferredConduitSelector)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Conduit (org.apache.cxf.transport.Conduit)2 IOException (java.io.IOException)1 List (java.util.List)1 Bus (org.apache.cxf.Bus)1 BusLifeCycleManager (org.apache.cxf.buslifecycle.BusLifeCycleManager)1 AbstractStaticFailoverStrategy (org.apache.cxf.clustering.AbstractStaticFailoverStrategy)1 UpfrontConduitSelector (org.apache.cxf.endpoint.UpfrontConduitSelector)1 Message (org.apache.cxf.message.Message)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)1 WSAddressingFeature (org.apache.cxf.ws.addressing.WSAddressingFeature)1