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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations