Search in sources :

Example 1 with PullMicroserviceVersionsInstancesEvent

use of org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent in project incubator-servicecomb-java-chassis by apache.

the class TestRemoteServiceRegistry method onPullMicroserviceVersionsInstancesEvent.

@Test
public void onPullMicroserviceVersionsInstancesEvent(@Injectable ServiceRegistryConfig config, @Injectable MicroserviceDefinition definition, @Mocked MicroserviceVersions microserviceVersions) {
    PullMicroserviceVersionsInstancesEvent event = new PullMicroserviceVersionsInstancesEvent(microserviceVersions, 1);
    ScheduledThreadPoolExecutor taskPool = new MockUp<ScheduledThreadPoolExecutor>() {

        @Mock
        ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
            Assert.assertEquals(1, delay);
            throw new Error("ok");
        }
    }.getMockInstance();
    expectedException.expect(Error.class);
    expectedException.expectMessage(Matchers.is("ok"));
    EventBus bus = new EventBus();
    RemoteServiceRegistry remote = new TestingRemoteServiceRegistry(bus, config, definition);
    bus.register(remote);
    Deencapsulation.setField(remote, "taskPool", taskPool);
    bus.post(event);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TimeUnit(java.util.concurrent.TimeUnit) EventBus(com.google.common.eventbus.EventBus) PullMicroserviceVersionsInstancesEvent(org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent) Mock(mockit.Mock) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

Example 2 with PullMicroserviceVersionsInstancesEvent

use of org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent 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 3 with PullMicroserviceVersionsInstancesEvent

use of org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent in project incubator-servicecomb-java-chassis by apache.

the class MicroserviceVersions method postPullInstanceEvent.

private void postPullInstanceEvent(long msTime) {
    pendingPullCount.incrementAndGet();
    appManager.getEventBus().post(new PullMicroserviceVersionsInstancesEvent(this, msTime));
}
Also used : PullMicroserviceVersionsInstancesEvent(org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent)

Aggregations

PullMicroserviceVersionsInstancesEvent (org.apache.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent)3 Test (org.junit.Test)2 EventBus (com.google.common.eventbus.EventBus)1 Subscribe (com.google.common.eventbus.Subscribe)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 TimeUnit (java.util.concurrent.TimeUnit)1 Mock (mockit.Mock)1 MicroserviceKey (org.apache.servicecomb.serviceregistry.api.MicroserviceKey)1 MicroserviceInstanceChangedEvent (org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent)1