Search in sources :

Example 11 with MicroserviceFactory

use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project java-chassis by ServiceComb.

the class TestMicroserviceFactory method testInit.

@Test
public void testInit() {
    MicroserviceFactory factory = new MicroserviceFactory();
    Microservice microservice = factory.create(ConfigUtil.createLocalConfig());
    String microserviceName = "default";
    Assert.assertEquals(microserviceName, microservice.getServiceName());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Example 12 with MicroserviceFactory

use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project java-chassis by ServiceComb.

the class TestMicroserviceFactory method testSetDescriptionOnEmptyDescription.

@Test
public void testSetDescriptionOnEmptyDescription() {
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { "", "" });
    MicroserviceFactory factory = new MicroserviceFactory();
    Microservice microservice = factory.create(configuration);
    Assert.assertEquals(",", microservice.getDescription());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Configuration(org.apache.commons.configuration.Configuration) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Example 13 with MicroserviceFactory

use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project java-chassis by ServiceComb.

the class TestClientHttp method testServiceRegistryClientImpl.

@SuppressWarnings("unchecked")
@Test
public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
    IpPort ipPort = new IpPort("127.0.0.1", 8853);
    new Expectations() {

        {
            manager.getAvailableAddress();
            result = ipPort;
        }
    };
    new MockUp<RegistryUtils>() {

        @Mock
        Microservice getMicroservice() {
            return microservice;
        }
    };
    new MockUp<CountDownLatch>() {

        @Mock
        public void await() throws InterruptedException {
        }
    };
    new MockUp<RestClientUtil>() {

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
        }
    };
    new MockUp<WebsocketClientUtil>() {

        @Mock
        void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
        }
    };
    // mock up this two client pool, since this UT case doesn't require the client pool actually boot up.
    new MockUp<HttpClientPool>() {

        @Mock
        void create() {
        }
    };
    new MockUp<WebsocketClientPool>() {

        @Mock
        void create() {
        }
    };
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create(configuration);
    ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(ServiceRegistryConfig.INSTANCE);
    oClient.init();
    oClient.registerMicroservice(microservice);
    oClient.registerMicroserviceInstance(microservice.getInstance());
    Assert.assertNull(oClient.getMicroservice(microservice.getServiceId()));
    Assert.assertNull(oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
    Assert.assertNull(oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertNull(oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
    Assert.assertNull(oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment()));
    Assert.assertNull(oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
    oClient.watch("", Mockito.mock(AsyncResultCallback.class));
    Assert.assertFalse(oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Configuration(org.apache.commons.configuration.Configuration) Handler(io.vertx.core.Handler) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) MockUp(mockit.MockUp) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 14 with MicroserviceFactory

use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.

the class TestServiceRegistryClientImpl method testPrivateMethodCreateHttpClientOptions.

@Test
public void testPrivateMethodCreateHttpClientOptions() {
    ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
    ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create();
    oClient.registerMicroservice(microservice);
    oClient.registerMicroserviceInstance(microservice.getInstance());
    try {
        oClient.init();
        HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
        Assert.assertNotNull(httpClientOptions);
        Assert.assertEquals(80, httpClientOptions.getDefaultPort());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    }
    ArchaiusUtils.resetConfig();
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) HttpClientOptions(io.vertx.core.http.HttpClientOptions) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) Test(org.junit.Test)

Example 15 with MicroserviceFactory

use of org.apache.servicecomb.registry.api.registry.MicroserviceFactory in project incubator-servicecomb-java-chassis by apache.

the class TestServiceRegistryClientImpl method testException.

@Test
public void testException() {
    ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
    ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create();
    Assert.assertNull(oClient.registerMicroservice(microservice));
    Assert.assertNull(oClient.registerMicroserviceInstance(microservice.getInstance()));
    oClient.init();
    Assert.assertNull(oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), microservice.getEnvironment()));
    Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
    Assert.assertNull(oClient.registerMicroservice(microservice));
    Assert.assertNull(oClient.getMicroservice("microserviceId"));
    Assert.assertNull(oClient.getMicroserviceInstance("consumerId", "providerId"));
    Assert.assertFalse(oClient.unregisterMicroserviceInstance("microserviceId", "microserviceInstanceId"));
    Assert.assertNull(oClient.heartbeat("microserviceId", "microserviceInstanceId"));
    Assert.assertNull(oClient.findServiceInstance("selfMicroserviceId", "appId", "serviceName", "versionRule"));
    Assert.assertNull(oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
    Assert.assertEquals("a", new ClientException("a").getMessage());
    ArchaiusUtils.resetConfig();
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Aggregations

MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)20 Test (org.junit.Test)18 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)16 Configuration (org.apache.commons.configuration.Configuration)12 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)4 Handler (io.vertx.core.Handler)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 Expectations (mockit.Expectations)2 MockUp (mockit.MockUp)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)2 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)2