From e043dca4e8b28fc1125827f9959e04834a02ac77 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 8 Jan 2020 09:31:47 +0100 Subject: Wait longer --- .../dispatch/searchcluster/SearchClusterTest.java | 22 +++++++++++++++++----- 1 file 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 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 numDocsPerNode; List pingCounts; + State(String clusterId, int nodesPergroup, String ... nodeNames) { this(clusterId, nodesPergroup, Arrays.asList(nodeNames)); } + State(String clusterId, int nodesPergroup, List 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 list) { + + static private int maxFrom(List 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 list) { + + private static int minFrom(List 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 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 { private final AtomicInteger numDocs; -- cgit v1.2.3