Search in sources :

Example 1 with Transport

use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.

the class AbstractEndpointsCache method createEndpoints.

protected List<ENDPOINT> createEndpoints(Map<String, List<CacheEndpoint>> transportMap) {
    List<ENDPOINT> tmpEndpoints = new ArrayList<>();
    for (Entry<String, List<CacheEndpoint>> entry : transportMap.entrySet()) {
        Transport transport = transportManager.findTransport(entry.getKey());
        if (transport == null) {
            continue;
        }
        List<CacheEndpoint> endpointList = entry.getValue();
        if (endpointList == null) {
            continue;
        }
        for (CacheEndpoint cacheEndpont : endpointList) {
            ENDPOINT endpoint = createEndpoint(transport, cacheEndpont);
            tmpEndpoints.add(endpoint);
        }
    }
    return tmpEndpoints;
}
Also used : CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Transport(io.servicecomb.core.Transport)

Example 2 with Transport

use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.

the class TestServerListCache method mockTestCases.

private void mockTestCases() {
    final Microservice microService = new Microservice();
    microService.setAppId("appId");
    new MockUp<RegistryUtils>() {

        @Mock
        public Microservice getMicroservice() {
            return microService;
        }

        @Mock
        private Microservice createMicroserviceFromDefinition() {
            return microService;
        }
    };
    new MockUp<InstanceCacheManager>() {

        @Mock
        public InstanceCache getOrCreate(String appId, String microserviceName, String microserviceVersionRule) {
            return null;
        }
    };
    transport = Mockito.mock(Transport.class);
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) MockUp(mockit.MockUp) Transport(io.servicecomb.core.Transport)

Example 3 with Transport

use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.

the class TestSessionSticknessRule method testRuleFullOperation.

@Test
public void testRuleFullOperation() {
    SessionStickinessRule rule = new SessionStickinessRule();
    LoadBalancer mockedLb = mock(LoadBalancer.class);
    Transport transport = mock(Transport.class);
    CseServer mockedServer = new CseServer(transport, new CacheEndpoint("rest:127.0.0.1:8888", null));
    Object key = Mockito.mock(Object.class);
    LoadBalancerStats stats = mock(LoadBalancerStats.class);
    Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
    Deencapsulation.invoke(rule, "chooseServerWhenTimeout", key);
    mockedServer.setAlive(true);
    mockedServer.setReadyToServe(true);
    List<Server> allServers = Arrays.asList(mockedServer);
    when(mockedLb.getReachableServers()).thenReturn(allServers);
    when(mockedLb.getAllServers()).thenReturn(allServers);
    rule.setLoadBalancer(mockedLb);
    Assert.assertEquals(rule.getLoadBalancer(), mockedLb);
    Server s = rule.choose("default");
    Assert.assertEquals(s, mockedServer);
    s = rule.choose("default");
    Assert.assertEquals(s, mockedServer);
}
Also used : Server(com.netflix.loadbalancer.Server) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) Transport(io.servicecomb.core.Transport) Test(org.junit.Test)

Example 4 with Transport

use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.

the class TransportManager method init.

public void init() throws Exception {
    AbstractEndpointsCache.setTransportManager(this);
    for (Transport transport : transportList) {
        transportMap.put(transport.getName(), transport);
        if (transport.init()) {
            Endpoint endpoint = transport.getPublishEndpoint();
            if (endpoint != null && endpoint.getEndpoint() != null) {
                LOGGER.info("endpoint to publish: {}", endpoint.getEndpoint());
                RegistryUtils.getMicroserviceInstance().getEndpoints().add(endpoint.getEndpoint());
            }
            continue;
        }
    }
}
Also used : Endpoint(io.servicecomb.core.Endpoint) Transport(io.servicecomb.core.Transport)

Aggregations

Transport (io.servicecomb.core.Transport)4 CacheEndpoint (io.servicecomb.serviceregistry.cache.CacheEndpoint)2 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)1 Server (com.netflix.loadbalancer.Server)1 Endpoint (io.servicecomb.core.Endpoint)1 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MockUp (mockit.MockUp)1 Test (org.junit.Test)1