Search in sources :

Example 1 with InstanceCache

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;
}
Also used : InstanceCache(io.servicecomb.serviceregistry.cache.InstanceCache)

Example 2 with InstanceCache

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);
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) ArrayList(java.util.ArrayList) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) InstanceCache(io.servicecomb.serviceregistry.cache.InstanceCache) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 3 with InstanceCache

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);
}
Also used : InstanceCache(io.servicecomb.serviceregistry.cache.InstanceCache)

Aggregations

InstanceCache (io.servicecomb.serviceregistry.cache.InstanceCache)3 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 ArrayList (java.util.ArrayList)1 MockUp (mockit.MockUp)1 Test (org.junit.Test)1