-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from allenxwang/cp
Fix #136
- Loading branch information
Showing
13 changed files
with
331 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
ribbon-test/src/main/java/com/netflix/ribbon/testutils/MockedDiscoveryServerListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* 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.ribbon.testutils; | ||
|
||
import com.netflix.appinfo.InstanceInfo; | ||
import com.netflix.discovery.DiscoveryClient; | ||
import com.netflix.discovery.DiscoveryManager; | ||
import com.netflix.loadbalancer.Server; | ||
import org.easymock.EasyMock; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.api.easymock.PowerMock; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.easymock.EasyMock.expect; | ||
import static org.powermock.api.easymock.PowerMock.createMock; | ||
import static org.powermock.api.easymock.PowerMock.replay; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest( {DiscoveryManager.class, DiscoveryClient.class} ) | ||
@PowerMockIgnore({"javax.management.*", "com.sun.jersey.*", "com.sun.*", "org.apache.*", "weblogic.*", "com.netflix.config.*", "com.sun.jndi.dns.*", | ||
"javax.naming.*", "com.netflix.logging.*", "javax.ws.*"}) | ||
|
||
@Ignore | ||
public abstract class MockedDiscoveryServerListTest { | ||
protected abstract List<Server> getMockServerList(); | ||
|
||
protected abstract String getVipAddress(); | ||
|
||
|
||
static List<InstanceInfo> getDummyInstanceInfo(String appName, List<Server> serverList){ | ||
List<InstanceInfo> list = new ArrayList<InstanceInfo>(); | ||
for (Server server: serverList) { | ||
InstanceInfo info = InstanceInfo.Builder.newBuilder().setAppName(appName) | ||
.setHostName(server.getHost()) | ||
.setPort(server.getPort()) | ||
.build(); | ||
list.add(info); | ||
} | ||
return list; | ||
} | ||
|
||
@Before | ||
public void setupMock(){ | ||
List<InstanceInfo> instances = getDummyInstanceInfo("dummy", getMockServerList()); | ||
PowerMock.mockStatic(DiscoveryManager.class); | ||
PowerMock.mockStatic(DiscoveryClient.class); | ||
|
||
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class); | ||
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class); | ||
|
||
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes(); | ||
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes(); | ||
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes(); | ||
|
||
expect(mockedDiscoveryClient.getInstancesByVipAddress(getVipAddress(), false, null)).andReturn(instances).anyTimes(); | ||
|
||
replay(DiscoveryManager.class); | ||
replay(DiscoveryClient.class); | ||
replay(mockedDiscoveryManager); | ||
replay(mockedDiscoveryClient); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
ribbon-transport/src/test/java/com/netflix/client/netty/http/DiscoveryLoadBalancerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.client.netty.http; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.netflix.client.config.IClientConfig; | ||
import com.netflix.client.config.IClientConfigKey; | ||
import com.netflix.client.netty.RibbonTransport; | ||
import com.netflix.loadbalancer.LoadBalancerExecutor; | ||
import com.netflix.loadbalancer.Server; | ||
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; | ||
import com.netflix.ribbon.testutils.MockedDiscoveryServerListTest; | ||
import io.netty.buffer.ByteBuf; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class DiscoveryLoadBalancerTest extends MockedDiscoveryServerListTest { | ||
|
||
@Override | ||
protected List<Server> getMockServerList() { | ||
return Lists.newArrayList(new Server("www.google.com", 80), new Server("www.microsoft.com", 80)); | ||
} | ||
|
||
@Override | ||
protected String getVipAddress() { | ||
return "myvip"; | ||
} | ||
|
||
@Test | ||
public void testLoadBalancer() { | ||
IClientConfig config = IClientConfig.Builder.newBuilder().withDefaultValues() | ||
.withDeploymentContextBasedVipAddresses(getVipAddress()).build() | ||
.set(IClientConfigKey.Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName()); | ||
NettyHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient(config); | ||
LoadBalancerExecutor lbExecutor = client.getLoadBalancerExecutor(); | ||
List<Server> serverList = lbExecutor.getLoadBalancer().getServerList(false); | ||
assertEquals(getMockServerList(), serverList); | ||
} | ||
} |
Oops, something went wrong.