Search in sources :

Example 1 with ResolverListener

use of com.netflix.zuul.resolver.ResolverListener in project zuul by Netflix.

the class DynamicServerResolverTest method verifyListenerUpdates.

@Test
public void verifyListenerUpdates() {
    class CustomListener implements ResolverListener<DiscoveryResult> {

        private List<DiscoveryResult> resultSet = Lists.newArrayList();

        @Override
        public void onChange(List<DiscoveryResult> changedSet) {
            resultSet = changedSet;
        }

        public List<DiscoveryResult> updatedList() {
            return resultSet;
        }
    }
    final CustomListener listener = new CustomListener();
    final DynamicServerResolver resolver = new DynamicServerResolver(new DefaultClientConfigImpl(), listener);
    final InstanceInfo first = Builder.newBuilder().setAppName("zuul-discovery-1").setHostName("zuul-discovery-1").setIPAddr("100.10.10.1").setPort(443).build();
    final InstanceInfo second = Builder.newBuilder().setAppName("zuul-discovery-2").setHostName("zuul-discovery-2").setIPAddr("100.10.10.2").setPort(443).build();
    final DiscoveryEnabledServer server1 = new DiscoveryEnabledServer(first, true);
    final DiscoveryEnabledServer server2 = new DiscoveryEnabledServer(second, true);
    resolver.onUpdate(ImmutableList.of(server1, server2), ImmutableList.of());
    Truth.assertThat(listener.updatedList()).containsExactly(new DiscoveryResult(server1), new DiscoveryResult(server2));
}
Also used : DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ResolverListener(com.netflix.zuul.resolver.ResolverListener) InstanceInfo(com.netflix.appinfo.InstanceInfo) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)1 ResolverListener (com.netflix.zuul.resolver.ResolverListener)1 List (java.util.List)1 Test (org.junit.Test)1