Search in sources :

Example 1 with MicroserviceKey

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

the class TestConsumers method watchDeleteEvent.

@Test
public void watchDeleteEvent() {
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
    Assert.assertEquals("0.0.0.0+", microserviceVersionRule.getVersionRule().getVersionRule());
    Assert.assertEquals(1, microserviceManager.getVersionsByName().size());
    mockNotExist();
    MicroserviceKey key = new MicroserviceKey();
    MicroserviceInstanceChangedEvent event = new MicroserviceInstanceChangedEvent();
    event.setKey(key);
    key.setAppId(appId);
    key.setServiceName(serviceName);
    eventBus.post(event);
    Assert.assertEquals(0, microserviceManager.getVersionsByName().size());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent) MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceKey(org.apache.servicecomb.registry.api.MicroserviceKey) Test(org.junit.Test)

Example 2 with MicroserviceKey

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

the class TestMicroserviceWatchTask method testWatchInstanceChanged.

@Test
public void testWatchInstanceChanged(@Mocked ServiceRegistryConfig serviceRegistryConfig, @Mocked ServiceRegistryClient srClient, @Mocked Microservice microservice) {
    initWatch(serviceRegistryConfig, srClient, microservice);
    MicroserviceInstanceChangedEvent changedEvent = new MicroserviceInstanceChangedEvent();
    MicroserviceKey key = new MicroserviceKey();
    key.setAppId(microservice.getAppId());
    key.setVersion(microservice.getVersion());
    key.setServiceName(microservice.getServiceName());
    changedEvent.setKey(key);
    changedEvent.setInstance(microservice.getInstance());
    new MockUp<ServiceRegistryClient>(srClient) {

        @Mock
        void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceInstanceChangedEvent> callback, AsyncResultCallback<Void> onOpen, AsyncResultCallback<Void> onClose) {
            callback.success(changedEvent);
        }
    };
    Holder<MicroserviceInstanceChangedEvent> holder = new Holder<>();
    eventBus.register(new Object() {

        @Subscribe
        public void onException(MicroserviceInstanceChangedEvent event) {
            holder.value = event;
        }
    });
    changedEvent.setAction(WatchAction.CREATE);
    microserviceWatchTask.run();
    Assert.assertEquals(WatchAction.CREATE, holder.value.getAction());
    changedEvent.setAction(WatchAction.DELETE);
    microserviceWatchTask.run();
    Assert.assertEquals(WatchAction.DELETE, holder.value.getAction());
    changedEvent.setAction(WatchAction.UPDATE);
    microserviceWatchTask.run();
    Assert.assertEquals(WatchAction.UPDATE, holder.value.getAction());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent) MicroserviceKey(org.apache.servicecomb.registry.api.MicroserviceKey) Holder(org.apache.servicecomb.foundation.common.Holder) MockUp(mockit.MockUp) Subscribe(com.google.common.eventbus.Subscribe) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Aggregations

MicroserviceKey (org.apache.servicecomb.registry.api.MicroserviceKey)2 MicroserviceInstanceChangedEvent (org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent)2 Test (org.junit.Test)2 Subscribe (com.google.common.eventbus.Subscribe)1 MockUp (mockit.MockUp)1 Holder (org.apache.servicecomb.foundation.common.Holder)1 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)1 MicroserviceVersionRule (org.apache.servicecomb.registry.consumer.MicroserviceVersionRule)1