Search in sources :

Example 1 with RegistryThread

use of io.servicecomb.serviceregistry.RegistryThread 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 2 with RegistryThread

use of io.servicecomb.serviceregistry.RegistryThread 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

RegistryThread (io.servicecomb.serviceregistry.RegistryThread)2 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)2 Test (org.junit.Test)2 IpPort (io.servicecomb.foundation.common.net.IpPort)1 AsyncResultCallback (io.servicecomb.foundation.vertx.AsyncResultCallback)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 ClientException (io.servicecomb.serviceregistry.client.ClientException)1 Expectations (mockit.Expectations)1 MockUp (mockit.MockUp)1