Search in sources :

Example 1 with ServiceLocator

use of org.talend.esb.servicelocator.client.ServiceLocator in project tesb-rt-se by Talend.

the class LocatorClientEnablerTest method enableClient.

@Test
public void enableClient() {
    ServiceLocator sl = createMock(ServiceLocator.class);
    Capture<LocatorTargetSelector> capturedSelector = new Capture<LocatorTargetSelector>();
    Client client = createMock(Client.class);
    expect(client.getConduitSelector()).andStubReturn(conduitSelector);
    client.setConduitSelector(capture(capturedSelector));
    replay(client);
    LocatorClientEnabler clientRegistrar = new LocatorClientEnabler();
    clientRegistrar.setServiceLocator(sl);
    clientRegistrar.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
    // clientRegistrar.setLocatorSelectionStrategy("defaultSelectionStrategy");
    clientRegistrar.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
    clientRegistrar.enable(client);
    LocatorTargetSelector selector = capturedSelector.getValue();
    assertEquals(endpoint, selector.getEndpoint());
    FailoverStrategy strategy = selector.getStrategy();
    assertThat(strategy, instanceOf(LocatorSelectionStrategy.class));
    verify(client);
}
Also used : ServiceLocator(org.talend.esb.servicelocator.client.ServiceLocator) FailoverStrategy(org.apache.cxf.clustering.FailoverStrategy) Client(org.apache.cxf.endpoint.Client) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 2 with ServiceLocator

use of org.talend.esb.servicelocator.client.ServiceLocator in project tesb-rt-se by Talend.

the class LocatorFeatureTest method initializeServer.

@Test
public void initializeServer() throws EndpointException {
    LocatorClientEnabler enabler = new LocatorClientEnabler();
    enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
    enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
    ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
    expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
    ServerLifeCycleManager slcm = new ServerLifeCycleManagerImpl();
    expect(busMock.getExtension(ServerLifeCycleManager.class)).andStubReturn(slcm);
    replayAll();
    Map<String, String> locatorProps = new HashMap<String, String>();
    locatorProps.put("key1", "value1");
    locatorProps.put("key2", "value2");
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceName(SERVICE_NAME);
    factory.setEndpointName(new QName(SERVICE_NS, "HelloWorldImplServiceInstance1"));
    factory.setServiceClass(HelloWorld.class);
    factory.setAddress("som.address/service");
    Server srv = factory.create();
    srv.getEndpoint().put(LocatorFeature.LOCATOR_PROPERTIES, locatorProps);
    srv.getEndpoint().put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
    LocatorRegistrar registrar = new LocatorRegistrar();
    ServiceLocator serviceLocator = new ServiceLocatorMock();
    registrar.setServiceLocator(serviceLocator);
    Bus bus = BusFactory.newInstance().createBus();
    EndpointInfo ei = new EndpointInfo();
    Service service = new org.apache.cxf.service.ServiceImpl();
    EndpointImpl endpoint = new EndpointImpl(busMock, service, ei);
    LocatorTargetSelector selector = new LocatorTargetSelector();
    selector.setEndpoint(endpoint);
    LocatorFeatureImpl lf = new LocatorFeatureImpl();
    lf.setLocatorRegistrar(registrar);
    lf.setClientEnabler(enabler);
    lf.initialize(srv, bus);
    SLEndpoint slEp = null;
    try {
        slEp = serviceLocator.getEndpoint(SERVICE_NAME, "HelloWorldImplServiceInstance1");
    } catch (Throwable t) {
        t.printStackTrace();
        Assert.fail(t.getMessage());
    }
    Assert.assertNotNull(slEp);
    SLProperties slProps = slEp.getProperties();
    Assert.assertNotNull(slProps);
    Assert.assertTrue(slProps.getPropertyNames().contains("key1"));
    Assert.assertTrue(slProps.getPropertyNames().contains("key2"));
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) ServerLifeCycleManagerImpl(org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl) HashMap(java.util.HashMap) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) ServiceLocator(org.talend.esb.servicelocator.client.ServiceLocator) SLProperties(org.talend.esb.servicelocator.client.SLProperties) ServiceLocatorMock(org.talend.esb.servicelocator.cxf.internal.internal.ServiceLocatorMock) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ServiceLocator (org.talend.esb.servicelocator.client.ServiceLocator)2 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)1 ServerLifeCycleManagerImpl (org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl)1 FailoverStrategy (org.apache.cxf.clustering.FailoverStrategy)1 Client (org.apache.cxf.endpoint.Client)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 Service (org.apache.cxf.service.Service)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 Capture (org.easymock.Capture)1 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)1 SLProperties (org.talend.esb.servicelocator.client.SLProperties)1 ServiceLocatorMock (org.talend.esb.servicelocator.cxf.internal.internal.ServiceLocatorMock)1