diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-24 00:00:19 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-24 00:00:19 +0100 |
commit | 90b260e83678edc36eb877ec235e0e6ce5892a48 (patch) | |
tree | 081a1ebe9316553bcbbf3d568f245d702b72bd55 /container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java | |
parent | ba11a8a87877dd3a97586255839b02782b70de87 (diff) |
Cleanup the concept of orderedGroups. Just use a single way of accessing the groups.
Simplify testing by introducing a GroupList to contain all acces to groups and nodes.
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java')
-rw-r--r-- | container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java | 84 |
1 files changed, 3 insertions, 81 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java b/container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java index 32ca63693b4..9a4931a8fa7 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/MockSearchCluster.java @@ -1,91 +1,25 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.dispatch; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; -import com.yahoo.search.dispatch.searchcluster.Group; +import com.yahoo.search.dispatch.searchcluster.GroupListImpl; import com.yahoo.search.dispatch.searchcluster.Node; import com.yahoo.search.dispatch.searchcluster.SearchCluster; import com.yahoo.vespa.config.search.DispatchConfig; -import com.yahoo.vespa.config.search.DispatchNodesConfig; -import java.util.ArrayList; import java.util.List; -import java.util.Optional; /** * @author ollivir */ public class MockSearchCluster extends SearchCluster { - private final int numGroups; - private final int numNodesPerGroup; - private final ImmutableList<Group> orderedGroups; - private final ImmutableMap<Integer, Group> groups; - private final List<Node> nodes; - public MockSearchCluster(String clusterId, int groups, int nodesPerGroup) { - this(clusterId, createDispatchConfig(), createNodesConfig(), groups, nodesPerGroup); + super(clusterId, 88.0, GroupListImpl.buildGroupListForTest(groups, nodesPerGroup), null, null); } - public MockSearchCluster(String clusterId, DispatchConfig dispatchConfig, DispatchNodesConfig nodesConfig, int groups, int nodesPerGroup) { - super(clusterId, dispatchConfig, nodesConfig, null, null); - - ImmutableList.Builder<Group> orderedGroupBuilder = ImmutableList.builder(); - ImmutableMap.Builder<Integer, Group> groupBuilder = ImmutableMap.builder(); - ImmutableMultimap.Builder<String, Node> hostBuilder = ImmutableMultimap.builder(); - int distributionKey = 0; - this.nodes = new ArrayList<>(); - for (int group = 0; group < groups; group++) { - List<Node> groupNodes = new ArrayList<>(); - for (int i = 0; i < nodesPerGroup; i++) { - Node node = new Node(distributionKey, "host" + distributionKey, group); - nodes.add(node); - groupNodes.add(node); - hostBuilder.put(node.hostname(), node); - distributionKey++; - } - Group g = new Group(group, groupNodes); - groupBuilder.put(group, g); - orderedGroupBuilder.add(g); - } - this.orderedGroups = orderedGroupBuilder.build(); - this.groups = groupBuilder.build(); - this.numGroups = groups; - this.numNodesPerGroup = nodesPerGroup; - } - - @Override - public ImmutableList<Group> orderedGroups() { - return orderedGroups; - } - - @Override - public ImmutableMap<Integer, Group> groups() { - return groups; - } - - @Override - public boolean allGroupsHaveSize1() { return numNodesPerGroup == 1;} - @Override public int groupsWithSufficientCoverage() { - return numGroups; - } - - @Override - public Optional<Group> group(int n) { - if (n < numGroups) { - return Optional.of(groups.get(n)); - } else { - return Optional.empty(); - } - } - - @Override - public Optional<Node> localCorpusDispatchTarget() { - return Optional.empty(); + return numGroups(); } @Override @@ -101,9 +35,6 @@ public class MockSearchCluster extends SearchCluster { public static DispatchConfig createDispatchConfig() { return createDispatchConfig(100.0); } - public static DispatchNodesConfig createNodesConfig(Node... nodes) { - return createNodesConfig(List.of(nodes)).build(); - } public static DispatchConfig createDispatchConfig(double minSearchCoverage) { return createDispatchConfigBuilder(minSearchCoverage).build(); @@ -121,13 +52,4 @@ public class MockSearchCluster extends SearchCluster { return builder; } - public static DispatchNodesConfig.Builder createNodesConfig(List<Node> nodes) { - DispatchNodesConfig.Builder builder = new DispatchNodesConfig.Builder(); - int port = 10000; - for (Node n : nodes) { - builder.node(new DispatchNodesConfig.Node.Builder().key(n.key()).host(n.hostname()).port(port++).group(n.group())); - } - return builder; - } - } |