Search in sources :

Example 16 with Microservice

use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestSimpleLoadBalanceHandler method mock.

public void mock() {
    Microservice microService = new Microservice();
    microService.setAppId("100");
    new MockUp<RegistryUtils>() {

        @Mock
        public Microservice getMicroservice() {
            return microService;
        }
    };
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) MockUp(mockit.MockUp)

Example 17 with Microservice

use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.

the class RegistryUtils method createMicroserviceFromDefinition.

private static Microservice createMicroserviceFromDefinition() {
    Microservice microservice = new Microservice();
    String name = DynamicPropertyFactory.getInstance().getStringProperty("service_description.name", null).get();
    if (name == null || name.isEmpty()) {
        throw new IllegalArgumentException("You must configure service_description.name");
    }
    microservice.setServiceName(name);
    microservice.setAppId(DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get());
    microservice.setVersion(DynamicPropertyFactory.getInstance().getStringProperty("service_description.version", "1.0.0").get());
    microservice.setDescription(DynamicPropertyFactory.getInstance().getStringProperty("service_description.description", "").get());
    microservice.setLevel(DynamicPropertyFactory.getInstance().getStringProperty("service_description.role", "FRONT").get());
    Map<String, String> propertiesMap = MicroservicePropertiesLoader.INSTANCE.loadProperties();
    if (!isEmpty(propertiesMap)) {
        microservice.setProperties(propertiesMap);
        // 当允许跨app调用时为服务设置一个别名
        if (allowCrossApp(propertiesMap)) {
            microservice.setAlias(Microservice.generateAbsoluteMicroserviceName(microservice.getAppId(), microservice.getServiceName()));
        }
    }
    return microservice;
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice)

Example 18 with Microservice

use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestInstanceCacheManager method testInstanceUpdate.

@Test
public void testInstanceUpdate() {
    Microservice oInstance = RegistryUtils.getMicroservice();
    InstanceCacheManager oInstanceCacheManager = new InstanceCacheManager();
    MicroserviceInstanceChangedEvent oChangedEnvent = new MicroserviceInstanceChangedEvent();
    oChangedEnvent.setAction(WatchAction.UPDATE);
    MicroserviceKey oKey = new MicroserviceKey();
    oKey.setAppId(oInstance.getAppId());
    oKey.setVersion(oInstance.getVersion());
    oKey.setServiceName(oInstance.getServiceName());
    oChangedEnvent.setKey(oKey);
    oChangedEnvent.setInstance(RegistryUtils.getMicroserviceInstance());
    oInstanceCacheManager.onInstanceUpdate(oChangedEnvent);
    oChangedEnvent.setAction(WatchAction.DELETE);
    oInstanceCacheManager.onInstanceUpdate(oChangedEnvent);
    oChangedEnvent.setAction(WatchAction.CREATE);
    oInstanceCacheManager.onInstanceUpdate(oChangedEnvent);
    Assert.assertEquals("UP", RegistryUtils.getMicroserviceInstance().getStatus().toString());
}
Also used : MicroserviceInstanceChangedEvent(io.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent) Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) MicroserviceKey(io.servicecomb.serviceregistry.api.MicroserviceKey) Test(org.junit.Test)

Example 19 with Microservice

use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestClienthttp method testServiceRegistryClientImpl.

@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
    IpPort ipPort = new IpPort("127.0.0.1", 8853);
    new Expectations() {

        {
            manager.get();
            result = ipPort;
            manager.next();
            result = null;
        }
    };
    Microservice oInstance = RegistryUtils.getMicroservice();
    RegistryThread oThread = new RegistryThread();
    oThread.start();
    ServiceRegistryClientImpl oClient = (ServiceRegistryClientImpl) RegistryClientFactory.getRegistryClient();
    oClient.registerMicroservice(oInstance);
    oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
    try {
        oClient.init();
    } catch (Exception e) {
        Assert.assertEquals(null, e.getMessage());
    }
    Assert.assertEquals(null, oClient.getMicroservice(RegistryUtils.getMicroservice().getServiceId()));
    Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
    Assert.assertEquals(null, oClient.findServiceInstance(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
    Assert.assertEquals(null, oClient.getMicroserviceId(RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
    Assert.assertEquals(null, oClient.heartbeat(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroserviceInstance().getInstanceId()));
    oClient.watch("", Mockito.mock(AsyncResultCallback.class));
    Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(RegistryUtils.getMicroservice().getServiceId(), RegistryUtils.getMicroserviceInstance().getInstanceId()));
}
Also used : Expectations(mockit.Expectations) Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) RegistryThread(io.servicecomb.serviceregistry.RegistryThread) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResultCallback(io.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 20 with Microservice

use of io.servicecomb.serviceregistry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestServiceRegistryClientImpl method testException.

@Test
public void testException() {
    Microservice oInstance = RegistryUtils.getMicroservice();
    RegistryThread oThread = new RegistryThread();
    oThread.start();
    oClient.registerMicroservice(oInstance);
    oClient.registerMicroserviceInstance(RegistryUtils.getMicroserviceInstance());
    try {
        oClient.init();
    } catch (Exception e) {
        Assert.assertEquals(null, e.getMessage());
    }
    new MockUp<CountDownLatch>() {

        @Mock
        public void await() throws InterruptedException {
            throw new InterruptedException();
        }
    };
    Assert.assertEquals(null, oClient.getMicroserviceId(RegistryUtils.getMicroservice().getAppId(), RegistryUtils.getMicroservice().getServiceName(), RegistryUtils.getMicroservice().getVersion()));
    Assert.assertEquals(null, oClient.getAllMicroservices());
    Assert.assertEquals(null, oClient.registerMicroservice(RegistryUtils.getMicroservice()));
    Assert.assertEquals(null, oClient.getMicroservice("microserviceId"));
    Assert.assertEquals(null, oClient.getMicroserviceInstance("consumerId", "providerId"));
    Assert.assertEquals(false, oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
    Assert.assertEquals(null, oClient.heartbeat("microserviceId", "microserviceInstanceId"));
    Assert.assertEquals(null, oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
    MicroserviceInstance microInstance = Mockito.mock(MicroserviceInstance.class);
    Assert.assertEquals(null, oClient.registerMicroserviceInstance(microInstance));
    Assert.assertEquals("a", new ClientException("a").getMessage());
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) RegistryThread(io.servicecomb.serviceregistry.RegistryThread) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) MockUp(mockit.MockUp) ClientException(io.servicecomb.serviceregistry.client.ClientException) ClientException(io.servicecomb.serviceregistry.client.ClientException) Test(org.junit.Test)

Aggregations

Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)22 MockUp (mockit.MockUp)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)5 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)4 BeforeClass (org.junit.BeforeClass)4 RegistryThread (io.servicecomb.serviceregistry.RegistryThread)2 HealthCheck (io.servicecomb.serviceregistry.api.registry.HealthCheck)2 ClientException (io.servicecomb.serviceregistry.client.ClientException)2 ServiceRegistryClient (io.servicecomb.serviceregistry.client.ServiceRegistryClient)2 HashMap (java.util.HashMap)2 CseContext (io.servicecomb.core.CseContext)1 Transport (io.servicecomb.core.Transport)1 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)1 MicroserviceMetaManager (io.servicecomb.core.definition.MicroserviceMetaManager)1 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)1 SchemaListenerManager (io.servicecomb.core.definition.loader.SchemaListenerManager)1 SchemaLoader (io.servicecomb.core.definition.loader.SchemaLoader)1 UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)1 IpPort (io.servicecomb.foundation.common.net.IpPort)1