aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-06-05 17:11:55 +0200
committerHarald Musum <musum@yahooinc.com>2023-06-05 17:11:55 +0200
commitaa21f8b53457c94144a969fb60ce1075b80fcecb (patch)
tree701e39c9ef8324346fd62be1cc5d9c08dbfe64e7 /clustercontroller-core/src/test
parentabf620e10fb21a1295a2f6ca69b4c592d824a385 (diff)
Remove support for RPC method getMaster, only used in tests
Diffstat (limited to 'clustercontroller-core/src/test')
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java116
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java20
2 files changed, 1 insertions, 135 deletions
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java
index 93a96be71a0..af7a0a4b92c 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/MasterElectionTest.java
@@ -1,10 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
-import com.yahoo.jrt.Request;
-import com.yahoo.jrt.Spec;
import com.yahoo.jrt.Supervisor;
-import com.yahoo.jrt.Target;
import com.yahoo.jrt.Transport;
import com.yahoo.vdslib.state.ClusterState;
import com.yahoo.vdslib.state.NodeState;
@@ -16,16 +13,13 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.extension.ExtendWith;
+
import java.time.Instant;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -281,114 +275,6 @@ public class MasterElectionTest extends FleetControllerTest {
waitForMaster(1);
}
- private void waitForNoMasterWithExpectedReason(String reason, List<Target> connections, int[] nodes) {
- Objects.requireNonNull(reason, "reason cannot be null");
- Instant endTime = Instant.now().plus(timeout());
- while (Instant.now().isBefore(endTime)) {
- boolean allOk = true;
- for (int node : nodes) {
- Request req = new Request("getMaster");
- connections.get(node).invokeSync(req, timeout());
- if (req.isError()) {
- allOk = false;
- break;
- }
- if (req.returnValues().get(0).asInt32() != -1) { // -1 means no master, which we are waiting for
- allOk = false;
- break;
- }
- if ( ! reason.equals(req.returnValues().get(1).asString())) {
- allOk = false;
- break;
- }
- }
- if (allOk) return;
- try { Thread.sleep(100); } catch (InterruptedException e) { /* ignore */ }
- }
- throw new IllegalStateException("Did not get master reason '" + reason + "' within timeout of " + timeout());
- }
-
- @Test
- void testGetMaster() throws Exception {
- FleetControllerOptions.Builder options = defaultOptions();
- options.setMasterZooKeeperCooldownPeriod(3600 * 1000); // An hour
- FakeTimer timer = new FakeTimer();
- setUpFleetControllers(3, timer, options);
- waitForMaster(0);
-
- List<Target> connections = new ArrayList<>();
- for (FleetController fleetController : fleetControllers) {
- int rpcPort = fleetController.getRpcPort();
- Target connection = supervisor.connect(new Spec("localhost", rpcPort));
- assertTrue(connection.isValid());
- connections.add(connection);
- }
-
- timer.advanceTime(24 * 3600 * 1000); // A day
- waitForCompleteCycles();
-
- Request req = new Request("getMaster");
-
- long maxRetries = timeout().toMillis() / 100;
- for (int nodeIndex = 0; nodeIndex < 3; ++nodeIndex) {
- for (int retry = 0; retry < maxRetries; ++retry) {
- req = new Request("getMaster");
- connections.get(nodeIndex).invokeSync(req, timeout());
- assertFalse(req.isError(), req.errorMessage());
- if (req.returnValues().get(0).asInt32() == 0 &&
- req.returnValues().get(1).asString().equals("All 3 nodes agree that 0 is current master.")) {
- break;
- }
- }
- assertEquals(0, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("All 3 nodes agree that 0 is current master.", req.returnValues().get(1).asString(), req.toString());
- }
-
- log.log(Level.INFO, "SHUTTING DOWN FLEET CONTROLLER 0");
- fleetControllers.get(0).shutdown();
- // Wait until fc 1 & 2 votes for node 1
- waitForCompleteCycle(1);
- waitForCompleteCycle(2);
- // 5 minutes is not long enough period to wait before letting this node be master.
- timer.advanceTime(300 * 1000); // 5 minutes
-
- int[] remainingNodes = {1, 2};
- waitForNoMasterWithExpectedReason(
- "2 of 3 nodes agree 1 should be master, but old master cooldown period of 3600000 ms has not passed yet. To ensure it has got time to realize it is no longer master before we elect a new one, currently there is no master.",
- connections,
- remainingNodes);
- // Verify that fc 1 is not master, and the correct reasons for why not
- assertFalse(fleetControllers.get(1).isMaster());
-
- // But after an hour it should become one.
- timer.advanceTime(3600 * 1000); // 60 minutes
- waitForMaster(1);
-
- req = new Request("getMaster");
- connections.get(0).invokeSync(req, timeout());
- assertEquals(104, req.errorCode(), req.toString());
- assertEquals("Connection error", req.errorMessage(), req.toString());
-
- for (int i = 0; i < maxRetries; ++i) {
- req = new Request("getMaster");
- connections.get(1).invokeSync(req, timeout());
- assertFalse(req.isError(), req.errorMessage());
- if (req.returnValues().get(0).asInt32() != -1) break;
- // We may have bad timing causing node not to have realized it is master yet
- }
- assertEquals(1, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("2 of 3 nodes agree 1 is master.", req.returnValues().get(1).asString(), req.toString());
-
- for (int i = 0; i < maxRetries; ++i) {
- req = new Request("getMaster");
- connections.get(2).invokeSync(req, timeout());
- assertFalse(req.isError(), req.errorMessage());
- if (req.returnValues().get(0).asInt32() != -1) break;
- }
- assertEquals(1, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("2 of 3 nodes agree 1 is master.", req.returnValues().get(1).asString(), req.toString());
- }
-
@Test
void testReconfigure() throws Exception {
FleetControllerOptions.Builder options = defaultOptions();
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
index e75ade7309c..82422762e88 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
@@ -462,26 +462,6 @@ public class RpcServerTest extends FleetControllerTest {
waitForState("version:\\d+ distributor:10 storage:10 .9.s:m");
}
- @Test
- void testGetMaster() throws Exception {
- FleetControllerOptions.Builder options = defaultOptions();
- options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(2, 10)));
- setUpFleetController(timer, options);
- setUpVdsNodes(timer);
- waitForStableSystem();
-
- int rpcPort = fleetController().getRpcPort();
- Target connection = supervisor.connect(new Spec("localhost", rpcPort));
- assertTrue(connection.isValid());
-
- Request req = new Request("getMaster");
- connection.invokeSync(req, timeout());
- assertEquals(0, req.returnValues().get(0).asInt32(), req.toString());
- assertEquals("All 1 nodes agree that 0 is current master.", req.returnValues().get(1).asString(), req.toString());
-
- // Note that this feature is tested better in MasterElectionTest.testGetMaster as it has multiple fleetcontrollers
- }
-
private Request setNodeState(String node, NodeState newNodeState, Target connection) {
return setNodeState(node, newNodeState.serialize(true), connection);
}