Search in sources :

Example 1 with Subscribe

use of com.netflix.eventbus.spi.Subscribe in project eureka by Netflix.

the class DiscoveryClientEventBusTest method testStatusChangeEvent.

@Test
public void testStatusChangeEvent() throws Exception {
    final CountDownLatch eventLatch = new CountDownLatch(1);
    final List<StatusChangeEvent> receivedEvents = new ArrayList<StatusChangeEvent>();
    EventBus eventBus = discoveryClientResource.getEventBus();
    eventBus.registerSubscriber(new Object() {

        @Subscribe
        public void consume(StatusChangeEvent event) {
            receivedEvents.add(event);
            eventLatch.countDown();
        }
    });
    Applications initialApps = toApplications(discoveryClientResource.getMyInstanceInfo());
    when(requestHandler.getApplications()).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    // Activates the client
    discoveryClientResource.getClient();
    assertThat(eventLatch.await(10, TimeUnit.SECONDS), is(true));
    assertThat(receivedEvents.size(), is(equalTo(1)));
    assertThat(receivedEvents.get(0), is(notNullValue()));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) ArrayList(java.util.ArrayList) EventBus(com.netflix.eventbus.spi.EventBus) Subscribe(com.netflix.eventbus.spi.Subscribe) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Applications (com.netflix.discovery.shared.Applications)1 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)1 EventBus (com.netflix.eventbus.spi.EventBus)1 Subscribe (com.netflix.eventbus.spi.Subscribe)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1