diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-01-08 10:44:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-08 10:44:26 +0100 |
commit | 2ab24ec8e3a57f4524ae4138b7c9e5ecfaaa77ce (patch) | |
tree | eae92af3e5e633b48bdc4eba0f4ac96b290ee128 | |
parent | 367398f4617955fcaad51d421cdff9d1f1794830 (diff) | |
parent | e043dca4e8b28fc1125827f9959e04834a02ac77 (diff) |
Merge pull request #11694 from vespa-engine/bratseth/wait-longer-on-ping
Wait longer
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/SearchClusterTest.java | 22 |
1 files changed, 17 insertions, 5 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 315a05ce14d..f7d2ebc2c1e 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 @@ -31,6 +31,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 @@ -44,15 +45,18 @@ public class SearchClusterTest { list.clear(); } } + final String clusterId; final int nodesPerGroup; final VipStatus vipStatus; final SearchCluster searchCluster; final List<AtomicInteger> numDocsPerNode; List<AtomicInteger> pingCounts; + State(String clusterId, int nodesPergroup, String ... nodeNames) { this(clusterId, nodesPergroup, Arrays.asList(nodeNames)); } + State(String clusterId, int nodesPergroup, List<String> nodeNames) { this.clusterId = clusterId; this.nodesPerGroup = nodesPergroup; @@ -70,10 +74,12 @@ public class SearchClusterTest { } searchCluster = new SearchCluster(clusterId, MockSearchCluster.createDispatchConfig(nodes), nodes.size() / nodesPergroup, vipStatus); } + void startMonitoring() { searchCluster.startClusterMonitoring(new Factory(nodesPerGroup, numDocsPerNode, pingCounts)); } - static private int getMaxValue(List<AtomicInteger> list) { + + static private int maxFrom(List<AtomicInteger> list) { int max = list.get(0).get(); for (AtomicInteger v : list) { if (v.get() > max) { @@ -82,7 +88,8 @@ public class SearchClusterTest { } return max; } - private static int getMinValue(List<AtomicInteger> list) { + + private static int minFrom(List<AtomicInteger> list) { int min = list.get(0).get(); for (AtomicInteger v : list) { if (v.get() < min) { @@ -91,19 +98,24 @@ public class SearchClusterTest { } return min; } + private void waitAtLeast(int atLeast, List<AtomicInteger> list) { - while (getMinValue(list) < atLeast) { + while (minFrom(list) < atLeast) { ExecutorService executor = Executors.newCachedThreadPool(); searchCluster.clusterMonitor().ping(executor); executor.shutdown(); try { - executor.awaitTermination(60, TimeUnit.SECONDS); + boolean completed = executor.awaitTermination(120, TimeUnit.SECONDS); + if ( ! completed ) + throw new IllegalStateException("Ping thread timed out"); } catch (InterruptedException e) {} } } + void waitOneFullPingRound() { - waitAtLeast(getMaxValue(pingCounts) + 1, pingCounts); + waitAtLeast(maxFrom(pingCounts) + 1, pingCounts); } + static class Factory implements PingFactory { static class Pinger implements Callable<Pong> { private final AtomicInteger numDocs; |