use of org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent 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.response.MicroserviceInstanceChangedEvent in project incubator-servicecomb-java-chassis by apache.
the class TestMicroserviceVersions method checkIsEventAccept.
public void checkIsEventAccept(MicroserviceKey key, boolean expected) {
MicroserviceInstanceChangedEvent changeEvent = new MicroserviceInstanceChangedEvent();
changeEvent.setKey(key);
boolean isEventAccept = microserviceVersions.isEventAccept(changeEvent);
Assert.assertEquals(expected, isEventAccept);
}
use of org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent 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.response.MicroserviceInstanceChangedEvent 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.response.MicroserviceInstanceChangedEvent in project incubator-servicecomb-java-chassis by apache.
the class MicroserviceWatchTask method doRun.
@Override
public void doRun() {
// will always run watch when it is ready
if (!needToWatch()) {
return;
}
srClient.watch(microservice.getServiceId(), (event) -> {
if (event.failed()) {
eventBus.post(new ExceptionEvent(event.cause()));
return;
}
MicroserviceInstanceChangedEvent changedEvent = event.result();
if (isProviderInstancesChanged(changedEvent) && !serviceRegistryConfig.isWatch()) {
return;
}
if (!isProviderInstancesChanged(changedEvent) && !serviceRegistryConfig.isRegistryAutoDiscovery()) {
return;
}
onMicroserviceInstanceChanged(changedEvent);
}, open -> {
eventBus.post(new RecoveryEvent());
}, close -> {
});
}
Aggregations