Search in sources :

Example 6 with ConduitSelector

use of org.apache.cxf.endpoint.ConduitSelector in project cxf by apache.

the class ProxyTest method testRMClientGetConduit.

@Test
public void testRMClientGetConduit() throws Exception {
    Proxy proxy = new Proxy(rme);
    Bus bus = control.createMock(Bus.class);
    Endpoint endpoint = control.createMock(Endpoint.class);
    Conduit conduit = control.createMock(Conduit.class);
    ConduitSelector cs = control.createMock(ConduitSelector.class);
    EasyMock.expect(cs.selectConduit(EasyMock.isA(Message.class))).andReturn(conduit).anyTimes();
    control.replay();
    Proxy.RMClient client = proxy.new RMClient(bus, endpoint, cs);
    assertSame(conduit, client.getConduit());
    client.close();
}
Also used : Bus(org.apache.cxf.Bus) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) Test(org.junit.Test)

Example 7 with ConduitSelector

use of org.apache.cxf.endpoint.ConduitSelector in project cxf by apache.

the class FailoverAddressOverrideTest method verifyStrategy.

protected void verifyStrategy(Object proxy, Class<?> clz, int count) {
    ConduitSelector conduitSelector = ClientProxy.getClient(proxy).getConduitSelector();
    if (conduitSelector instanceof FailoverTargetSelector) {
        AbstractStaticFailoverStrategy strategy = (AbstractStaticFailoverStrategy) ((FailoverTargetSelector) conduitSelector).getStrategy();
        assertTrue("unexpected strategy", clz.isInstance(strategy));
        List<String> alternates = strategy.getAlternateAddresses(null);
        assertNotNull("expected alternate addresses", alternates);
        assertEquals("unexpected alternate addresses", count, alternates.size());
    } else {
        fail("unexpected conduit selector: " + conduitSelector);
    }
}
Also used : AbstractStaticFailoverStrategy(org.apache.cxf.clustering.AbstractStaticFailoverStrategy) FailoverTargetSelector(org.apache.cxf.clustering.FailoverTargetSelector) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector)

Example 8 with ConduitSelector

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

use of org.apache.cxf.endpoint.ConduitSelector in project cxf by apache.

the class FailoverTest method verifyStrategy.

protected void verifyStrategy(Object proxy, Class<?> clz) {
    ConduitSelector conduitSelector = ClientProxy.getClient(proxy).getConduitSelector();
    if (conduitSelector instanceof FailoverTargetSelector) {
        Object strategy = ((FailoverTargetSelector) conduitSelector).getStrategy();
        assertTrue("unexpected strategy", clz.isInstance(strategy));
    } else {
        fail("unexpected conduit selector: " + conduitSelector);
    }
}
Also used : FailoverTargetSelector(org.apache.cxf.clustering.FailoverTargetSelector) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector)

Example 10 with ConduitSelector

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

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