use of io.servicecomb.serviceregistry.cache.CacheEndpoint 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;
}
use of io.servicecomb.serviceregistry.cache.CacheEndpoint 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);
}
use of io.servicecomb.serviceregistry.cache.CacheEndpoint in project java-chassis by ServiceComb.
the class IpPortManager method get.
public IpPort get() {
List<CacheEndpoint> addresses = getAddressCaches();
if (addresses == null || addresses.size() == 0) {
return getDefaultIpPort();
}
synchronized (lockObj) {
int id = indexForAuto.get();
addressCanUsed.putIfAbsent(id, true);
return new URIEndpointObject(addresses.get(id).getEndpoint());
}
}
use of io.servicecomb.serviceregistry.cache.CacheEndpoint in project java-chassis by ServiceComb.
the class IpPortManager method next.
public IpPort next() {
List<CacheEndpoint> addresses = getAddressCaches();
if ((addresses == null || addresses.size() == 0)) {
return nextDefaultIpPort();
}
synchronized (lockObj) {
int id = indexForAuto.get();
// 重置可用的地址为false
if (addressCanUsed.get(id) != null && addressCanUsed.get(id)) {
addressCanUsed.put(id, false);
if (id == addresses.size() - 1) {
indexForAuto.set(0);
// 重新轮询
addressCanUsed.clear();
LOGGER.warn("service center has no available instance");
return null;
} else {
indexForAuto.getAndIncrement();
}
LOGGER.warn("service center instance {} is unreachable, try another instance {}", addresses.get(id).getEndpoint(), addresses.get(indexForAuto.get()).getEndpoint());
}
return new URIEndpointObject(addresses.get(indexForAuto.get()).getEndpoint());
}
}
use of io.servicecomb.serviceregistry.cache.CacheEndpoint in project java-chassis by ServiceComb.
the class TestServerListCache method testCreateEndpointTransportString.
@Test
public void testCreateEndpointTransportString() {
Server server = instance.createEndpoint(transport, new CacheEndpoint("stringAddress", null));
Assert.assertNotNull(server);
}
Aggregations