Search in sources :

Example 1 with ShutdownEvent

use of org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent in project incubator-servicecomb-java-chassis by apache.

the class TestRemoteServiceRegistry method testLifeCycle.

@Test
public void testLifeCycle(@Injectable ServiceRegistryConfig config, @Injectable MicroserviceDefinition definition, @Injectable ServiceRegistry registry) {
    ArrayList<IpPort> ipPortList = new ArrayList<>();
    ipPortList.add(new IpPort("127.0.0.1", 9980));
    ipPortList.add(new IpPort("127.0.0.1", 9981));
    new Expectations() {

        {
            definition.getConfiguration();
            result = ConfigUtil.createLocalConfig();
            config.getIpPort();
            result = ipPortList;
            config.getTransport();
            result = "rest";
            config.isRegistryAutoDiscovery();
            result = true;
            config.getHeartbeatInterval();
            result = 30;
            config.getInstancePullInterval();
            result = 30;
            config.isWatch();
            result = false;
        }
    };
    ServiceRegistry oldRegistry = RegistryUtils.getServiceRegistry();
    RegistryUtils.setServiceRegistry(registry);
    EventBus bus = new EventBus();
    RemoteServiceRegistry remote = new TestingRemoteServiceRegistry(bus, config, definition);
    remote.init();
    remote.run();
    // includes complete tasks
    Assert.assertTrue(2 <= remote.getTaskPool().getTaskCount());
    bus.post(new ShutdownEvent());
    remote.getTaskPool().schedule(new Runnable() {

        @Override
        public void run() {
        // TODO Auto-generated method stub
        }
    }, 0, TimeUnit.SECONDS);
    Assert.assertTrue(remote.getTaskPool().isShutdown());
    RegistryUtils.setServiceRegistry(oldRegistry);
}
Also used : Expectations(mockit.Expectations) ArrayList(java.util.ArrayList) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) EventBus(com.google.common.eventbus.EventBus) ShutdownEvent(org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent) Test(org.junit.Test)

Example 2 with ShutdownEvent

use of org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent in project incubator-servicecomb-java-chassis by apache.

the class AbstractServiceRegistry method destroy.

public void destroy() {
    eventBus.post(new ShutdownEvent());
    unregisterInstance();
}
Also used : ShutdownEvent(org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent)

Aggregations

ShutdownEvent (org.apache.servicecomb.serviceregistry.task.event.ShutdownEvent)2 EventBus (com.google.common.eventbus.EventBus)1 ArrayList (java.util.ArrayList)1 Expectations (mockit.Expectations)1 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)1 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 Test (org.junit.Test)1