aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorJon Marius Venstad <jvenstad@yahoo-inc.com>2019-03-28 16:34:45 +0100
committerJon Marius Venstad <jvenstad@yahoo-inc.com>2019-03-28 16:34:45 +0100
commita648cd083c9ce29ab555490fe56d3c07b0404637 (patch)
treeb933477f3f67e252acffd1dae4aed41d01487266 /controller-server
parent18b482611899f2f794bd03b898f68dadd051851c (diff)
Update PathGroup tests to reflect nice property: no group overlap!
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java63
1 files changed, 30 insertions, 33 deletions
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java
index 4cf46933dcb..b4a3e674594 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/role/PathGroupTest.java
@@ -2,10 +2,12 @@ package com.yahoo.vespa.hosted.controller.role;
import org.junit.Test;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Pattern;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
@@ -15,45 +17,40 @@ import static org.junit.Assert.fail;
public class PathGroupTest {
@Test
- public void nonOverlappingGroups() {
- for (PathGroup pg : PathGroup.all()) {
- for (PathGroup pg2 : PathGroup.all()) {
- if (pg == pg2) continue;
- Set<String> overlapping = new LinkedHashSet<>(pg.pathSpecs);
- overlapping.retainAll(pg2.pathSpecs);
- if ( ! overlapping.isEmpty()) {
- fail("The following path specs overlap in " + pg + " and " + pg2 + ": " + overlapping);
- }
- }
- }
- }
-
- @Test
public void uniqueMatches() {
// Ensure that each path group contains at most one match for any given path, to avoid undefined context extraction.
- for (PathGroup group : PathGroup.values())
- for (String path1 : group.pathSpecs)
- for (String path2 : group.pathSpecs) {
- if (path1 == path2) continue;
+ Set<String> checkedAgainstSelf = new HashSet<>();
+ for (PathGroup group1 : PathGroup.values())
+ for (PathGroup group2 : PathGroup.values())
+ for (String path1 : group1.pathSpecs)
+ for (String path2 : group2.pathSpecs) {
+ if (path1.equals(path2)) {
+ if (checkedAgainstSelf.add(path1)) continue;
+ fail("Path '" + path1 + "' appears in both '" + group1 + "' and '" + group2 + "'.");
+ }
- String[] parts1 = path1.split("/");
- String[] parts2 = path2.split("/");
+ String[] parts1 = path1.split("/");
+ String[] parts2 = path2.split("/");
- int end = Math.min(parts1.length, parts2.length);
- // If one path has more parts than the other ...
- // and the other doesn't end with a wildcard matcher ...
- // and the longest one isn't just one wildcard longer ...
- if (end < parts1.length && (end == 0 || ! parts2[end - 1].equals("{*}")) && ! parts1[end].equals("{*}")) continue;
- if (end < parts2.length && (end == 0 || ! parts1[end - 1].equals("{*}")) && ! parts2[end].equals("{*}")) continue;
+ int end = Math.min(parts1.length, parts2.length);
+ // If one path has more parts than the other ...
+ // and the other doesn't end with a wildcard matcher ...
+ // and the longest one isn't just one wildcard longer ...
+ // then one is strictly longer than the other, and it's not a match.
+ if (end < parts1.length && (end == 0 || ! parts2[end - 1].equals("{*}")) && ! parts1[end].equals("{*}")) continue;
+ if (end < parts2.length && (end == 0 || ! parts1[end - 1].equals("{*}")) && ! parts2[end].equals("{*}")) continue;
- int i;
- for (i = 0; i < end; i++)
- if ( ! parts1[i].equals(parts2[i])
- && ! (parts1[i].startsWith("{") && parts1[i].endsWith("}"))
- && ! (parts2[i].startsWith("{") && parts2[i].endsWith("}"))) break;
+ int i;
+ for (i = 0; i < end; i++)
+ if ( ! parts1[i].equals(parts2[i])
+ && ! (parts1[i].startsWith("{") && parts1[i].endsWith("}"))
+ && ! (parts2[i].startsWith("{") && parts2[i].endsWith("}"))) break;
- if (i == end) fail("Paths '" + path1 + "' and '" + path2 + "' overlap.");
- }
+ if (i == end) fail("Paths '" + path1 + "' and '" + path2 + "' overlap.");
+ }
+
+ assertEquals(PathGroup.all().stream().mapToInt(group -> group.pathSpecs.size()).sum(),
+ checkedAgainstSelf.size());
}
@Test