use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class IpPortManager method getAvailableAddress.
private IpPort getAvailableAddress(int index) {
if (index < defaultIpPort.size()) {
return defaultIpPort.get(index);
}
List<CacheEndpoint> endpoints = getDiscoveredIpPort();
if (endpoints == null || (index >= defaultIpPort.size() + endpoints.size())) {
currentAvailableIndex.set(0);
return defaultIpPort.get(0);
}
CacheEndpoint nextEndpoint = endpoints.get(index - defaultIpPort.size());
return new URIEndpointObject(nextEndpoint.getEndpoint());
}
use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
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 cacheEndpoint : endpointList) {
ENDPOINT endpoint = createEndpoint(transport, cacheEndpoint);
tmpEndpoints.add(endpoint);
}
}
return tmpEndpoints;
}
use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint 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.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method send_success.
@Test
public void send_success() {
CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://localhost:8080", null);
CseServer server = new CseServer(restTransport, cacheEndpoint);
new MockUp<System>() {
@Mock
long currentTimeMillis() {
return 123;
}
};
new Expectations(loadBalancer) {
{
loadBalancer.chooseServer(invocation);
result = server;
}
};
server.incrementContinuousFailureCount();
sendResponse = Response.ok("success");
Holder<String> result = new Holder<>();
Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
result.value = resp.getResult();
}, loadBalancer);
Assert.assertEquals(123, server.getLastVisitTime());
Assert.assertEquals(1, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getActiveRequestsCount());
Assert.assertEquals("success", result.value);
Assert.assertEquals(0, server.getCountinuousFailureCount());
}
use of org.apache.servicecomb.serviceregistry.cache.CacheEndpoint in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method send_failed.
@Test
public void send_failed() {
CacheEndpoint cacheEndpoint = new CacheEndpoint("rest://localhost:8080", null);
CseServer server = new CseServer(restTransport, cacheEndpoint);
new MockUp<System>() {
@Mock
long currentTimeMillis() {
return 123;
}
};
new Expectations(loadBalancer) {
{
loadBalancer.chooseServer(invocation);
result = server;
}
};
int continuousFailureCount = server.getCountinuousFailureCount();
sendResponse = Response.create(Status.BAD_REQUEST, "send failed");
Holder<Throwable> result = new Holder<>();
Deencapsulation.invoke(handler, "send", invocation, (AsyncResponse) resp -> {
result.value = (Throwable) resp.getResult();
}, loadBalancer);
Assert.assertEquals(123, server.getLastVisitTime());
Assert.assertEquals(1, loadBalancer.getLoadBalancerStats().getSingleServerStat(server).getSuccessiveConnectionFailureCount());
Assert.assertEquals("InvocationException: code=400;msg=send failed", result.value.getMessage());
Assert.assertEquals(continuousFailureCount + 1, server.getCountinuousFailureCount());
}
Aggregations