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