Search in sources :

Example 16 with MicroserviceFactory

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

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 17 with MicroserviceFactory

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

the class TestMicroserviceFactory method testSetDescriptionOnNullDescription.

@Test
public void testSetDescriptionOnNullDescription() {
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.clearProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION);
    MicroserviceFactory factory = new MicroserviceFactory();
    Microservice microservice = factory.create(configuration);
    Assert.assertNull(microservice.getDescription());
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] {});
    microservice = factory.create(configuration);
    Assert.assertNull(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 18 with MicroserviceFactory

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

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 19 with MicroserviceFactory

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

the class TestMicroserviceFactory method testCreateMicroserviceFromDefinitionWithInvalidVersion.

@Test
public void testCreateMicroserviceFromDefinitionWithInvalidVersion() {
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_VERSION, "x.y.x.1");
    expectedException.equals(IllegalStateException.class);
    expectedException.expectMessage("Invalid major \"x\", version \"x.y.x.1\".");
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    microserviceFactory.create(configuration);
}
Also used : Configuration(org.apache.commons.configuration.Configuration) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Example 20 with MicroserviceFactory

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

the class TestMicroserviceFactory method testSetDescription.

@Test
public void testSetDescription() {
    MicroserviceFactory factory = new MicroserviceFactory();
    Configuration configuration = ConfigUtil.createLocalConfig();
    configuration.setProperty(BootStrapProperties.CONFIG_SERVICE_DESCRIPTION, new String[] { "test1", "test2" });
    Microservice microservice = factory.create(configuration);
    Assert.assertEquals("test1,test2", 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)

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