From 12a6b3b68b7a8b00f166a4ce25f916e553d43959 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 19 Sep 2022 13:05:26 +0200 Subject: Create supervisor only in tests that uses it --- .../vespa/clustercontroller/core/DatabaseTest.java | 18 ++++++++++----- .../core/FleetControllerTest.java | 10 +-------- .../clustercontroller/core/MasterElectionTest.java | 17 ++++++++++++-- .../clustercontroller/core/RpcServerTest.java | 23 +++++++++++-------- .../clustercontroller/core/WantedStateTest.java | 26 +++++++++++++++++----- .../clustercontroller/core/testutils/Waiter.java | 9 ++++---- 6 files changed, 68 insertions(+), 35 deletions(-) (limited to 'clustercontroller-core') diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java index e4360a74885..666b4f63801 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/DatabaseTest.java @@ -12,9 +12,10 @@ import com.yahoo.vdslib.state.Node; import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.NodeType; import com.yahoo.vdslib.state.State; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; - import java.util.Map; import java.util.TreeMap; import java.util.logging.Logger; @@ -26,6 +27,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class DatabaseTest extends FleetControllerTest { private static final Logger log = Logger.getLogger(DatabaseTest.class.getName()); + private Supervisor supervisor; + + @BeforeEach + public void setup() { + supervisor = new Supervisor(new Transport()); + } + + @AfterEach + public void teardown() { + supervisor.transport().shutdown().join(); + } @Test void testWantedStatesInZooKeeper() throws Exception { @@ -147,9 +159,6 @@ public class DatabaseTest extends FleetControllerTest { // Note: different semantics than FleetControllerTest.setWantedState private void setWantedState(Node n, NodeState ns, Map wantedStates) { int rpcPort = fleetController().getRpcPort(); - if (supervisor == null) { - supervisor = new Supervisor(new Transport()); - } Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -162,5 +171,4 @@ public class DatabaseTest extends FleetControllerTest { wantedStates.put(n, ns); } - } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/FleetControllerTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/FleetControllerTest.java index 49d04e20621..d2ae4a8623f 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/FleetControllerTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/FleetControllerTest.java @@ -6,7 +6,6 @@ import com.yahoo.jrt.Spec; import com.yahoo.jrt.StringValue; import com.yahoo.jrt.Supervisor; import com.yahoo.jrt.Target; -import com.yahoo.jrt.Transport; import com.yahoo.jrt.slobrok.server.Slobrok; import com.yahoo.log.LogSetup; import com.yahoo.vdslib.distribution.ConfiguredNode; @@ -55,7 +54,6 @@ public abstract class FleetControllerTest implements Waiter { private final Duration timeout = Duration.ofSeconds(30); protected final FakeTimer timer = new FakeTimer(); - Supervisor supervisor; protected Slobrok slobrok; protected FleetControllerOptions options; ZooKeeperTestServer zooKeeperServer; @@ -259,9 +257,6 @@ public abstract class FleetControllerTest implements Waiter { System.err.println("STOPPING TEST " + testName); testName = null; } - if (supervisor != null) { - supervisor.transport().shutdown().join(); - } fleetControllers.forEach(f -> { try { f.shutdown(); @@ -303,10 +298,7 @@ public abstract class FleetControllerTest implements Waiter { .collect(Collectors.toSet()); } - void setWantedState(DummyVdsNode node, State state, String reason) { - if (supervisor == null) { - supervisor = new Supervisor(new Transport()); - } + void setWantedState(DummyVdsNode node, State state, String reason, Supervisor supervisor) { NodeState ns = new NodeState(node.getType(), state); if (reason != null) ns.setDescription(reason); Target connection = supervisor.connect(new Spec("localhost", fleetController().getRpcPort())); 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 4b566bd2aab..941ec6e23f3 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 @@ -11,6 +11,8 @@ import com.yahoo.vdslib.state.ClusterState; import com.yahoo.vdslib.state.NodeState; import com.yahoo.vdslib.state.NodeType; import com.yahoo.vdslib.state.State; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; @@ -35,6 +37,18 @@ public class MasterElectionTest extends FleetControllerTest { private static final Logger log = Logger.getLogger(MasterElectionTest.class.getName()); private static int defaultZkSessionTimeoutInMillis() { return 30_000; } + private Supervisor supervisor; + + @BeforeEach + public void setup() { + supervisor = new Supervisor(new Transport()); + } + + @AfterEach + public void teardown() { + supervisor.transport().shutdown().join(); + } + protected void setUpFleetControllers(int count, boolean useFakeTimer, FleetControllerOptions.Builder builder) throws Exception { if (zooKeeperServer == null) { zooKeeperServer = new ZooKeeperTestServer(); @@ -309,7 +323,6 @@ public class MasterElectionTest extends FleetControllerTest { setUpFleetControllers(3, true, options); waitForMaster(0); - supervisor = new Supervisor(new Transport()); List connections = new ArrayList<>(); for (FleetController fleetController : fleetControllers) { int rpcPort = fleetController.getRpcPort(); @@ -434,7 +447,7 @@ public class MasterElectionTest extends FleetControllerTest { n.disconnectImmediately(); waitForCompleteCycle(0); }); - setWantedState(this.nodes.get(2 * 10 - 1), State.MAINTENANCE, "bar"); + setWantedState(this.nodes.get(2 * 10 - 1), State.MAINTENANCE, "bar", supervisor); waitForCompleteCycle(0); // This receives the version number of the highest _working_ cluster state, with 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 e61bdd566c3..be06ea5a0d5 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 @@ -21,6 +21,8 @@ import com.yahoo.vdslib.state.State; import com.yahoo.vespa.clustercontroller.core.rpc.RpcServer; import com.yahoo.vespa.clustercontroller.core.testutils.LogFormatter; import com.yahoo.vespa.clustercontroller.core.testutils.WaitCondition; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import java.util.ArrayList; @@ -44,6 +46,18 @@ public class RpcServerTest extends FleetControllerTest { public static Logger log = Logger.getLogger(RpcServerTest.class.getName()); + private Supervisor supervisor; + + @BeforeEach + public void setup() { + supervisor = new Supervisor(new Transport()); + } + + @AfterEach + public void teardown() { + supervisor.transport().shutdown().join(); + } + @Test void testRebinding() throws Exception { startingTest("RpcServerTest::testRebinding"); @@ -118,7 +132,6 @@ public class RpcServerTest extends FleetControllerTest { }, null, timeout()); int rpcPort = fleetController().getRpcPort(); - supervisor = new Supervisor(new Transport()); Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -134,9 +147,6 @@ public class RpcServerTest extends FleetControllerTest { private void setWantedNodeState(State newState, NodeType nodeType, int nodeIndex) { int rpcPort = fleetController().getRpcPort(); - if (supervisor == null) { - supervisor = new Supervisor(new Transport()); - } Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -181,7 +191,6 @@ public class RpcServerTest extends FleetControllerTest { waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:i .1.i:0.2 .2.s:d .7.s:m"); int rpcPort = fleetController().getRpcPort(); - supervisor = new Supervisor(new Transport()); Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -448,7 +457,6 @@ public class RpcServerTest extends FleetControllerTest { waitForState("version:\\d+ distributor:26 .0.s:d .1.s:d .2.s:d .3.s:d .5.s:d .7.s:d .8.s:d .11.s:d .12.s:d .13.s:d .15.s:d .17.s:d .18.s:d .19.s:d .20.s:d .24.s:d storage:26 .0.s:d .1.s:d .2.s:d .3.s:d .5.s:d .7.s:d .8.s:d .11.s:d .12.s:d .13.s:d .15.s:d .17.s:d .18.s:d .19.s:d .20.s:d .24.s:d"); int rpcPort = fleetController().getRpcPort(); - supervisor = new Supervisor(new Transport()); Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -487,7 +495,6 @@ public class RpcServerTest extends FleetControllerTest { waitForStableSystem(); int rpcPort = fleetController().getRpcPort(); - supervisor = new Supervisor(new Transport()); Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -515,7 +522,6 @@ public class RpcServerTest extends FleetControllerTest { waitForStableSystem(); int rpcPort = fleetController().getRpcPort(); - supervisor = new Supervisor(new Transport()); Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); @@ -540,7 +546,6 @@ public class RpcServerTest extends FleetControllerTest { waitForState("version:\\d+ distributor:5 .0.s:d storage:5"); int rpcPort = fleetController().getRpcPort(); - supervisor = new Supervisor(new Transport()); Target connection = supervisor.connect(new Spec("localhost", rpcPort)); assertTrue(connection.isValid()); diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/WantedStateTest.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/WantedStateTest.java index d697dc40bb2..909f5a1f784 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/WantedStateTest.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/WantedStateTest.java @@ -1,7 +1,11 @@ // 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.Supervisor; +import com.yahoo.jrt.Transport; import com.yahoo.vdslib.state.State; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -10,6 +14,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(CleanupZookeeperLogsOnSuccess.class) public class WantedStateTest extends FleetControllerTest { + private Supervisor supervisor; + + @BeforeEach + public void setup() { + supervisor = new Supervisor(new Transport()); + } + + @AfterEach + public void teardown() { + supervisor.transport().shutdown().join(); + } + @Test void testSettingStorageNodeMaintenanceAndBack() throws Exception { startingTest("WantedStateTest::testSettingStorageNodeMaintenanceAndBack()"); @@ -17,10 +33,10 @@ public class WantedStateTest extends FleetControllerTest { setUpVdsNodes(true); waitForStableSystem(); - setWantedState(nodes.get(1), State.MAINTENANCE, null); + setWantedState(nodes.get(1), State.MAINTENANCE, null, supervisor); waitForState("version:\\d+ distributor:10 storage:10 .0.s:m"); - setWantedState(nodes.get(1), State.UP, null); + setWantedState(nodes.get(1), State.UP, null, supervisor); waitForState("version:\\d+ distributor:10 storage:10"); } @@ -31,15 +47,15 @@ public class WantedStateTest extends FleetControllerTest { setUpVdsNodes(true); waitForStableSystem(); - setWantedState(nodes.get(1), State.MAINTENANCE, "Foo"); + setWantedState(nodes.get(1), State.MAINTENANCE, "Foo", supervisor); waitForState("version:\\d+ distributor:10 storage:10 .0.s:m"); assertEquals("Foo", fleetController().getWantedNodeState(nodes.get(1).getNode()).getDescription()); - setWantedState(nodes.get(1), State.MAINTENANCE, "Bar"); + setWantedState(nodes.get(1), State.MAINTENANCE, "Bar", supervisor); waitForCompleteCycle(); assertEquals("Bar", fleetController().getWantedNodeState(nodes.get(1).getNode()).getDescription()); - setWantedState(nodes.get(1), State.UP, null); + setWantedState(nodes.get(1), State.UP, null, supervisor); waitForState("version:\\d+ distributor:10 storage:10"); } diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java index e4df6f31987..a7de2f0eedb 100644 --- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java +++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java @@ -43,17 +43,16 @@ public interface Waiter { } // TODO refactor - private ClusterState waitForState(String state, Duration timeoutMS, boolean checkAllSpaces, Set checkSpaces) { - LinkedList nodesToCheck = new LinkedList<>(); + private ClusterState waitForState(String state, Duration timeout, boolean checkAllSpaces, Set checkSpaces) { + LinkedList nodesToCheck = new LinkedList<>(); for(DummyVdsNode node : data.getDummyNodes()) { if (node.isConnected()) nodesToCheck.add(node); } - WaitCondition.StateWait swc = new WaitCondition.RegexStateMatcher( - state, data.getFleetController(), data.getMonitor()) + WaitCondition.StateWait swc = new WaitCondition.RegexStateMatcher(state, data.getFleetController(), data.getMonitor()) .includeNotifyingNodes(nodesToCheck) .checkAllSpaces(checkAllSpaces) .checkSpaceSubset(checkSpaces); - wait(swc, new WaitTask.StateResender(data.getFleetController()), timeoutMS); + wait(swc, new WaitTask.StateResender(data.getFleetController()), timeout); return swc.getCurrentState(); } -- cgit v1.2.3