Search in sources :

Example 1 with EndpointsCache

use of org.apache.servicecomb.core.endpoint.EndpointsCache in project incubator-servicecomb-java-chassis by apache.

the class TestTransport method testAbstractTransport.

@Test
public void testAbstractTransport(@Mocked Microservice microservice, @Injectable InstanceCacheManager instanceCacheManager, @Injectable TransportManager transportManager, @Mocked InstanceCache instanceCache, @Injectable MicroserviceInstance instance) throws Exception {
    EndpointsCache.init(instanceCacheManager, transportManager);
    EndpointsCache oEndpointsCache = new EndpointsCache("app", "testname", "test", "rest");
    List<Endpoint> endpoionts = oEndpointsCache.getLatestEndpoints();
    Assert.assertEquals(endpoionts.size(), 0);
    Map<String, List<CacheEndpoint>> allTransportMap = new HashMap<>();
    CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://127.0.0.1:9999", instance);
    List<CacheEndpoint> restEndpoints = new ArrayList<>();
    restEndpoints.add(cacheEndpoint);
    allTransportMap.put("rest", restEndpoints);
    new Expectations() {

        {
            instanceCacheManager.getOrCreate(anyString, anyString, anyString);
            result = instanceCache;
            instanceCache.cacheChanged((InstanceCache) any);
            result = true;
            instanceCache.getOrCreateTransportMap();
            result = allTransportMap;
        }
    };
    endpoionts = oEndpointsCache.getLatestEndpoints();
    Assert.assertEquals(endpoionts.size(), 1);
}
Also used : Expectations(mockit.Expectations) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) HashMap(java.util.HashMap) CacheEndpoint(org.apache.servicecomb.serviceregistry.cache.CacheEndpoint) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EndpointsCache(org.apache.servicecomb.core.endpoint.EndpointsCache) Test(org.junit.Test)

Example 2 with EndpointsCache

use of org.apache.servicecomb.core.endpoint.EndpointsCache in project incubator-servicecomb-java-chassis by apache.

the class Consumer method prepareEdge.

private URIEndpointObject prepareEdge() {
    Microservice microservice = RegistryUtils.getMicroservice();
    EndpointsCache endpointsCache = new EndpointsCache(microservice.getAppId(), "edge", "latest", "");
    Endpoint ep = endpointsCache.getLatestEndpoints().get(0);
    URIEndpointObject edgeAddress = (URIEndpointObject) ep.getAddress();
    edgePrefix = String.format("http://%s:%d/api/business", edgeAddress.getHostOrIp(), edgeAddress.getPort());
    return edgeAddress;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Endpoint(org.apache.servicecomb.core.Endpoint) EndpointsCache(org.apache.servicecomb.core.endpoint.EndpointsCache) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

EndpointsCache (org.apache.servicecomb.core.endpoint.EndpointsCache)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Expectations (mockit.Expectations)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 CacheEndpoint (org.apache.servicecomb.serviceregistry.cache.CacheEndpoint)1 Test (org.junit.Test)1