summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java
Publish
Diffstat (limited to 'clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java')
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java
new file mode 100644
index 00000000000..ae1f10eb61f
--- /dev/null
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/LeafGroupsTest.java
@@ -0,0 +1,67 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.clustercontroller.core;
+
+import com.yahoo.vdslib.distribution.Group;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+
+public class LeafGroupsTest {
+
+ @Test
+ public void rootGroupCountedAsLeafWhenNoChildren() {
+ Group g = new Group(0, "donkeykong");
+
+ List<Group> leaves = LeafGroups.enumerateFrom(g);
+ assertThat(leaves.size(), is(1));
+ assertThat(leaves.get(0).getName(), is("donkeykong"));
+ }
+
+ private Group.Distribution dummyDistribution() throws Exception {
+ return new Group.Distribution("*", 1);
+ }
+
+ @Test
+ public void singleLeafIsEnumerated() throws Exception {
+ Group g = new Group(0, "donkeykong", dummyDistribution());
+ Group child = new Group(1, "mario");
+ g.addSubGroup(child);
+
+ List<Group> leaves = LeafGroups.enumerateFrom(g);
+ assertThat(leaves.size(), is(1));
+ assertThat(leaves.get(0).getName(), is("mario"));
+ }
+
+ @Test
+ public void singleLeafIsEnumeratedInNestedCase() throws Exception {
+ Group g = new Group(0, "donkeykong", dummyDistribution());
+ Group child = new Group(1, "mario", dummyDistribution());
+ child.addSubGroup(new Group(2, "toad"));
+ g.addSubGroup(child);
+
+ List<Group> leaves = LeafGroups.enumerateFrom(g);
+ assertThat(leaves.size(), is(1));
+ assertThat(leaves.get(0).getName(), is("toad"));
+ }
+
+ @Test
+ public void multipleLeafGroupsAreEnumerated() throws Exception {
+ Group g = new Group(0, "donkeykong", dummyDistribution());
+ Group child = new Group(1, "mario", dummyDistribution());
+ child.addSubGroup(new Group(2, "toad"));
+ child.addSubGroup(new Group(3, "yoshi"));
+ g.addSubGroup(child);
+ g.addSubGroup(new Group(4, "luigi"));
+
+ List<Group> leaves = LeafGroups.enumerateFrom(g);
+ // Ensure that output order matches insertion order.
+ leaves.sort((a, b) -> Integer.compare(a.getIndex(), b.getIndex()));
+ assertThat(leaves.size(), is(3));
+ assertThat(leaves.get(0).getName(), is("toad"));
+ assertThat(leaves.get(1).getName(), is("yoshi"));
+ assertThat(leaves.get(2).getName(), is("luigi"));
+ }
+}