This is an automated email from the ASF dual-hosted git repository.
hanahmily pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 8eb2bef Add Junit test for ribbon's NIWSServerListClassName #1390
(#1407)
8eb2bef is described below
commit 8eb2bef192aa2a9f875fc8e36b8196d3b002223c
Author: 歪脖大肚子Q <[email protected]>
AuthorDate: Mon Jul 9 10:08:42 2018 +0800
Add Junit test for ribbon's NIWSServerListClassName #1390 (#1407)
* Add Junit test for ribbon's NIWSServerListClassName
* Add License Head to Code file
* try to solve submodule skywalking-ui conflict
---
apm-webapp/pom.xml | 6 ++
.../apm/webapp/proxy/NIWSServerListTest.java | 95 ++++++++++++++++++++++
2 files changed, 101 insertions(+)
diff --git a/apm-webapp/pom.xml b/apm-webapp/pom.xml
index f81c1fc..9e171c4 100644
--- a/apm-webapp/pom.xml
+++ b/apm-webapp/pom.xml
@@ -88,6 +88,12 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <version>${spring.boot.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/proxy/NIWSServerListTest.java
b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/proxy/NIWSServerListTest.java
new file mode 100644
index 0000000..38748ce
--- /dev/null
+++
b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/proxy/NIWSServerListTest.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.skywalking.apm.webapp.proxy;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.core.env.AbstractEnvironment;
+import org.springframework.core.env.Environment;
+import org.springframework.core.env.MapPropertySource;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import com.netflix.loadbalancer.Server;
+import com.netflix.loadbalancer.ServerList;
+import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
+import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@SpringBootTest
+@DirtiesContext
+public class NIWSServerListTest {
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private SpringClientFactory factory;
+
+ private Map<String, String> serverListClassNames = new HashMap<String,
String>();
+
+ @Before
+ public void initServerListClassNames() {
+ for (Iterator<?> iter = ((AbstractEnvironment)
env).getPropertySources().iterator(); iter.hasNext();) {
+ Object propertySource = iter.next();
+ if (propertySource instanceof MapPropertySource) {
+ Map<String, Object> mapPropertySource = ((MapPropertySource)
propertySource).getSource();
+ for (Map.Entry<String, Object> entry :
mapPropertySource.entrySet()) {
+ String key = entry.getKey();
+ int index;
+ if (key.endsWith(".NIWSServerListClassName") &&
+ (index = key.indexOf(".ribbon")) > 0) {
+ String clientName = key.substring(0, index);
+
serverListClassNames.put(clientName,(String)entry.getValue());
+ }
+ }
+ }
+ }
+ }
+
+ @Test
+ public void serverListClass() throws ClassNotFoundException {
+ for (String serverListClassName : serverListClassNames.values()) {
+ Class<?> clazz = Class.forName(serverListClassName);
+ }
+ }
+
+ @Test
+ public void serverListFliter() {
+ for (Map.Entry<String, String> entry :
serverListClassNames.entrySet()) {
+ String clientName = entry.getKey();
+ String serverListClassName = entry.getValue();
+ ServerList<Server> serverList =
getLoadBalancer(clientName).getServerListImpl();
+ assertNotNull("Client: " + clientName + "'s ServerListImpl is
null",serverList);
+ assertEquals("Clinet: " + clientName + "'s ServerListImpl not Same
with setting in configs",
+ serverListClassName, serverList.getClass().getName());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private ZoneAwareLoadBalancer<Server> getLoadBalancer(String name) {
+ return
(ZoneAwareLoadBalancer<Server>)this.factory.getLoadBalancer(name);
+ }
+}