diff --git a/ribbon-core/src/test/java/com/netflix/loadbalancer/DynamicServerListLoadBalancerTest.java b/ribbon-core/src/test/java/com/netflix/loadbalancer/DynamicServerListLoadBalancerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7485aca445f099a557598893e42d3bb6a37a7123 --- /dev/null +++ b/ribbon-core/src/test/java/com/netflix/loadbalancer/DynamicServerListLoadBalancerTest.java @@ -0,0 +1,77 @@ +/* + * + * Copyright 2014 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.netflix.loadbalancer; + +import static org.junit.Assert.*; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; + +import com.google.common.collect.Lists; +import com.netflix.client.config.CommonClientConfigKey; +import com.netflix.client.config.DefaultClientConfigImpl; +import com.netflix.client.config.IClientConfig; + +public class DynamicServerListLoadBalancerTest { + public static class MyServerList extends AbstractServerList { + + public final static CountDownLatch latch = new CountDownLatch(5); + + public static final List list = Lists.newArrayList(new Server("www.google.com:80")); + + public MyServerList() { + } + + public MyServerList(IClientConfig clientConfig) { + } + + @Override + public List getInitialListOfServers() { + return list; + } + + @Override + public List getUpdatedListOfServers() { + latch.countDown(); + return list; + } + + @Override + public void initWithNiwsConfig(IClientConfig clientConfig) { + } + + } + + @Test + public void testDynamicServerListLoadBalancer() { + DefaultClientConfigImpl config = DefaultClientConfigImpl.getClientConfigWithDefaultValues(); + config.setProperty(CommonClientConfigKey.NIWSServerListClassName, MyServerList.class.getName()); + config.setProperty(CommonClientConfigKey.NFLoadBalancerClassName, DynamicServerListLoadBalancer.class.getName()); + config.setProperty(CommonClientConfigKey.ServerListRefreshInterval, "50"); + DynamicServerListLoadBalancer lb = new DynamicServerListLoadBalancer(config); + try { + assertTrue(MyServerList.latch.await(2, TimeUnit.SECONDS)); + } catch (InterruptedException e) { // NOPMD + } + assertEquals(lb.getServerList(false), MyServerList.list); + } +} +