aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/test/java/com/yahoo')
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java18
-rw-r--r--container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/MockSearchCluster.java14
2 files changed, 32 insertions, 0 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java
index 82b7845d63d..ff37352b39c 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/rpc/RpcSearchInvokerTest.java
@@ -16,6 +16,8 @@ import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
+import static com.yahoo.search.dispatch.searchcluster.MockSearchCluster.createDispatchConfig;
+import static com.yahoo.search.dispatch.searchcluster.MockSearchCluster.createNodesConfig;
import static org.junit.jupiter.api.Assertions.*;
/**
@@ -71,6 +73,22 @@ public class RpcSearchInvokerTest {
assertEquals(maxHits, request.getHits());
}
+ void verifyConnections(RpcResourcePool rpcResourcePool, int numGroups, int nodesPerGroup) {
+ rpcResourcePool.updateNodes(createNodesConfig(numGroups,nodesPerGroup));
+ for (int nodeId = 0; nodeId < numGroups*nodesPerGroup; nodeId++) {
+ assertTrue(rpcResourcePool.getConnection(nodeId) instanceof RpcClient.RpcNodeConnection);
+ }
+ assertNull(rpcResourcePool.getConnection(numGroups*nodesPerGroup));
+ }
+
+ @Test
+ void testUpdateOfRpcResourcePool() {
+ RpcResourcePool rpcResourcePool = new RpcResourcePool(createDispatchConfig(), createNodesConfig(0, 0));
+ verifyConnections(rpcResourcePool, 3,3);
+ verifyConnections(rpcResourcePool, 4,4);
+ verifyConnections(rpcResourcePool, 2,2);
+ }
+
private Client parameterCollectorClient(AtomicReference<CompressionType> compressionTypeHolder, AtomicReference<byte[]> payloadHolder,
AtomicInteger lengthHolder) {
return new Client() {
diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/MockSearchCluster.java b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/MockSearchCluster.java
index cbf6273d3ae..5fb5b465c69 100644
--- a/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/MockSearchCluster.java
+++ b/container-search/src/test/java/com/yahoo/search/dispatch/searchcluster/MockSearchCluster.java
@@ -2,6 +2,7 @@
package com.yahoo.search.dispatch.searchcluster;
import com.yahoo.vespa.config.search.DispatchConfig;
+import com.yahoo.vespa.config.search.DispatchNodesConfig;
import java.util.ArrayList;
import java.util.HashMap;
@@ -52,6 +53,19 @@ public class MockSearchCluster extends SearchCluster {
return builder;
}
+ public static DispatchNodesConfig createNodesConfig(int numGroups, int nodesPerGroup) {
+ var builder = new DispatchNodesConfig.Builder();
+ int key = 0;
+ for (int g = 0; g < numGroups; g++) {
+ for (int i = 0; i < nodesPerGroup; i++) {
+ var nodeBuilder = new DispatchNodesConfig.Node.Builder();
+ nodeBuilder.key(key++).port(0).group(g).host("host" + g + "." + i);
+ builder.node.add(nodeBuilder);
+ }
+ }
+ return builder.build();
+ }
+
public static SearchGroupsImpl buildGroupListForTest(int numGroups, int nodesPerGroup, double minActivedocsPercentage) {
return new SearchGroupsImpl(buildGroupMapForTest(numGroups, nodesPerGroup), minActivedocsPercentage);
}