diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-01-08 09:31:47 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-01-08 09:31:47 +0100 |
commit | e043dca4e8b28fc1125827f9959e04834a02ac77 (patch) | |
tree | f1781ed59a68921f8425ac7e67e1317b3392c5b0 /container-search/src/test/java/com/yahoo/search/dispatch | |
parent | c09114f0c8111e3fe8b9c7758ee8c386d58f3e73 (diff) |
Wait longer
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/dispatch')
-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; |