Search in sources :

Example 1 with MicroserviceFactory

use of org.apache.servicecomb.serviceregistry.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) {
    IpPort ipPort = new IpPort("127.0.0.1", 8853);
    new Expectations() {

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

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

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

        @Mock
        void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
        }
    };
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create("app", "ms");
    ServiceRegistryClientImpl oClient = new ServiceRegistryClientImpl(manager);
    oClient.init();
    oClient.registerMicroservice(microservice);
    oClient.registerMicroserviceInstance(microservice.getInstance());
    Assert.assertEquals(null, oClient.getMicroservice(microservice.getServiceId()));
    Assert.assertEquals(null, oClient.getMicroserviceInstance("testConsumerID", "testproviderID"));
    Assert.assertEquals(null, oClient.findServiceInstance(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertEquals(null, oClient.findServiceInstances(microservice.getServiceId(), microservice.getAppId(), microservice.getServiceName(), microservice.getVersion(), "0"));
    Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertEquals(null, oClient.heartbeat(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
    oClient.watch("", Mockito.mock(AsyncResultCallback.class));
    Assert.assertEquals(false, oClient.unregisterMicroserviceInstance(microservice.getServiceId(), microservice.getInstance().getInstanceId()));
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Handler(io.vertx.core.Handler) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) MockUp(mockit.MockUp) MicroserviceFactory(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 2 with MicroserviceFactory

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

the class TestServiceRegistryClientImpl method testException.

@Test
public void testException() {
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create("app", "ms");
    Assert.assertEquals(null, oClient.registerMicroservice(microservice));
    Assert.assertEquals(null, oClient.registerMicroserviceInstance(microservice.getInstance()));
    oClient.init();
    Assert.assertEquals(null, oClient.getMicroserviceId(microservice.getAppId(), microservice.getServiceName(), microservice.getVersion()));
    Assert.assertThat(oClient.getAllMicroservices().isEmpty(), is(true));
    Assert.assertEquals(null, oClient.registerMicroservice(microservice));
    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"));
    Assert.assertEquals(null, oClient.findServiceInstances("selfMicroserviceId", "appId", "serviceName", "versionRule", "0"));
    Assert.assertEquals("a", new ClientException("a").getMessage());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) MicroserviceFactory(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory) Test(org.junit.Test)

Example 3 with MicroserviceFactory

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

the class TestServiceRegistryClientImpl method testPrivateMethodCreateHttpClientOptions.

@Test
public void testPrivateMethodCreateHttpClientOptions() {
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create("app", "ms");
    oClient.registerMicroservice(microservice);
    oClient.registerMicroserviceInstance(microservice.getInstance());
    new MockUp<ServiceRegistryConfig>() {

        @Mock
        public HttpVersion getHttpVersion() {
            return HttpVersion.HTTP_2;
        }

        @Mock
        public boolean isSsl() {
            return true;
        }
    };
    try {
        oClient.init();
        HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
        Assert.assertNotNull(httpClientOptions);
        Assert.assertEquals(80, httpClientOptions.getDefaultPort());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) MockUp(mockit.MockUp) MicroserviceFactory(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory) HttpClientOptions(io.vertx.core.http.HttpClientOptions) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)3 MicroserviceFactory (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory)3 Test (org.junit.Test)3 MockUp (mockit.MockUp)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 Handler (io.vertx.core.Handler)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 Expectations (mockit.Expectations)1 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)1 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)1