提交 b4a7b86f 编写于 作者: A Allen Wang

Added Junit test for DynamicServerListLoadBalancer

上级 f9add2b3
/*
*
* 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<Server> {
public final static CountDownLatch latch = new CountDownLatch(5);
public static final List<Server> list = Lists.newArrayList(new Server("www.google.com:80"));
public MyServerList() {
}
public MyServerList(IClientConfig clientConfig) {
}
@Override
public List<Server> getInitialListOfServers() {
return list;
}
@Override
public List<Server> 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<Server> lb = new DynamicServerListLoadBalancer<Server>(config);
try {
assertTrue(MyServerList.latch.await(2, TimeUnit.SECONDS));
} catch (InterruptedException e) { // NOPMD
}
assertEquals(lb.getServerList(false), MyServerList.list);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册