use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.
the class TestRegistry method testDelegate.
@SuppressWarnings("deprecation")
@Test
public void testDelegate() {
ServiceRegistry serviceRegistry = LocalServiceRegistryFactory.createLocal();
serviceRegistry.init();
RegistryUtils.init();
serviceRegistry.run();
RegistryUtils.setServiceRegistry(serviceRegistry);
Assert.assertEquals(serviceRegistry, RegistryUtils.getServiceRegistry());
Assert.assertEquals(serviceRegistry.getServiceRegistryClient(), RegistryUtils.getServiceRegistryClient());
Microservice microservice = RegistryUtils.getMicroservice();
Assert.assertEquals(serviceRegistry.getMicroservice(), microservice);
Assert.assertEquals(serviceRegistry.getMicroserviceInstance(), RegistryUtils.getMicroserviceInstance());
List<MicroserviceInstance> instanceList = RegistryUtils.findServiceInstance("default", "default", "0.0.1");
Assert.assertEquals(1, instanceList.size());
Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceList.get(0).getServiceId());
instanceList = RegistryUtils.findServiceInstance("default", "notExists", "0.0.1");
Assert.assertNull(instanceList);
MicroserviceInstances microserviceInstances = RegistryUtils.findServiceInstances("default", "default", "0.0.1");
List<MicroserviceInstance> instanceLists = microserviceInstances.getInstancesResponse().getInstances();
Assert.assertEquals(1, instanceLists.size());
Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceLists.get(0).getServiceId());
Map<String, String> properties = new HashMap<>();
properties.put("k", "v");
RegistryUtils.updateInstanceProperties(properties);
Assert.assertEquals(properties, RegistryUtils.getMicroserviceInstance().getProperties());
Assert.assertEquals(microservice, RegistryUtils.getMicroservice(microservice.getServiceId()));
RegistryUtils.updateMicroserviceProperties(properties);
Assert.assertEquals(properties, RegistryUtils.getMicroservice().getProperties());
Assert.assertEquals("default", RegistryUtils.getAppId());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.
the class LocalServiceRegistryClientImplTest method findServiceInstance_noInstances.
@Test
public void findServiceInstance_noInstances() {
List<MicroserviceInstance> result = registryClient.findServiceInstance("self", appId, microserviceName, DefinitionConst.VERSION_RULE_ALL);
Assert.assertThat(result, Matchers.nullValue());
MicroserviceInstances microserviceInstances = registryClient.findServiceInstances("self", appId, microserviceName, DefinitionConst.VERSION_RULE_ALL, null);
Assert.assertThat(microserviceInstances.isMicroserviceNotExist(), Matchers.is(true));
Assert.assertThat(microserviceInstances.getInstancesResponse(), Matchers.nullValue());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.
the class MicroserviceVersions method pullInstances.
public void pullInstances() {
lastPullTime = System.currentTimeMillis();
MicroserviceInstances microserviceInstances = findServiceInstances();
lastPulledResult = microserviceInstances;
if (microserviceInstances == null) {
// will not do anything, consumers will use existing instances
return;
}
if (microserviceInstances.isMicroserviceNotExist()) {
// pulled failed, SC said target not exist
waitingDelete = true;
return;
}
if (null != revision && revision.equals(microserviceInstances.getRevision())) {
return;
}
pulledInstances = microserviceInstances.getInstancesResponse().getInstances();
pulledInstances.sort(Comparator.comparing(MicroserviceInstance::getInstanceId));
String rev = microserviceInstances.getRevision();
safeSetInstances(pulledInstances, rev);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.
the class RefreshableMicroserviceCacheTest method forceRefresh.
@Test
public void forceRefresh() {
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
microserviceInstance.setInstanceId("instanceId00");
ArrayList<MicroserviceInstance> instances = new ArrayList<>();
instances.add(microserviceInstance);
findServiceInstancesOprHolder.value = params -> {
Assert.assertEquals("consumerId", params[0]);
Assert.assertEquals("app", params[1]);
Assert.assertEquals("svc", params[2]);
Assert.assertEquals("0.0.0.0+", params[3]);
Assert.assertNull(params[4]);
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision("rev2");
microserviceInstances.setMicroserviceNotExist(false);
FindInstancesResponse instancesResponse = new FindInstancesResponse();
instancesResponse.setInstances(instances);
microserviceInstances.setInstancesResponse(instancesResponse);
return microserviceInstances;
};
microserviceCache.revisionId = "rev";
microserviceCache.forceRefresh();
Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, microserviceCache.getStatus());
List<MicroserviceInstance> cachedInstances = microserviceCache.getInstances();
Assert.assertEquals(1, cachedInstances.size());
MicroserviceInstance instance = cachedInstances.iterator().next();
Assert.assertEquals("instanceId00", instance.getInstanceId());
Assert.assertEquals("rev2", microserviceCache.getRevisionId());
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project java-chassis by ServiceComb.
the class RegistryUtils method convertCacheToMicroserviceInstances.
/**
* for compatibility
*/
public static MicroserviceInstances convertCacheToMicroserviceInstances(MicroserviceCache microserviceCache) {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
switch(microserviceCache.getStatus()) {
case SERVICE_NOT_FOUND:
microserviceInstances.setMicroserviceNotExist(true);
microserviceInstances.setNeedRefresh(false);
microserviceInstances.setRevision("");
microserviceInstances.setInstancesResponse(null);
return microserviceInstances;
case NO_CHANGE:
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setNeedRefresh(false);
microserviceInstances.setRevision(microserviceCache.getRevisionId());
return microserviceInstances;
case REFRESHED:
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision(microserviceCache.getRevisionId());
FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
findInstancesResponse.setInstances(new ArrayList<>(microserviceCache.getInstances()));
microserviceInstances.setInstancesResponse(findInstancesResponse);
return microserviceInstances;
default:
return null;
}
}
Aggregations