aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/RpcServerTest.java
blob: 41d7465b602c741a7353390f046cfb239310d146 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
// 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.ErrorCode;
import com.yahoo.jrt.Int32Value;
import com.yahoo.jrt.Request;
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.vdslib.distribution.ConfiguredNode;
import com.yahoo.vdslib.distribution.Distribution;
import com.yahoo.vdslib.state.ClusterState;
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 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.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author humbe
 */
public class RpcServerTest extends FleetControllerTest {

    public static Logger log = Logger.getLogger(RpcServerTest.class.getName());

    private Supervisor supervisor;

    public void tearDown() throws Exception {
        if (supervisor != null) {
            supervisor.transport().shutdown().join();
        }
        super.tearDown();
    }

    @Test
    void testRebinding() throws Exception {
        startingTest("RpcServerTest::testRebinding");
        Slobrok slobrok = new Slobrok();
        String[] slobrokConnectionSpecs = new String[1];
        slobrokConnectionSpecs[0] = "tcp/localhost:" + slobrok.port();
        RpcServer server = new RpcServer(timer, new Object(), "mycluster", 0, new BackOff());
        server.setSlobrokConnectionSpecs(slobrokConnectionSpecs, 18347);
        int portUsed = server.getPort();
        server.setSlobrokConnectionSpecs(slobrokConnectionSpecs, portUsed);
        server.disconnect();
        server.disconnect();
        server.connect();
        server.connect();
        server.disconnect();
        server.connect();
        server.shutdown();
        slobrok.stop();
    }

    /**
     * For some reason, the first test trying to set up a stable system here occasionally times out.
     * The theory is that some test run before it does something that is not cleaned up in time.
     * Trying to add a test that should provoke the failure, but not fail due to it to see if we can verify that
     * assumption.
     *
     * (testRebinding() does not seem to be that test. Tests in StateChangeTest that runs before this test tests very
     * similar things, so strange if it should be from them too though. Maybe last test there.
     */
    @Test
    void testFailOccasionallyAndIgnoreToSeeIfOtherTestsThenWork() {
        try {
            startingTest("RpcServerTest::testFailOccasionallyAndIgnoreToSeeIfOtherTestsThenWork");
            setUpFleetController(true, defaultOptions("mycluster"));
            setUpVdsNodes(true, new DummyVdsNodeOptions());
            waitForStableSystem();
        } catch (Throwable t) {
        }
    }

