use of io.servicecomb.serviceregistry.cache.InstanceCache in project java-chassis by ServiceComb.
the class AbstractEndpointsCache method getLatestEndpoints.
public List<ENDPOINT> getLatestEndpoints() {
InstanceCache newCache = InstanceCacheManager.INSTANCE.getOrCreate(instanceCache.getAppId(), instanceCache.getMicroserviceName(), instanceCache.getMicroserviceVersionRule());
if (!instanceCache.cacheChanged(newCache)) {
return endpoints;
}
// 走到这里,肯定已经是存在"有效"地址了(可能是个空列表,表示没有存活的实例)
// 先创建,成功了,再走下面的更新逻辑
List<ENDPOINT> tmpEndpoints = createEndpints(newCache);
this.instanceCache = newCache;
this.endpoints = tmpEndpoints;
return endpoints;
}
use of io.servicecomb.serviceregistry.cache.InstanceCache in project java-chassis by ServiceComb.
the class TestIpPortManager method testCreateServiceRegistryCacheWithInstanceCache.
@Test
public void testCreateServiceRegistryCacheWithInstanceCache() {
boolean validAssert = true;
List<MicroserviceInstance> list = new ArrayList<MicroserviceInstance>();
MicroserviceInstance e1 = new MicroserviceInstance();
list.add(e1);
new MockUp<RegistryUtils>() {
@Mock
public List<MicroserviceInstance> findServiceInstance(String appId, String serviceName, String versionRule) {
return list;
}
};
Microservice microservice = new Microservice();
new MockUp<RegistryUtils>() {
@Mock
private Microservice createMicroserviceFromDefinition() {
return microservice;
}
};
try {
Deencapsulation.setField(manager, "instanceCache", Mockito.mock(InstanceCache.class));
manager.createServiceRegistryCache();
Assert.assertNotNull(manager.get());
Assert.assertNull(manager.next());
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of io.servicecomb.serviceregistry.cache.InstanceCache in project java-chassis by ServiceComb.
the class IpPortManager method getAddressCaches.
private List<CacheEndpoint> getAddressCaches() {
if (instanceCache == null) {
return null;
}
InstanceCache newCache = InstanceCacheManager.INSTANCE.getOrCreate(Const.REGISTRY_APP_ID, Const.REGISTRY_SERVICE_NAME, Const.REGISTRY_VERSION);
if (instanceCache == null || instanceCache.cacheChanged(newCache)) {
synchronized (lockObj) {
if (instanceCache == null || instanceCache.cacheChanged(newCache)) {
indexForAuto.set(0);
addressCanUsed.clear();
instanceCache = newCache;
}
}
}
return instanceCache == null ? null : instanceCache.getOrCreateTransportMap().get(defaultTransport);
}
Aggregations