use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.
the class TestInstanceCacheCheckerMock method createFindServiceInstancesResult.
private Holder<MicroserviceInstances> createFindServiceInstancesResult() {
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision("first");
FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
findInstancesResponse.setInstances(new ArrayList<>());
microserviceInstances.setInstancesResponse(findInstancesResponse);
Holder<MicroserviceInstances> findHolder = new Holder<>();
findHolder.value = microserviceInstances;
return findHolder;
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project incubator-servicecomb-java-chassis by apache.
the class RefreshableMicroserviceCacheTest method refresh.
@Test
public void refresh() {
ArrayList<MicroserviceInstance> instances = new ArrayList<>();
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("rev0");
microserviceInstances.setMicroserviceNotExist(false);
FindInstancesResponse instancesResponse = new FindInstancesResponse();
instancesResponse.setInstances(instances);
microserviceInstances.setInstancesResponse(instancesResponse);
return microserviceInstances;
};
// at the beginning, no instances in cache
List<MicroserviceInstance> cachedInstances = microserviceCache.getInstances();
Assert.assertEquals(0, cachedInstances.size());
Assert.assertNull(microserviceCache.getRevisionId());
// find 1 instance from sc
MicroserviceInstance microserviceInstance = new MicroserviceInstance();
instances.add(microserviceInstance);
microserviceInstance.setInstanceId("instanceId00");
microserviceCache.refresh();
Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, microserviceCache.getStatus());
cachedInstances = microserviceCache.getInstances();
Assert.assertEquals(1, cachedInstances.size());
MicroserviceInstance instance = cachedInstances.iterator().next();
Assert.assertEquals("instanceId00", instance.getInstanceId());
Assert.assertEquals("rev0", microserviceCache.getRevisionId());
// 2nd time, find 2 instances, one of them is the old instance
MicroserviceInstance microserviceInstance1 = new MicroserviceInstance();
instances.add(microserviceInstance1);
microserviceInstance1.setInstanceId("instanceId01");
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.assertEquals("rev0", params[4]);
MicroserviceInstances microserviceInstances = new MicroserviceInstances();
microserviceInstances.setNeedRefresh(true);
microserviceInstances.setRevision("rev1");
microserviceInstances.setMicroserviceNotExist(false);
FindInstancesResponse instancesResponse = new FindInstancesResponse();
instancesResponse.setInstances(instances);
microserviceInstances.setInstancesResponse(instancesResponse);
return microserviceInstances;
};
microserviceCache.refresh();
Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, microserviceCache.getStatus());
cachedInstances = microserviceCache.getInstances();
Assert.assertEquals(2, cachedInstances.size());
Assert.assertEquals("instanceId00", cachedInstances.get(0).getInstanceId());
Assert.assertEquals("instanceId01", cachedInstances.get(1).getInstanceId());
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project java-chassis by ServiceComb.
the class TestFindInstancesResponse method setUp.
@Before
public void setUp() throws Exception {
oFindInstancesResponse = new FindInstancesResponse();
oListMicroserviceInstance = new ArrayList<>();
oListMicroserviceInstance.add(Mockito.mock(MicroserviceInstance.class));
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse in project java-chassis by ServiceComb.
the class StaticMicroserviceVersions method addInstances.
protected void addInstances(List<MicroserviceInstance> instances) {
for (int idx = 0; idx < instances.size(); idx++) {
MicroserviceInstance instance = instances.get(idx);
instance.setServiceId(microservice.getServiceId());
instance.setInstanceId(microservice.getServiceId() + "-" + idx);
}
microserviceInstances.setMicroserviceNotExist(false);
microserviceInstances.setInstancesResponse(new FindInstancesResponse());
microserviceInstances.getInstancesResponse().setInstances(instances);
}
use of org.apache.servicecomb.registry.api.registry.FindInstancesResponse 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());
}
Aggregations