    @Test
    void testGetSystemState() throws Exception {
        LogFormatter.initializeLogging();
        startingTest("RpcServerTest::testGetSystemState");
        FleetControllerOptions options = defaultOptions("mycluster");
        setUpFleetController(true, options);
        setUpVdsNodes(true, new DummyVdsNodeOptions());
        waitForStableSystem();

        assertTrue(nodes.get(0).isDistributor());
        log.log(Level.INFO, "Disconnecting distributor 0. Waiting for state to reflect change.");
        nodes.get(0).disconnect();
        nodes.get(19).disconnect();
        fleetController.waitForNodesInSlobrok(9, 9, timeoutMS);
        timer.advanceTime(options.nodeStateRequestTimeoutMS + options.maxSlobrokDisconnectGracePeriod);

        wait(new WaitCondition.StateWait(fleetController, fleetController.getMonitor()) {
            @Override
            public String isConditionMet() {
                if (currentState == null) {
                    return "No cluster state defined yet";
                }
                NodeState distState = currentState.getNodeState(new Node(NodeType.DISTRIBUTOR, 0));
                if (distState.getState() != State.DOWN) {
                    return "Distributor not detected down yet: " + currentState.toString();
                }
                NodeState storState = currentState.getNodeState(new Node(NodeType.STORAGE, 9));
                if (!storState.getState().oneOf("md")) {
                    return "Storage node not detected down yet: " + currentState.toString();
                }
                return null;
            }
        }, null, timeoutMS);

        int rpcPort = fleetController.getRpcPort();
        supervisor = new Supervisor(new Transport());
        Target connection = supervisor.connect(new Spec("localhost", rpcPort));
        assertTrue(connection.isValid());

        Request req = new Request("getSystemState");
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ss"), req.toString());
        String systemState = req.returnValues().get(1).asString();
        ClusterState retrievedClusterState = new ClusterState(systemState);
        assertEquals(State.DOWN, retrievedClusterState.getNodeState(new Node(NodeType.DISTRIBUTOR, 0)).getState(), systemState);
        assertTrue(retrievedClusterState.getNodeState(new Node(NodeType.STORAGE, 9)).getState().oneOf("md"), systemState);
    }

    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());

        Node node = new Node(nodeType, nodeIndex);
        NodeState newNodeState = new NodeState(nodeType, newState);

        Request req = new Request("setNodeState");
        req.parameters().add(new StringValue("storage/cluster.mycluster/" + node.getType().toString() + "/" + node.getIndex()));
        req.parameters().add(new StringValue(newNodeState.serialize(true)));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("s"), req.toString());
    }

    @Test
    void testGetNodeState() throws Exception {
        startingTest("RpcServerTest::testGetNodeState");
        Set<ConfiguredNode> configuredNodes = new TreeSet<>();
        for (int i = 0; i < 10; i++)
            configuredNodes.add(new ConfiguredNode(i, false));
        FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
        options.minRatioOfStorageNodesUp = 0;
        options.maxInitProgressTime = 30000;
        options.stableStateTimePeriod = 60000;
        setUpFleetController(true, options);
        setUpVdsNodes(true, new DummyVdsNodeOptions());
        waitForStableSystem();

        setWantedNodeState(State.DOWN, NodeType.DISTRIBUTOR, 2);
        setWantedNodeState(State.RETIRED, NodeType.STORAGE, 2);
        setWantedNodeState(State.MAINTENANCE, NodeType.STORAGE, 7);
        waitForCompleteCycle();
        timer.advanceTime(1000000);
        waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
        nodes.get(0).disconnect();
        nodes.get(3).disconnect();
        nodes.get(5).disconnect();
        waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:m .2.s:m .7.s:m");
        timer.advanceTime(1000000);
        waitForState("version:\\d+ distributor:10 .0.s:d .2.s:d storage:10 .1.s:d .2.s:d .7.s:m");
        timer.advanceTime(1000000);
        waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
        nodes.get(3).setNodeState(new NodeState(nodes.get(3).getType(), State.INITIALIZING).setInitProgress(0.2f));
        nodes.get(3).connect();
        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());

        Request req = new Request("getNodeState");
        req.parameters().add(new StringValue("distributor"));
        req.parameters().add(new Int32Value(0));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
        NodeState reported = NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(1).asString());
        assertTrue(reported.getState().oneOf("d-"), req.returnValues().get(1).asString());
        assertEquals("", req.returnValues().get(2).asString());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("distributor"));
        req.parameters().add(new Int32Value(2));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(0).asString()).getState());
        assertEquals("t:946080000", req.returnValues().get(1).asString());
        assertEquals(State.DOWN, NodeState.deserialize(NodeType.DISTRIBUTOR, req.returnValues().get(2).asString()).getState());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("distributor"));
        req.parameters().add(new Int32Value(4));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals("", req.returnValues().get(0).asString());
        assertEquals("t:946080000", req.returnValues().get(1).asString());
        assertEquals("", req.returnValues().get(2).asString());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("distributor"));
        req.parameters().add(new Int32Value(15));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.METHOD_FAILED, req.errorCode(), req.toString());
        assertEquals("No node distributor.15 exists in cluster mycluster", req.errorMessage());
        assertFalse(req.checkReturnTypes("ssss"), req.toString());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("storage"));
        req.parameters().add(new Int32Value(1));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals("s:i i:0.2", req.returnValues().get(0).asString());
        assertEquals("s:i i:0.2", req.returnValues().get(1).asString());
        assertEquals("", req.returnValues().get(2).asString());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("storage"));
        req.parameters().add(new Int32Value(2));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals(State.DOWN, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
        reported = NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(1).asString());
        assertTrue(reported.getState().oneOf("d-"), req.returnValues().get(1).asString());
        assertEquals(State.RETIRED, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("storage"));
        req.parameters().add(new Int32Value(5));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals("", req.returnValues().get(0).asString());
        assertEquals("t:946080000", req.returnValues().get(1).asString());
        assertEquals("", req.returnValues().get(2).asString());

        req = new Request("getNodeState");
        req.parameters().add(new StringValue("storage"));
        req.parameters().add(new Int32Value(7));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("ssss"), req.toString());
        assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(0).asString()).getState());
        assertEquals("t:946080000", req.returnValues().get(1).asString());
        assertEquals(State.MAINTENANCE, NodeState.deserialize(NodeType.STORAGE, req.returnValues().get(2).asString()).getState());
    }

    @Test
    void testGetNodeStateWithConfiguredRetired() throws Exception {
        startingTest("RpcServerTest::testGetNodeStateWithConfiguredRetired");
        List<ConfiguredNode> configuredNodes = new ArrayList<>();
        for (int i = 0; i < 4; i++)
            configuredNodes.add(new ConfiguredNode(i, false));
        configuredNodes.add(new ConfiguredNode(4, true)); // Last node is configured retired
        FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
        options.minRatioOfStorageNodesUp = 0;
        options.maxInitProgressTime = 30000;
        options.stableStateTimePeriod = 60000;
        setUpFleetController(true, options);
        setUpVdsNodes(true, new DummyVdsNodeOptions(), false, configuredNodes);
        waitForState("version:\\d+ distributor:5 storage:5 .4.s:r");

        setWantedNodeState(State.DOWN, NodeType.DISTRIBUTOR, 2);
        setWantedNodeState(State.RETIRED, NodeType.STORAGE, 2);
        setWantedNodeState(State.MAINTENANCE, NodeType.STORAGE, 3);
        waitForCompleteCycle();
        timer.advanceTime(1000000);
        waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
        nodes.get(0).disconnect();
        nodes.get(3).disconnect();
        nodes.get(5).disconnect();
        waitForState("version:\\d+ distributor:5 .0.s:d .2.s:d storage:5 .1.s:m .2.s:m .3.s:m .4.s:r");
        timer.advanceTime(1000000);
        waitForState("version:\\d+ distributor:5 .0.s:d .2.s:d storage:5 .1.s:d .2.s:d .3.s:m .4.s:r");
        timer.advanceTime(1000000);
        waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
        nodes.get(3).setNodeState(new NodeState(nodes.get(3).getType(), State.INITIALIZING).setInitProgress(0.2f));
        nodes.get(3).connect();
        waitForState("version:\\d+ distributor:5 .0.s:d .2.s:d storage:5 .1.s:i .1.i:0.2 .2.s:d .3.s:m .4.s:r");
    }

    @Test
    void testGetNodeStateWithConfigurationChangeToRetiredWhileNodeDown() throws Exception {
        startingTest("RpcServerTest::testGetNodeStateWithConfigurationChangeToRetiredWhileNodeDown");

        { // Configuration: 5 nodes, all normal
            List<ConfiguredNode> configuredNodes = new ArrayList<>();
            for (int i = 0; i < 5; i++)
                configuredNodes.add(new ConfiguredNode(i, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.maxInitProgressTime = 30000;
            options.stableStateTimePeriod = 60000;
            setUpFleetController(true, options);
            setUpVdsNodes(true, new DummyVdsNodeOptions(), false, configuredNodes);
            waitForState("version:\\d+ distributor:5 storage:5");
        }

        { // 2 first storage nodes go down (0 and 2 are the corresponding distributors)
            waitForCompleteCycle();
            timer.advanceTime(1000000);
            waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
            nodes.get(1).disconnectImmediately();
            nodes.get(3).disconnectImmediately();
            waitForState("version:\\d+ distributor:5 storage:5 .0.s:m .1.s:m");
        }

        { // Configuration change: Add 2 new nodes and retire the 5 existing ones
            setUpVdsNodes(true, new DummyVdsNodeOptions(), false, 2);
            Set<ConfiguredNode> configuredNodes = new TreeSet<>();
            for (int i = 0; i < 5; i++)
                configuredNodes.add(new ConfiguredNode(i, true));
            configuredNodes.add(new ConfiguredNode(5, false));
            configuredNodes.add(new ConfiguredNode(6, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.slobrokConnectionSpecs = this.options.slobrokConnectionSpecs;
            this.options.maxInitProgressTime = 30000;
            this.options.stableStateTimePeriod = 60000;
            fleetController.updateOptions(options);
            waitForState("version:\\d+ distributor:7 storage:7 .0.s:m .1.s:m .2.s:r .3.s:r .4.s:r");
        }

        { // 2 storage nodes down come up, should go to state retired
            waitForCompleteCycle();
            timer.advanceTime(1000000);
            waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
            nodes.get(1).connect();
            nodes.get(3).connect();
            waitForState("version:\\d+ distributor:7 storage:7 .0.s:r .1.s:r .2.s:r .3.s:r .4.s:r");
        }

        { // 2 first storage nodes go down again
            waitForCompleteCycle();
            timer.advanceTime(1000000);
            waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
            nodes.get(1).disconnectImmediately();
            nodes.get(3).disconnectImmediately();
            waitForState("version:\\d+ distributor:7 storage:7 .0.s:m .1.s:m .2.s:r .3.s:r .4.s:r");
        }

        { // Configuration change: Unretire the nodes
            Set<ConfiguredNode> configuredNodes = new TreeSet<>();
            for (int i = 0; i < 7; i++)
                configuredNodes.add(new ConfiguredNode(i, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.slobrokConnectionSpecs = this.options.slobrokConnectionSpecs;
            this.options.maxInitProgressTime = 30000;
            this.options.stableStateTimePeriod = 60000;
            fleetController.updateOptions(options);
            waitForState("version:\\d+ distributor:7 storage:7 .0.s:m .1.s:m");
        }

        { // 2 storage nodes down come up, should go to state up
            waitForCompleteCycle();
            timer.advanceTime(1000000);
            waitForCompleteCycle(); // Make fleet controller notice that time has changed before any disconnects
            nodes.get(1).connect();
            nodes.get(3).connect();
            waitForState("version:\\d+ distributor:7 storage:7");
        }

    }

    @Test
    void testGetNodeStateWithConfigurationChangeToRetired() throws Exception {
        startingTest("RpcServerTest::testGetNodeStateWithConfigurationChangeToRetired");

        { // Configuration: 5 nodes, all normal
            List<ConfiguredNode> configuredNodes = new ArrayList<>();
            for (int i = 0; i < 5; i++)
                configuredNodes.add(new ConfiguredNode(i, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.maxInitProgressTime = 30000;
            options.stableStateTimePeriod = 60000;
            setUpFleetController(true, options);
            setUpVdsNodes(true, new DummyVdsNodeOptions(), false, configuredNodes);
            waitForState("version:\\d+ distributor:5 storage:5");
        }

        { // Reconfigure with the same state
            Set<ConfiguredNode> configuredNodes = new TreeSet<>();
            for (int i = 0; i < 5; i++)
                configuredNodes.add(new ConfiguredNode(i, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.slobrokConnectionSpecs = this.options.slobrokConnectionSpecs;
            this.options.maxInitProgressTime = 30000;
            this.options.stableStateTimePeriod = 60000;
            fleetController.updateOptions(options);
            waitForState("version:\\d+ distributor:5 storage:5");
        }

        { // Configuration change: Add 2 new nodes and retire the 5 existing ones
            setUpVdsNodes(true, new DummyVdsNodeOptions(), false, 2);
            Set<ConfiguredNode> configuredNodes = new TreeSet<>();
            for (int i = 0; i < 5; i++)
                configuredNodes.add(new ConfiguredNode(i, true));
            configuredNodes.add(new ConfiguredNode(5, false));
            configuredNodes.add(new ConfiguredNode(6, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.slobrokConnectionSpecs = this.options.slobrokConnectionSpecs;
            this.options.maxInitProgressTime = 30000;
            this.options.stableStateTimePeriod = 60000;
            fleetController.updateOptions(options);
            waitForState("version:\\d+ distributor:7 storage:7 .0.s:r .1.s:r .2.s:r .3.s:r .4.s:r");
        }

        { // Reconfigure with the same state
            Set<ConfiguredNode> configuredNodes = new TreeSet<>();
            for (int i = 0; i < 5; i++)
                configuredNodes.add(new ConfiguredNode(i, true));
            configuredNodes.add(new ConfiguredNode(5, false));
            configuredNodes.add(new ConfiguredNode(6, false));
            FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
            options.slobrokConnectionSpecs = this.options.slobrokConnectionSpecs;
            this.options.maxInitProgressTime = 30000;
            this.options.stableStateTimePeriod = 60000;
            fleetController.updateOptions(options);
            waitForState("version:\\d+ distributor:7 storage:7 .0.s:r .1.s:r .2.s:r .3.s:r .4.s:r");
        }

        { // Configuration change: Remove the previously retired nodes
            /*
        TODO: Verify current result: version:23 distributor:7 .0.s:d .1.s:d .2.s:d .3.s:d .4.s:d storage:7 .0.s:m .1.s:m .2.s:m .3.s:m .4.s:m
        TODO: Make this work without stopping/disconnecting (see StateChangeHandler.setNodes
        Set<ConfiguredNode> configuredNodes = new TreeSet<>();
        configuredNodes.add(new ConfiguredNode(5, false));
        configuredNodes.add(new ConfiguredNode(6, false));
        FleetControllerOptions options = new FleetControllerOptions("mycluster", configuredNodes);
        options.slobrokConnectionSpecs = this.options.slobrokConnectionSpecs;
        this.options.maxInitProgressTimeMs = 30000;
        this.options.stableStateTimePeriod = 60000;
        fleetController.updateOptions(options, 0);
        for (int i = 0; i < 5*2; i++) {
            nodes.get(i).disconnectSlobrok();
            nodes.get(i).disconnect();
        }
        waitForState("version:\\d+ distributor:7 storage:7 .0.s:d .1.s:d .2.s:d .3.s:d .4.s:d");
        */
        }
    }

    @Test
    void testSetNodeState() throws Exception {
        startingTest("RpcServerTest::testSetNodeState");
        Set<Integer> nodeIndexes = new TreeSet<>(List.of(4, 6, 9, 10, 14, 16, 21, 22, 23, 25));
        Set<ConfiguredNode> configuredNodes = nodeIndexes.stream().map(i -> new ConfiguredNode(i, false)).collect(Collectors.toSet());
        FleetControllerOptions options = defaultOptions("mycluster", configuredNodes);
        //options.setStorageDistribution(new Distribution(getDistConfig(nodeIndexes)));
        setUpFleetController(true, options);
        setUpVdsNodes(true, new DummyVdsNodeOptions(), false, nodeIndexes);
        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());

        Request req = new Request("setNodeState");
        req.parameters().add(new StringValue("storage/cluster.mycluster/storage/14"));
        req.parameters().add(new StringValue("s:r"));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("s"), req.toString());

        waitForState("version:\\d+ distributor:26 .* storage:26 .* .14.s:r .*");

        req = new Request("setNodeState");
        req.parameters().add(new StringValue("storage/cluster.mycluster/storage/16"));
        req.parameters().add(new StringValue("s:m"));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());
        assertTrue(req.checkReturnTypes("s"), req.toString());

        waitForState("version:\\d+ distributor:26 .* storage:26 .* .14.s:r.* .16.s:m .*");
        nodes.get(5 * 2 + 1).disconnect();
        waitForCompleteCycle();
        timer.advanceTime(100000000);
        waitForCompleteCycle();
        assertEquals(State.MAINTENANCE, fleetController.getSystemState().getNodeState(new Node(NodeType.STORAGE, 16)).getState());

        nodes.get(4 * 2 + 1).disconnect();
        waitForState("version:\\d+ distributor:26 .* storage:26 .* .14.s:m.* .16.s:m .*");
        nodes.get(4 * 2 + 1).connect();
        timer.advanceTime(100000000);
        // Might need to pass more actual time while waiting below?
        waitForState("version:\\d+ distributor:26 .* storage:26 .* .14.s:r.* .16.s:m .*");
    }

    @Test
    void testSetNodeStateOutOfRange() throws Exception {
        startingTest("RpcServerTest::testSetNodeStateOutOfRange");
        FleetControllerOptions options = defaultOptions("mycluster");
        options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(2, 10)));
        setUpFleetController(true, options);
        setUpVdsNodes(true, new DummyVdsNodeOptions());
        waitForStableSystem();

        int rpcPort = fleetController.getRpcPort();
        supervisor = new Supervisor(new Transport());
        Target connection = supervisor.connect(new Spec("localhost", rpcPort));
        assertTrue(connection.isValid());

        Request req = new Request("setNodeState");
        req.parameters().add(new StringValue("storage/cluster.mycluster/storage/10"));
        req.parameters().add(new StringValue("s:m"));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.METHOD_FAILED, req.errorCode(), req.toString());
        assertEquals("Cannot set wanted state of node storage.10. Index does not correspond to a configured node.", req.errorMessage(), req.toString());

        req = new Request("setNodeState");
        req.parameters().add(new StringValue("storage/cluster.mycluster/distributor/10"));
        req.parameters().add(new StringValue("s:m"));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.METHOD_FAILED, req.errorCode(), req.toString());
        assertEquals("Cannot set wanted state of node distributor.10. Index does not correspond to a configured node.", req.errorMessage(), req.toString());

        req = new Request("setNodeState");
        req.parameters().add(new StringValue("storage/cluster.mycluster/storage/9"));
        req.parameters().add(new StringValue("s:m"));
        connection.invokeSync(req, timeoutS);
        assertEquals(ErrorCode.NONE, req.errorCode(), req.toString());

        waitForState("version:\\d+ distributor:10 storage:10 .9.s:m");
    }

    @Test
    void testGetMaster() throws Exception {
        startingTest("RpcServerTest::testGetMaster");
        FleetControllerOptions options = defaultOptions("mycluster");
        options.setStorageDistribution(new Distribution(Distribution.getDefaultDistributionConfig(2, 10)));
        setUpFleetController(true, options);
        setUpVdsNodes(true, new DummyVdsNodeOptions());
        waitForStableSystem();

        int rpcPort = fleetController.getRpcPort();
        supervisor = new Supervisor(new Transport());
        Target connection = supervisor.connect(new Spec("localhost", rpcPort));
        assertTrue(connection.isValid());

        Request req = new Request("getMaster");
        connection.invokeSync(req, timeoutS);
        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
    }

    @Test
    void testGetNodeList() throws Exception {
        startingTest("RpcServerTest::testGetNodeList");
        setUpFleetController(true, defaultOptions("mycluster", 5));
        final int nodeCount = 5;
        setUpVdsNodes(true, new DummyVdsNodeOptions(), false, nodeCount);
        waitForStableSystem();

        assertTrue(nodes.get(0).isDistributor());
        nodes.get(0).disconnect();
        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());

        // Possibly do request multiple times if we haven't lost slobrok contact first times yet.
        for (int j = 0; j <= nodeCount; ++j) {
            Request req = new Request("getNodeList");
            connection.invokeSync(req, timeoutS);
            assertEquals(ErrorCode.NONE, req.errorCode(), req.errorMessage());
            assertTrue(req.checkReturnTypes("SS"), req.toString());
            String[] slobrok = req.returnValues().get(0).asStringArray().clone();
            String[] rpc = req.returnValues().get(1).asStringArray().clone();

            assertEquals(2 * nodeCount, slobrok.length);
            assertEquals(2 * nodeCount, rpc.length);

            // Verify that we can connect to all addresses returned.
            for (int i = 0; i < 2 * nodeCount; ++i) {
                if (slobrok[i].equals("storage/cluster.mycluster/distributor/0")) {
                    if (i < nodeCount && !"".equals(rpc[i])) {
                        continue;
                    }
                    assertEquals("", rpc[i], slobrok[i]);
                    continue;
                }
                assertNotEquals("", rpc[i]);
                Request req2 = new Request("getnodestate2");
                req2.parameters().add(new StringValue("unknown"));
                Target connection2 = supervisor.connect(new Spec(rpc[i]));
                connection2.invokeSync(req2, timeoutS);
                assertEquals(ErrorCode.NONE, req.errorCode(), req2.toString());
            }
            break;
        }
    }

}