Search in sources :

Example 6 with EurekaEventListener

use of com.netflix.discovery.EurekaEventListener in project ribbon by Netflix.

the class EurekaDynamicServerListLoadBalancerTest method testLoadBalancerHappyCase.

@Test
public void testLoadBalancerHappyCase() throws Exception {
    Assert.assertNotEquals("the two test server list counts should be different", secondServerListSize, initialServerListSize);
    DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null;
    try {
        Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
        PowerMock.replay(DiscoveryClient.class);
        PowerMock.replay(eurekaClientMock);
        // actual testing
        // initial creation and loading of the first serverlist
        lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        Assert.assertEquals(initialServerListSize, lb.getServerCount(false));
        // trigger an eureka CacheRefreshEvent
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb));
    } finally {
        if (lb != null) {
            lb.shutdown();
            PowerMock.verify(eurekaClientMock);
            PowerMock.verify(DiscoveryClient.class);
        }
    }
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) EurekaEventListener(com.netflix.discovery.EurekaEventListener) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) Capture(org.easymock.Capture) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with EurekaEventListener

use of com.netflix.discovery.EurekaEventListener in project ribbon by Netflix.

the class EurekaNotificationServerListUpdaterTest method testTaskAlreadyQueued.

@Test
public void testTaskAlreadyQueued() throws Exception {
    EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(new Provider<EurekaClient>() {

        @Override
        public EurekaClient get() {
            return eurekaClientMock;
        }
    }, testExecutor);
    try {
        Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
        EasyMock.replay(eurekaClientMock);
        final CountDownLatch countDownLatch = new CountDownLatch(1);
        serverListUpdater.start(new ServerListUpdater.UpdateAction() {

            @Override
            public void doUpdate() {
                if (countDownLatch.getCount() == 0) {
                    Assert.fail("should only countdown once");
                }
                countDownLatch.countDown();
            }
        });
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        Assert.assertTrue(countDownLatch.await(2, TimeUnit.SECONDS));
        // sleep a bit more
        Thread.sleep(100);
        Assert.assertFalse(serverListUpdater.updateQueued.get());
    } finally {
        serverListUpdater.stop();
        EasyMock.verify(eurekaClientMock);
    }
}
Also used : EurekaClient(com.netflix.discovery.EurekaClient) EurekaEventListener(com.netflix.discovery.EurekaEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Capture(org.easymock.Capture) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) Test(org.junit.Test)

Aggregations

CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)7 EurekaEventListener (com.netflix.discovery.EurekaEventListener)7 Capture (org.easymock.Capture)6 Test (org.junit.Test)6 EurekaClient (com.netflix.discovery.EurekaClient)5 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)5 CountDownLatch (java.util.concurrent.CountDownLatch)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 EurekaEvent (com.netflix.discovery.EurekaEvent)1 DiscoveryEnabledNIWSServerList (com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList)1 DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)1 EurekaNotificationServerListUpdater (com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1