trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [incubator-trafficcontrol] 19/36: Add deep NetworkNode test coverage
Date Wed, 24 Jan 2018 17:23:28 GMT
This is an automated email from the ASF dual-hosted git repository.

elsloo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-trafficcontrol.git

commit d5ec7447eb7d520d26438076fda8feb5c52b2bc2
Author: Rawlin Peters <rawlin_peters@comcast.com>
AuthorDate: Fri Nov 3 16:34:55 2017 -0600

    Add deep NetworkNode test coverage
---
 .../traffic_router/core/router/TrafficRouter.java  |  2 +-
 .../traffic_router/core/loc/NetworkNodeTest.java   | 44 +++++++++++++++-------
 .../core/loc/NetworkNodeUnitTest.java              | 27 +++++++++++++
 3 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
index 00fafdb..be0579d 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/TrafficRouter.java
@@ -640,7 +640,7 @@ public class TrafficRouter {
 
 	@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
 	public CacheLocation getCoverageZoneCacheLocation(final String ip, final String deliveryServiceId,
final boolean useDeep) {
-		NetworkNode networkNode = useDeep ? getDeepNetworkNode(ip) : getNetworkNode(ip);
+		final NetworkNode networkNode = useDeep ? getDeepNetworkNode(ip) : getNetworkNode(ip);
 
 		if (networkNode == null) {
 			return null;
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
index 0a1e7dd..3517751 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeTest.java
@@ -42,36 +42,45 @@ import org.junit.experimental.categories.Category;
 public class NetworkNodeTest {
 	private static final Logger LOGGER = Logger.getLogger(NetworkNodeTest.class);
 	private Map<String, List<String>> netMap = new HashMap<String, List<String>>();
+	private Map<String, List<String>> deepNetMap = new HashMap<String, List<String>>();
 	private NetworkNode root;
+	private NetworkNode deepRoot;
 
 	@Before
 	public void setUp() throws Exception {
-		final File file = new File(getClass().getClassLoader().getResource("czmap.json").toURI());
-		root = NetworkNode.generateTree(file, false);
+		root = setUp("czmap.json", false);
+		deepRoot = setUp("dczmap.json", true);
+	}
+
+	private NetworkNode setUp(final String filename, final boolean useDeep) throws Exception
{
+		final Map<String, List<String>> testNetMap = useDeep ? deepNetMap : netMap;
+		final File file = new File(getClass().getClassLoader().getResource(filename).toURI());
+		final NetworkNode nn = NetworkNode.generateTree(file, false, useDeep);
 		final ObjectMapper mapper = new ObjectMapper();
 		final JsonNode jsonNode = mapper.readTree(file);
 		final JsonNode coverageZones = jsonNode.get("coverageZones");
 
 		final Iterator<String> networkIter = coverageZones.fieldNames();
 		while (networkIter.hasNext()) {
-			final String loc = networkIter.next();
+		    final String loc = networkIter.next();
 			final JsonNode locData = coverageZones.get(loc);
-			for (final JsonNode networkType : locData) {
-				final String network = networkType.get(0).asText().split("/")[0];
+			for (String networkType : new String[]{"network", "network6"}) {
+				final JsonNode networks = locData.get(networkType);
+				final String network = networks.get(0).asText().split("/")[0];
 				InetAddress ip = InetAddresses.forString(network);
 				ip = InetAddresses.increment(ip);
 
-				if (!netMap.containsKey(loc)) {
-					netMap.put(loc, new ArrayList<String>());
+				if (!testNetMap.containsKey(loc)) {
+					testNetMap.put(loc, new ArrayList<String>());
 				}
 
-				final List<String> addressList = netMap.get(loc);
+				final List<String> addressList = testNetMap.get(loc);
 				addressList.add(InetAddresses.toAddrString(ip));
 
-				netMap.put(loc, addressList);
-
+				testNetMap.put(loc, addressList);
 			}
 		}
+		return nn;
 	}
 
 	@Test
@@ -93,15 +102,24 @@ public class NetworkNodeTest {
 
 	@Test
 	public void testNetworkNodePerformance() {
+		testNetworkNodePerformance(root, netMap);
+	}
+
+	@Test
+	public void testDeepNetworkNodePerformance() {
+		testNetworkNodePerformance(deepRoot, deepNetMap);
+	}
+
+	private void testNetworkNodePerformance(NetworkNode testRoot, Map<String, List<String>>
testNetMap) {
 		final int iterations = 100000;
 		final long startTime = System.currentTimeMillis();
 		final long nnTPS = Long.parseLong(System.getProperty("nnTPS", "12000"));
 
 		for (int i = 0; i < iterations; i++) {
-			for (final String location : netMap.keySet()) {
+			for (final String location : testNetMap.keySet()) {
 				try {
-					for (final String address : netMap.get(location)) {
-						final NetworkNode nn = root.getNetwork(address);
+					for (final String address : testNetMap.get(location)) {
+						final NetworkNode nn = testRoot.getNetwork(address);
 					}
 				} catch (final NetworkNodeException e) {
 					e.printStackTrace();
diff --git a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
index c12bfd6..f4dd55a 100644
--- a/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
+++ b/traffic_router/core/src/test/java/com/comcast/cdn/traffic_control/traffic_router/core/loc/NetworkNodeUnitTest.java
@@ -20,8 +20,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 
 
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
@@ -87,6 +89,31 @@ public class NetworkNodeUnitTest {
     }
 
     @Test
+    public void itSupportsDeepCaches() throws Exception {
+        String czmapString = "{" +
+                "\"revision\": \"Mon Dec 21 15:04:01 2015\"," +
+                "\"customerName\": \"Kabletown\"," +
+                "\"coverageZones\": {" +
+                "\"us-co-denver\": {" +
+                "\"network\": [\"192.168.55.0/24\",\"192.168.6.0/24\",\"192.168.0.0/16\"],"
+
+                "\"network6\": [\"1234:5678::/64\",\"1234:5679::/64\"]," +
+                "\"caches\": [\"host1\",\"host2\"]" +
+                "}" +
+                "}" +
+                "}";
+
+        JSONTokener jsonTokener = new JSONTokener(czmapString);
+        final JSONObject json = new JSONObject(jsonTokener);
+        NetworkNode networkNode = NetworkNode.generateTree(json, false, true);
+        NetworkNode foundNetworkNode = networkNode.getNetwork("192.168.55.100");
+
+        Set<String> expected = new HashSet<String>();
+        expected.add("host1");
+        expected.add("host2");
+        assertThat(foundNetworkNode.getDeepCacheNames(), equalTo(expected));
+    }
+
+    @Test
     public void itDoesIpV6() throws Exception {
         String czmapString = "{" +
             "\"revision\": \"Mon Dec 21 15:04:01 2015\"," +

-- 
To stop receiving notification emails like this one, please contact
elsloo@apache.org.

Mime
View raw message