summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-01-13 14:37:32 +0100
committerGitHub <noreply@github.com>2020-01-13 14:37:32 +0100
commit2bc80f900585a40d1cfb49f66ee9a4248ecf733b (patch)
treefdad997fea4919bf9f50ad8ba5ebe0a661208eb8
parent09ddc9f27f81d8f1c4933cd2b6f8c7d8622372c4 (diff)
parentcf4f08d9edaf1adeea8711de5cfb3dde1bf79844 (diff)
Merge pull request #11758 from vespa-engine/hmusum/try-to-stabilize-test
Hmusum/try to stabilize test
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java231
1 files changed, 116 insertions, 115 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 f7d2ebc2c1e..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
@@ -9,14 +9,12 @@ import com.yahoo.prelude.Pong;
import com.yahoo.search.cluster.ClusterMonitor;
import com.yahoo.search.dispatch.MockSearchCluster;
import com.yahoo.search.result.ErrorMessage;
-import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
-import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -30,21 +28,7 @@ import static org.junit.Assert.assertTrue;
*/
public class SearchClusterTest {
- static class State {
-
- class MyExecutor implements Executor {
- private final List<Runnable> list = new ArrayList<>();
- @Override
- public void execute(@NotNull Runnable command) {
- list.add(command);
- }
- void run() {
- for (Runnable runnable : list) {
- runnable.run();
- }
- list.clear();
- }
- }
+ static class State implements AutoCloseable{
final String clusterId;
final int nodesPerGroup;
@@ -57,22 +41,22 @@ public class SearchClusterTest {
this(clusterId, nodesPergroup, Arrays.asList(nodeNames));
}
- State(String clusterId, int nodesPergroup, List<String> nodeNames) {
+ State(String clusterId, int nodesPerGroup, List<String> nodeNames) {
this.clusterId = clusterId;
- this.nodesPerGroup = nodesPergroup;
+ this.nodesPerGroup = nodesPerGroup;
vipStatus = new VipStatus(new QrSearchersConfig.Builder().searchcluster(new QrSearchersConfig.Searchcluster.Builder().name(clusterId)).build(), new ClustersStatus());
numDocsPerNode = new ArrayList<>(nodeNames.size());
pingCounts = new ArrayList<>(nodeNames.size());
List<Node> nodes = new ArrayList<>(nodeNames.size());
for (String name : nodeNames) {
- int key = nodes.size() % nodesPergroup;
- int group = nodes.size() / nodesPergroup;
+ int key = nodes.size() % nodesPerGroup;
+ int group = nodes.size() / nodesPerGroup;
nodes.add(new Node(key, name, group));
numDocsPerNode.add(new AtomicInteger(1));
pingCounts.add(new AtomicInteger(0));
}
- searchCluster = new SearchCluster(clusterId, MockSearchCluster.createDispatchConfig(nodes), nodes.size() / nodesPergroup, vipStatus);
+ searchCluster = new SearchCluster(clusterId, MockSearchCluster.createDispatchConfig(nodes), nodes.size() / nodesPerGroup, vipStatus);
}
void startMonitoring() {
@@ -108,7 +92,9 @@ public class SearchClusterTest {
boolean completed = executor.awaitTermination(120, TimeUnit.SECONDS);
if ( ! completed )
throw new IllegalStateException("Ping thread timed out");
- } catch (InterruptedException e) {}
+ } catch (InterruptedException e) {
+ System.out.println("Ping thread interrupted");
+ }
}
}
@@ -116,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;
@@ -125,7 +116,7 @@ public class SearchClusterTest {
this.pingCount = pingCount;
}
@Override
- public Pong call() throws Exception {
+ public Pong call() {
int docs = numDocs.get();
pingCount.incrementAndGet();
return (docs < 0)
@@ -164,102 +155,109 @@ 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
public void requireThatVipStatusDownRequireAllNodesDown() {
verifyThatVipStatusDownRequireAllNodesDown(1,2);
@@ -278,25 +276,28 @@ 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
public void requireThatVipStatusUpRequireOnlyOneOnlineNode() {
verifyThatVipStatusUpRequireOnlyOneOnlineNode(1, 2);