Search in sources :

Example 31 with MicroserviceInstance

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;
}
Also used : MicroserviceInstances(org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)

Example 32 with MicroserviceInstance

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());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 33 with 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");
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) Before(org.junit.Before)

Example 34 with MicroserviceInstance

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());
}
Also used : Expectations(mockit.Expectations) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 35 with MicroserviceInstance

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());
}
Also used : Expectations(mockit.Expectations) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Aggregations

MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)56 Test (org.junit.Test)30 Expectations (mockit.Expectations)16 ArrayList (java.util.ArrayList)15 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)15 HashMap (java.util.HashMap)11 MicroserviceInstances (org.apache.servicecomb.serviceregistry.client.http.MicroserviceInstances)7 Before (org.junit.Before)5 EventBus (com.google.common.eventbus.EventBus)4 Server (com.netflix.loadbalancer.Server)4 BootEvent (org.apache.servicecomb.core.BootListener.BootEvent)4 CseServer (org.apache.servicecomb.loadbalance.CseServer)4 Subscribe (com.google.common.eventbus.Subscribe)3 Map (java.util.Map)3 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)3 MicroserviceInstanceRegisterTask (org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceRegisterTask)3 URI (java.net.URI)2 List (java.util.List)2 RSAProviderTokenManager (org.apache.servicecomb.authentication.provider.RSAProviderTokenManager)2 SchemaListenerManager (org.apache.servicecomb.core.definition.loader.SchemaListenerManager)2