use of org.apache.servicecomb.serviceregistry.registry.cache.MockedMicroserviceCache in project java-chassis by ServiceComb.
the class RegistryUtilsTest method convertCacheToMicroserviceInstances.
@Test
public void convertCacheToMicroserviceInstances() {
MockedMicroserviceCache microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.CLIENT_ERROR);
MicroserviceInstances microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertNull(microserviceInstances);
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.SETTING_CACHE_ERROR);
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertNull(microserviceInstances);
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.INIT);
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertNull(microserviceInstances);
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.SERVICE_NOT_FOUND);
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertTrue(microserviceInstances.isMicroserviceNotExist());
Assert.assertFalse(microserviceInstances.isNeedRefresh());
Assert.assertEquals("", microserviceInstances.getRevision());
Assert.assertNull(microserviceInstances.getInstancesResponse());
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.REFRESHED);
microserviceCache.setRevisionId("0166f3c18702617d5e55cf911e4e412cc8760dab");
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
microserviceCache.setInstances(Collections.singletonList(microserviceInstance));
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertFalse(microserviceInstances.isMicroserviceNotExist());
Assert.assertTrue(microserviceInstances.isNeedRefresh());
Assert.assertEquals("0166f3c18702617d5e55cf911e4e412cc8760dab", microserviceInstances.getRevision());
Assert.assertEquals(1, microserviceInstances.getInstancesResponse().getInstances().size());
Assert.assertSame(microserviceInstance, microserviceInstances.getInstancesResponse().getInstances().get(0));
microserviceCache = new MockedMicroserviceCache();
microserviceCache.setStatus(MicroserviceCacheStatus.NO_CHANGE);
microserviceCache.setRevisionId("0166f3c18702617d5e55cf911e4e412cc8760dab");
microserviceInstances = RegistryUtils.convertCacheToMicroserviceInstances(microserviceCache);
Assert.assertFalse(microserviceInstances.isMicroserviceNotExist());
Assert.assertFalse(microserviceInstances.isNeedRefresh());
Assert.assertEquals("0166f3c18702617d5e55cf911e4e412cc8760dab", microserviceInstances.getRevision());
Assert.assertNull(microserviceInstances.getInstancesResponse());
}
Aggregations