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);
}
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;
}
Aggregations