summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-01-13 13:10:06 +0100
committerHarald Musum <musum@verizonmedia.com>2020-01-13 13:10:06 +0100
commitcf4f08d9edaf1adeea8711de5cfb3dde1bf79844 (patch)
tree2cadd33b537021613737921389331d59ddc910e5
parent6dee1f03f77ff7395c375ef561bcae4b56b1f390 (diff)
Shutdown search cluster monitoring after use
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java197
1 files changed, 105 insertions, 92 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java
index 5e188cb5c17..57c587dcabc 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java
@@ -28,7 +28,7 @@ import static org.junit.Assert.assertTrue;
*/
public class SearchClusterTest {
- static class State {
+ static class State implements AutoCloseable{
final String clusterId;
final int nodesPerGroup;
@@ -102,6 +102,11 @@ public class SearchClusterTest {
waitAtLeast(maxFrom(pingCounts) + 1, pingCounts);
}
+ @Override
+ public void close() {
+ searchCluster.shutDown();
+ }
+
static class Factory implements PingFactory {
static class Pinger implements Callable<Pong> {
private final AtomicInteger numDocs;
@@ -150,101 +155,107 @@ public class SearchClusterTest {
@Test
public void requireThatZeroDocsAreFine() {
- State test = new State("cluster.1", 2, "a", "b");
- test.startMonitoring();
- test.waitOneFullPingRound();
-
- assertTrue(test.vipStatus.isInRotation());
- assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty());
-
- test.numDocsPerNode.get(0).set(-1);
- test.numDocsPerNode.get(1).set(-1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(0).set(0);
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
+ try (State test = new State("cluster.1", 2, "a", "b")) {
+ test.startMonitoring();
+ test.waitOneFullPingRound();
+
+ assertTrue(test.vipStatus.isInRotation());
+ assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty());
+
+ test.numDocsPerNode.get(0).set(-1);
+ test.numDocsPerNode.get(1).set(-1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(0).set(0);
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ }
}
@Test
public void requireThatVipStatusIsDefaultDownWithLocalDispatch() {
- State test = new State("cluster.1", 1, HostName.getLocalhost(), "b");
- assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent());
+ try (State test = new State("cluster.1", 1, HostName.getLocalhost(), "b")) {
+ assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent());
- assertFalse(test.vipStatus.isInRotation());
- test.startMonitoring();
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
+ assertFalse(test.vipStatus.isInRotation());
+ test.startMonitoring();
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ }
}
@Test
public void requireThatVipStatusIsDefaultDownWithOnlySingleLocalDispatch() {
- State test = new State("cluster.1", 1, HostName.getLocalhost());
- assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent());
-
- assertFalse(test.vipStatus.isInRotation());
- test.startMonitoring();
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(0).set(-1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
+ try (State test = new State("cluster.1", 1, HostName.getLocalhost())) {
+ assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent());
+
+ assertFalse(test.vipStatus.isInRotation());
+ test.startMonitoring();
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(0).set(-1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
+ }
}
@Test
public void requireThatVipStatusDownWhenLocalIsDown() {
- State test = new State("cluster.1",1,HostName.getLocalhost(), "b");
-
- test.startMonitoring();
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent());
-
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(0).set(-1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
-
- test.numDocsPerNode.get(0).set(1);
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
-
- test.numDocsPerNode.get(1).set(-1);
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
-
- test.numDocsPerNode.get(0).set(-1);
- test.numDocsPerNode.get(1).set(-1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(1).set(1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(0).set(1);
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
+ try (State test = new State("cluster.1",1,HostName.getLocalhost(), "b")) {
+
+ test.startMonitoring();
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ assertTrue(test.searchCluster.localCorpusDispatchTarget().isPresent());
+
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(0).set(-1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
+
+ test.numDocsPerNode.get(0).set(1);
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+
+ test.numDocsPerNode.get(1).set(-1);
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+
+ test.numDocsPerNode.get(0).set(-1);
+ test.numDocsPerNode.get(1).set(-1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(1).set(1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(0).set(1);
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ }
}
private void verifyThatVipStatusDownRequireAllNodesDown(int numGroups, int nodesPerGroup) {
List<String> nodeNames = generateNodeNames(numGroups, nodesPerGroup);
- State test = new State("cluster.1", nodesPerGroup, nodeNames);
- test.startMonitoring();
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty());
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
+ try (State test = new State("cluster.1", nodesPerGroup, nodeNames)) {
+ test.startMonitoring();
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty());
+
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
- for (int i=0; i < test.numDocsPerNode.size()-1; i++) {
- test.numDocsPerNode.get(i).set(-1);
+ for (int i = 0; i < test.numDocsPerNode.size() - 1; i++) {
+ test.numDocsPerNode.get(i).set(-1);
+ }
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(test.numDocsPerNode.size() - 1).set(-1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
}
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(test.numDocsPerNode.size()-1).set(-1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
}
@Test
@@ -265,24 +276,26 @@ public class SearchClusterTest {
private void verifyThatVipStatusUpRequireOnlyOneOnlineNode(int numGroups, int nodesPerGroup) {
List<String> nodeNames = generateNodeNames(numGroups, nodesPerGroup);
- State test = new State("cluster.1", nodesPerGroup, nodeNames);
- test.startMonitoring();
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty());
- for (int i=0; i < test.numDocsPerNode.size()-1; i++) {
- test.numDocsPerNode.get(i).set(-1);
- }
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
- test.numDocsPerNode.get(test.numDocsPerNode.size()-1).set(-1);
- test.waitOneFullPingRound();
- assertFalse(test.vipStatus.isInRotation());
+ try (State test = new State("cluster.1", nodesPerGroup, nodeNames)) {
+ test.startMonitoring();
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ assertTrue(test.searchCluster.localCorpusDispatchTarget().isEmpty());
- test.numDocsPerNode.get(0).set(0);
- test.waitOneFullPingRound();
- assertTrue(test.vipStatus.isInRotation());
+ for (int i = 0; i < test.numDocsPerNode.size() - 1; i++) {
+ test.numDocsPerNode.get(i).set(-1);
+ }
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ test.numDocsPerNode.get(test.numDocsPerNode.size() - 1).set(-1);
+ test.waitOneFullPingRound();
+ assertFalse(test.vipStatus.isInRotation());
+
+ test.numDocsPerNode.get(0).set(0);
+ test.waitOneFullPingRound();
+ assertTrue(test.vipStatus.isInRotation());
+ }
}
@Test