Search in sources :

Example 1 with MicroserviceKey

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

the class TestMicroserviceVersions method onMicroserviceInstanceChangedMatch.

@Test
public void onMicroserviceInstanceChangedMatch() {
    MicroserviceKey key = new MicroserviceKey();
    key.setAppId(appId);
    key.setServiceName(microserviceName);
    MicroserviceInstanceChangedEvent event = new MicroserviceInstanceChangedEvent();
    event.setKey(key);
    eventBus.register(new Object() {

        @Subscribe
        public void onEvent(PullMicroserviceVersionsInstancesEvent pullEvent) {
            pendingPullCount.incrementAndGet();
        }
    });
    eventBus.post(event);
    Assert.assertEquals(2, pendingPullCount.get());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent) MicroserviceKey(org.apache.servicecomb.serviceregistry.api.MicroserviceKey) Subscribe(com.google.common.eventbus.Subscribe) PullMicroserviceVersionsInstancesEvent(org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent) Test(org.junit.Test)

Example 2 with MicroserviceKey

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

the class TestMicroserviceVersions method onMicroserviceInstanceChangedAppNotMatch.

@Test
public void onMicroserviceInstanceChangedAppNotMatch() {
    MicroserviceKey key = new MicroserviceKey();
    key.setAppId("otherAppId");
    MicroserviceInstanceChangedEvent event = new MicroserviceInstanceChangedEvent();
    event.setKey(key);
    microserviceVersions.onMicroserviceInstanceChanged(event);
    Assert.assertEquals(0, pendingPullCount.get());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent) MicroserviceKey(org.apache.servicecomb.serviceregistry.api.MicroserviceKey) Test(org.junit.Test)

Example 3 with MicroserviceKey

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

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.serviceregistry.api.response.MicroserviceInstanceChangedEvent) MicroserviceKey(org.apache.servicecomb.serviceregistry.api.MicroserviceKey) Holder(javax.xml.ws.Holder) MockUp(mockit.MockUp) Subscribe(com.google.common.eventbus.Subscribe) AsyncResultCallback(org.apache.servicecomb.foundation.vertx.AsyncResultCallback) Test(org.junit.Test)

Example 4 with MicroserviceKey

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

the class TestMicroserviceVersions method onMicroserviceInstanceChangedNameNotMatch.

@Test
public void onMicroserviceInstanceChangedNameNotMatch() {
    MicroserviceKey key = new MicroserviceKey();
    key.setAppId(appId);
    key.setServiceName("otherName");
    MicroserviceInstanceChangedEvent event = new MicroserviceInstanceChangedEvent();
    event.setKey(key);
    eventBus.post(event);
    Assert.assertEquals(0, pendingPullCount.get());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent) MicroserviceKey(org.apache.servicecomb.serviceregistry.api.MicroserviceKey) Test(org.junit.Test)

Example 5 with MicroserviceKey

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

the class TestMicroserviceVersions method testIsEventAccept.

@Test
public void testIsEventAccept() {
    MicroserviceKey key = new MicroserviceKey();
    key.setAppId(appId);
    key.setServiceName(microserviceName);
    checkIsEventAccept(key, true);
    key.setServiceName("falseMicroserviceName");
    checkIsEventAccept(key, false);
    key.setAppId("falseAppId");
    checkIsEventAccept(key, false);
    key.setServiceName(microserviceName);
    checkIsEventAccept(key, false);
    key.setAppId(appId);
    key.setServiceName(appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
    microserviceVersions = new MicroserviceVersions(appManager, appId, appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
    checkIsEventAccept(key, true);
    microserviceVersions = new MicroserviceVersions(appManager, "falseAppId", appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
    checkIsEventAccept(key, false);
    microserviceVersions = new MicroserviceVersions(appManager, "falseAppId", "false" + appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
    checkIsEventAccept(key, false);
    microserviceVersions = new MicroserviceVersions(appManager, appId, "false" + appId + Const.APP_SERVICE_SEPARATOR + microserviceName);
    checkIsEventAccept(key, false);
}
Also used : MicroserviceKey(org.apache.servicecomb.serviceregistry.api.MicroserviceKey) Test(org.junit.Test)

Aggregations

MicroserviceKey (org.apache.servicecomb.serviceregistry.api.MicroserviceKey)5 Test (org.junit.Test)5 MicroserviceInstanceChangedEvent (org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent)4 Subscribe (com.google.common.eventbus.Subscribe)2 Holder (javax.xml.ws.Holder)1 MockUp (mockit.MockUp)1 AsyncResultCallback (org.apache.servicecomb.foundation.vertx.AsyncResultCallback)1 PullMicroserviceVersionsInstancesEvent (org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent)1