use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class AbstractServiceRegistry method findServiceInstances.
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
MicroserviceInstances microserviceInstances = srClient.findServiceInstances(microservice.getServiceId(), appId, serviceName, versionRule, revision);
if (microserviceInstances == null) {
LOGGER.error("Can not find any instances from service center due to previous errors. service={}/{}/{}", appId, serviceName, versionRule);
return null;
}
if (!microserviceInstances.isNeedRefresh()) {
LOGGER.debug("instances revision is not changed, service={}/{}/{}", appId, serviceName, versionRule);
return microserviceInstances;
}
List<MicroserviceInstance> instances = microserviceInstances.getInstancesResponse().getInstances();
LOGGER.info("find instances[{}] from service center success. service={}/{}/{}", instances.size(), appId, serviceName, versionRule);
for (MicroserviceInstance instance : instances) {
LOGGER.info("service id={}, instance id={}, endpoints={}", instance.getServiceId(), instance.getInstanceId(), instance.getEndpoints());
}
return microserviceInstances;
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractRegisterTask method setup.
@Before
public void setup() {
eventBus = new EventBus();
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setInstance(new MicroserviceInstance());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstanceHeartbeatTask method setup.
@Before
public void setup() {
eventBus = new EventBus();
heartbeatTaskList = new ArrayList<>();
eventBus.register(new Object() {
@Subscribe
public void onEvent(MicroserviceInstanceHeartbeatTask task) {
heartbeatTaskList.add(task);
}
});
microservice = new Microservice();
microservice.setAppId("app");
microservice.setServiceName("ms");
microservice.setServiceId("serviceId");
microservice.setInstance(new MicroserviceInstance());
microservice.getInstance().setInstanceId("instanceId");
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstanceRegisterTask method registerIpSuccess.
@Test
public void registerIpSuccess() {
MicroserviceInstance instance = microservice.getInstance();
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getPublishAddress();
result = "127.0.0.1";
serviceRegistryConfig.isPreferIpAddress();
result = true;
serviceRegistryConfig.getHeartbeatInterval();
result = 10;
serviceRegistryConfig.getResendHeartBeatTimes();
result = 20;
srClient.registerMicroserviceInstance(instance);
result = "instanceId";
}
};
MicroserviceInstanceRegisterTask registerTask = new MicroserviceInstanceRegisterTask(eventBus, serviceRegistryConfig, srClient, microservice);
registerTask.taskStatus = TaskStatus.READY;
registerTask.run();
Assert.assertEquals(true, registerTask.isRegistered());
Assert.assertEquals("127.0.0.1", instance.getHostName());
Assert.assertEquals("instanceId", instance.getInstanceId());
Assert.assertEquals(10, instance.getHealthCheck().getInterval());
Assert.assertEquals(20, instance.getHealthCheck().getTimes());
Assert.assertEquals(1, taskList.size());
}
use of org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceInstanceRegisterTask method registerIpFailed.
@Test
public void registerIpFailed() {
MicroserviceInstance instance = microservice.getInstance();
new Expectations(RegistryUtils.class) {
{
RegistryUtils.getPublishAddress();
result = "127.0.0.1";
serviceRegistryConfig.isPreferIpAddress();
result = true;
serviceRegistryConfig.getHeartbeatInterval();
result = 10;
serviceRegistryConfig.getResendHeartBeatTimes();
result = 20;
srClient.registerMicroserviceInstance(instance);
result = null;
}
};
MicroserviceInstanceRegisterTask registerTask = new MicroserviceInstanceRegisterTask(eventBus, serviceRegistryConfig, srClient, microservice);
registerTask.taskStatus = TaskStatus.READY;
registerTask.run();
Assert.assertEquals(false, registerTask.isRegistered());
Assert.assertEquals("127.0.0.1", instance.getHostName());
Assert.assertEquals(10, instance.getHealthCheck().getInterval());
Assert.assertEquals(20, instance.getHealthCheck().getTimes());
Assert.assertEquals(1, taskList.size());
}
Aggregations