File: test_bootstrap_clusterset.cc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (1088 lines) | stat: -rw-r--r-- 47,264 bytes parent folder | download
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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
/*
  Copyright (c) 2021, 2025, Oracle and/or its affiliates.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License, version 2.0,
  as published by the Free Software Foundation.

  This program is designed to work with certain software (including
  but not limited to OpenSSL) that is licensed under separate terms,
  as designated in a particular file or component or in included license
  documentation.  The authors of MySQL hereby grant you an additional
  permission to link the program and your derivative works with the
  separately licensed software that they have either included with
  the program or referenced in the documentation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <chrono>

#include <gmock/gmock.h>

#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
#include "my_rapidjson_size_t.h"
#endif
#include <rapidjson/document.h>
#include <rapidjson/writer.h>

#include "dim.h"
#include "harness_assert.h"
#include "keyring/keyring_manager.h"
#include "mock_server_rest_client.h"
#include "mock_server_testutils.h"
#include "mysql/harness/string_utils.h"  // mysql_harness::split_string
#include "mysqlrouter/cluster_metadata.h"
#include "random_generator.h"
#include "rest_api_testutils.h"
#include "router_component_clusterset.h"
#include "router_component_test.h"
#include "router_component_testutils.h"
#include "router_config.h"  // MYSQL_ROUTER_VERSION
#include "socket_operations.h"
#include "tcp_port_pool.h"

using namespace std::chrono_literals;
using namespace std::string_literals;
using mysqlrouter::ClusterType;

// for the test with no param
class RouterClusterSetBootstrapTest : public RouterComponentClusterSetTest {
 protected:
  ProcessWrapper &launch_router_for_bootstrap(
      std::vector<std::string> params, int expected_exit_code = EXIT_SUCCESS,
      const bool disable_rest = true, const bool add_report_host = true) {
    if (disable_rest) params.push_back("--disable-rest");
    if (add_report_host) params.push_back("--report-host=dont.query.dns");

    return ProcessManager::launch_router(
        params, expected_exit_code, /*catch_stderr=*/true, /*with_sudo=*/false,
        /*wait_for_notify_ready=*/std::chrono::seconds(-1),
        RouterComponentBootstrapTest::kBootstrapOutputResponder);
  }

  using NodeAddress = std::pair<std::string, uint16_t>;
  TempDirectory bootstrap_directory;
  uint64_t view_id{1};
};

struct TargetClusterTestParams {
  // which cluster from the CS should be used as a param for --bootstrap
  unsigned bootstrap_cluster_id;
  // which node from the selected cluster should be used as a param for
  // --bootstrap
  unsigned bootstrap_node_id;
  // what should be the value for --conf-target-cluster (if empty do not use
  // this parameter in the bootstrap command)
  std::string target_cluster_param;
  // what should be the value for --conf-target-cluster-by-name (if empty do not
  // use this parameter in the bootstrap command)
  std::string target_cluster_by_name_param;

  // id of the target Cluster within ClusterSet
  unsigned target_cluster_id;

  // what is the expected value of the target_cluster in the configuration file
  // created by the bootstrap
  std::string expected_target_cluster;

  // vector of strings expected on the console after the bootstrap
  std::vector<std::string> expected_output_strings;
};

class ClusterSetBootstrapTargetClusterTest
    : public RouterClusterSetBootstrapTest,
      public ::testing::WithParamInterface<TargetClusterTestParams> {};

TEST_P(ClusterSetBootstrapTargetClusterTest, ClusterSetBootstrapTargetCluster) {
  const auto target_cluster_id = GetParam().target_cluster_id;
  const std::string expected_target_cluster =
      GetParam().expected_target_cluster;

  create_clusterset(view_id, target_cluster_id, /*primary_cluster_id*/ 0,
                    "bootstrap_clusterset.js", "", expected_target_cluster);
  const unsigned bootstrap_cluster_id = GetParam().bootstrap_cluster_id;
  const unsigned bootstrap_node_id = GetParam().bootstrap_node_id;
  const std::string target_cluster_param =
      GetParam().target_cluster_param.empty()
          ? ""
          : "--conf-target-cluster=" + GetParam().target_cluster_param;

  const std::string target_cluster_by_name_param =
      GetParam().target_cluster_by_name_param.empty()
          ? ""
          : "--conf-target-cluster-by-name=" +
                GetParam().target_cluster_by_name_param;
  const auto &expected_output_strings = GetParam().expected_output_strings;

  std::vector<std::string> bootstrap_params = {
      "--bootstrap=127.0.0.1:" +
          std::to_string(clusterset_data_.clusters[bootstrap_cluster_id]
                             .nodes[bootstrap_node_id]
                             .classic_port),
      "-d", bootstrap_directory.name()};

  if (!target_cluster_param.empty()) {
    bootstrap_params.push_back(target_cluster_param);
  }
  if (!target_cluster_by_name_param.empty()) {
    bootstrap_params.push_back(target_cluster_by_name_param);
  }

  auto &router = launch_router_for_bootstrap(bootstrap_params, EXIT_SUCCESS);

  check_exit_code(router, EXIT_SUCCESS);

  const std::string conf_file_path =
      bootstrap_directory.name() + "/mysqlrouter.conf";

  const std::string state_file_path =
      bootstrap_directory.name() + "/data/state.json";

  // check the state file that was produced
  // [@FR12]
  check_state_file(state_file_path, ClusterType::GR_CS, clusterset_data_.uuid,
                   clusterset_data_.get_all_nodes_classic_ports(), view_id);

  const std::string config_file_str = get_file_output(conf_file_path);

  // [@FR2]
  EXPECT_TRUE(pattern_found(config_file_str, "cluster_type=gr"))
      << config_file_str;
  EXPECT_TRUE(pattern_found(config_file_str, "ttl=5")) << config_file_str;

  const std::string router_console_output = router.get_full_output();
  for (const auto &expected_output_string : expected_output_strings) {
    EXPECT_TRUE(pattern_found(router_console_output, expected_output_string))
        << router_console_output;
  }
}

INSTANTIATE_TEST_SUITE_P(
    ClusterSetBootstrapTargetCluster, ClusterSetBootstrapTargetClusterTest,
    ::testing::Values(
        // we bootstrap against the consecutive nodes (0, 1, 2) of the first
        // cluster which is the PRIMARY cluster; both "--conf-target-cluster"
        // and "--conf-target-cluster-by-name" parameters are empty (not used)
        // so per requirement we are expected to configure
        // empty target cluster
        // [@FR1]
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 1,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 2,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        // we bootstrap against the nodes of the other clusters which is
        // are REPLICA clusters; both "--conf-target-cluster" and
        // "--conf-target-cluster-by-name" parameters are empty (not used) so
        // per requirement we are expected to configure empty target cluster
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 1,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 1,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 1,
                                /*bootstrap_node_id*/ 1,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 1,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 1,
                                /*bootstrap_node_id*/ 2,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 1,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        // second Replica Cluster, nodes 0-2
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 2,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 2,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 2,
                                /*bootstrap_node_id*/ 1,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 2,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 2,
                                /*bootstrap_node_id*/ 2,
                                /*--conf-target-cluster*/ "",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 2,
                                /*expected_target_cluster*/ "",
                                /*expected_output_strings*/ {}},
        // we bootstrap against the nodes of the first Cluster which is the
        // PRIMARY Cluster; the "--conf-target-cluster=current" so
        // per requirement we are expected to configure
        // target_cluster=UUID-OF-PRIMARY-CLUSTER
        // NOTE: since we are using "current" on the Primary cluster we expect
        // the warning on the console
        // NOTE: also checks that the "current" option is case insensitive
        // [@FR3.1.1] [@FR3.3] [@TS_R2_1/1]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "current",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/
            {"WARNING: Option --conf-target-cluster=current was used to "
             "bootstrap against the Primary Cluster. Note that the Router will "
             "not follow the new Primary Cluster in case of the Primary "
             "Cluster change in the ClusterSet"}},
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "Current",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/
            {"WARNING: Option --conf-target-cluster=current was used to "
             "bootstrap against the Primary Cluster. Note that the Router will "
             "not follow the new Primary Cluster in case of the Primary "
             "Cluster change in the ClusterSet"}},
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "CURRENT",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/
            {"WARNING: Option --conf-target-cluster=current was used to "
             "bootstrap against the Primary Cluster. Note that the Router will "
             "not follow the new Primary Cluster in case of the Primary "
             "Cluster change in the ClusterSet"}},
        // [@TS_R2_1/2]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 1,
            /*--conf-target-cluster*/ "currenT",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/
            {"WARNING: Option --conf-target-cluster=current was used to "
             "bootstrap against the Primary Cluster. Note that the Router will "
             "not follow the new Primary Cluster in case of the Primary "
             "Cluster change in the ClusterSet"}},

        // we bootstrap against the nodes of the second Cluster which is the
        // REPLICA Cluster; the "--conf-target-cluster=current" so
        // per requirement we are expected to configure
        // target_cluster=UUID-OF-REPLICA-CLUSTER
        // NOTE: since this is not the PRIMARY cluster we do not expect the
        // warning now NOTE: also checks that the "current" option is case
        // insensitive
        // [@FR3.2] [@TS_R2_1/3]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "current",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 1,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g2",
            /*expected_output_strings*/
            {""}},
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "Current",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 1,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g2",
            /*expected_output_strings*/
            {""}},
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "CURRENT",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 1,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g2",
            /*expected_output_strings*/
            {""}},
        // [@TS_R2_1/4]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 1,
            /*--conf-target-cluster*/ "current",
            /*--conf-target-cluster-by-name*/ "",
            /*target_cluster_id*/ 1,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g2",
            /*expected_output_strings*/
            {""}},

        // we bootstrap against various ClusterSet nodes using
        // "--conf-target-cluster=primary" so we expect target_cluster=primary
        // NOTE: also checks that the "current" option is case insensitive
        // [@FR3.2] [@FR3.3] [@TS_R3_1/1]
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "primary",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "Primary",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "PRIMARY",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        // [@TS_R3_1/2]
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 0,
                                /*bootstrap_node_id*/ 2,
                                /*--conf-target-cluster*/ "primarY",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        // [@TS_R3_1/3]
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 1,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "primary",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        // [@TS_R3_1/4]
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 2,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "primary",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 2,
                                /*bootstrap_node_id*/ 1,
                                /*--conf-target-cluster*/ "Primary",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},
        TargetClusterTestParams{/*bootstrap_cluster_id*/ 2,
                                /*bootstrap_node_id*/ 0,
                                /*--conf-target-cluster*/ "PRIMARY",
                                /*--conf-target-cluster-by-name*/ "",
                                /*target_cluster_id*/ 0,
                                /*expected_target_cluster*/ "primary",
                                /*expected_output_strings*/
                                {""}},

        // we bootstrap against various ClusterSet nodes using
        // "--conf-target-cluster-name=<CLUSTER-NAME>" so we expect
        // target_cluster=<CLUSTER_GR_UUID>
        // [@FR3.4]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            /*--conf-target-cluster*/ "",
            /*--conf-target-cluster-by-name*/ "cluster-name-1",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/ {}},
        // [@TS_R5_1/2]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 1,
            /*--conf-target-cluster*/ "",
            /*--conf-target-cluster-by-name*/ "cluster-name-1",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/ {}},
        // [@TS_R5_1/2]
        TargetClusterTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 1,
            /*--conf-target-cluster*/ "",
            /*--conf-target-cluster-by-name*/ "cluster-name-1",
            /*target_cluster_id*/ 0,
            /*expected_target_cluster*/ "00000000-0000-0000-0000-0000000000g1",
            /*expected_output_strings*/ {}}));

struct ClusterSetUseGrNotificationTestParams {
  std::vector<std::string> bootstrap_params;
  std::vector<std::string> expected_config_lines;
};

class ClusterSetConfUseGrNotificationParamTest
    : public RouterClusterSetBootstrapTest,
      public ::testing::WithParamInterface<
          ClusterSetUseGrNotificationTestParams> {};

/**
 * @test
 *       verify that using various values for --conf-use-gr-notifications
 * creates proper config file entries.
 */
TEST_P(ClusterSetConfUseGrNotificationParamTest,
       ClusterSetConfUseGrNotificationParam) {
  TempDirectory bootstrap_directory;
  create_clusterset(view_id, /*target_cluster_id*/ 0, /*primary_cluster_id*/ 0,
                    "bootstrap_clusterset.js");

  std::vector<std::string> bootstrap_params = {
      "--bootstrap=127.0.0.1:" +
          std::to_string(clusterset_data_.clusters[0].nodes[0].classic_port),
      "-d", bootstrap_directory.name()};

  bootstrap_params.insert(bootstrap_params.end(),
                          GetParam().bootstrap_params.begin(),
                          GetParam().bootstrap_params.end());

  // launch the router in bootstrap mode
  auto &router = launch_router_for_bootstrap(bootstrap_params);

  check_exit_code(router, EXIT_SUCCESS);

  const std::string state_file_path =
      bootstrap_directory.name() + "/data/state.json";

  // check the state file that was produced
  // [@FR12]
  check_state_file(state_file_path, ClusterType::GR_CS, clusterset_data_.uuid,
                   clusterset_data_.get_all_nodes_classic_ports(), view_id);

  // check if the expected config options were added to the configuration file
  const auto conf_file_content =
      get_file_output(bootstrap_directory.name() + "/mysqlrouter.conf");
  for (const auto &expected_config_line : GetParam().expected_config_lines) {
    EXPECT_THAT(mysql_harness::split_string(conf_file_content, '\n'),
                ::testing::Contains(expected_config_line));
  }
}

INSTANTIATE_TEST_SUITE_P(
    ClusterSetConfUseGrNotificationParam,
    ClusterSetConfUseGrNotificationParamTest,
    ::testing::Values(
        // 0) --conf-use-gr-notifications with no param: GR Notifications should
        // be enabled and TTL=5 seconds
        // [@FR5]
        // [@FR5.2.3]
        ClusterSetUseGrNotificationTestParams{
            {"--conf-use-gr-notifications"},
            {"use_gr_notifications=1", "ttl=5"}},
        // 1) --conf-use-gr-notifications=1: GR Notifications should be enabled
        // and TTL=5 seconds
        // [@FR5]
        ClusterSetUseGrNotificationTestParams{
            {"--conf-use-gr-notifications=1"},
            {"use_gr_notifications=1", "ttl=5"}},
        // 2) no --conf-use-gr-notifications param: GR Notifications should be
        // enabled and TTL=5 seconds
        // [@FR5]
        // [@FR5.1]
        // [@FR5.2]
        // [@FR5.2.2]
        ClusterSetUseGrNotificationTestParams{
            {}, {"use_gr_notifications=1", "ttl=5"}},
        // 3) --conf-use-gr-notification=0: GR Notifications should be disabled
        // and TTL=5 seconds
        // [@FR5.2]
        // [@FR5.2.1]
        ClusterSetUseGrNotificationTestParams{
            {"--conf-use-gr-notifications=0"},
            {"use_gr_notifications=0", "ttl=5"}}));

struct BootstrapParametersErrorTestParams {
  // which cluster from the CS should be used as a param for --bootstrap
  unsigned bootstrap_cluster_id;
  // which node from the selected cluster should be used as a param for
  // --bootstrap
  unsigned bootstrap_node_id;

  std::vector<std::string> bootstrap_params;
  std::string expected_error;
};

class ClusterSetBootstrapParamsErrorTest
    : public RouterClusterSetBootstrapTest,
      public ::testing::WithParamInterface<BootstrapParametersErrorTestParams> {
};

/**
 * @test
 *       verify the proper errors are reported for invalid --conf-target-cluster
 * and --conf-target-cluster-by-name uses
 */
TEST_P(ClusterSetBootstrapParamsErrorTest, ClusterSetBootstrapParamsError) {
  const unsigned bootstrap_cluster_id = GetParam().bootstrap_cluster_id;
  const unsigned bootstrap_node_id = GetParam().bootstrap_node_id;

  create_clusterset(view_id, /*target_cluster_id*/ 0, /*primary_cluster_id*/ 0,
                    "bootstrap_clusterset.js");

  std::vector<std::string> bootsrtap_params{
      "--bootstrap=127.0.0.1:" +
          std::to_string(clusterset_data_.clusters[bootstrap_cluster_id]
                             .nodes[bootstrap_node_id]
                             .classic_port),
      "--connect-timeout=1",
      "-d",
      bootstrap_directory.name(),
  };

  bootsrtap_params.insert(bootsrtap_params.end(),
                          GetParam().bootstrap_params.begin(),
                          GetParam().bootstrap_params.end());

  auto &router = launch_router_for_bootstrap(bootsrtap_params, EXIT_FAILURE);

  // verify that appropriate message was logged

  EXPECT_NO_THROW(router.wait_for_exit());
  EXPECT_THAT(router.get_full_output(),
              ::testing::HasSubstr(GetParam().expected_error));

  check_exit_code(router, EXIT_FAILURE);
}

INSTANTIATE_TEST_SUITE_P(
    ClusterSetBootstrapParamsError, ClusterSetBootstrapParamsErrorTest,
    ::testing::Values(
        // verify that using empty string as value for --conf-target-cluster
        // leads to expected bootstrap error
        // [@FR3.3.2]
        // [@FTS_R4_1/1]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster="},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        //[@FTS_R4_1/2]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=''"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // [@FTS_R4_1/3]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=''"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        //[@FTS_R4_1/4]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster=\"\""},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // [@FTS_R4_1/5]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=none"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // [@FTS_R4_1/6]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=gr-id-1"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // [@FTS_R4_1/7]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=current2"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // [@FTS_R4_1/8]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=primary cluster"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // [@FTS_R4_1/9]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster=0"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // verify that using --conf-target-cluster-by-name with no value
        // leads to expected bootstrap error
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster-by-name"},
            "Error: option '--conf-target-cluster-by-name' expects a value, "
            "got nothing"},
        // verify that using --conf-target-cluster-by-name with no value
        // leads to expected bootstrap error
        // [@TS_R5_1/13]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 1,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name="},
            "Value for parameter '--conf-target-cluster-by-name' can't be "
            "empty"},
        // verify that using both --conf-target-cluster and
        // --conf-target-cluster-by-name leads to expected bootstrap error
        // [@FR3.5.1]
        // [@TS_R8_2/1]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=primary",
             "--conf-target-cluster-by-name=cluster-name-1"},
            "Parameters '--conf-target-cluster' and "
            "'--conf-target-cluster-by-name' "
            "are mutually exclusive and can't be used together"},
        // [@TS_R8_2/2]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster-by-name=cluster-name-1",
             "--conf-target-cluster=primary"},
            "Parameters '--conf-target-cluster' and "
            "'--conf-target-cluster-by-name' "
            "are mutually exclusive and can't be used together"},
        // verify that using value other than 'primary' or 'current' for
        // --conf-target-cluster leads to expected bootstrap error
        // [@FR3.3.1]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=invalid"},
            "Value for parameter '--conf-target-cluster' needs to be one of: "
            "['primary', 'current']"},
        // verify that using --conf-target-cluster with no value leads to
        // expected bootstrap error
        // [@FR3.3.2]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster"},
            "Error: option '--conf-target-cluster' expects a value, got "
            "nothing"}));

class ClusterSetBootstrapClusterNotFoundErrorTest
    : public RouterClusterSetBootstrapTest,
      public ::testing::WithParamInterface<BootstrapParametersErrorTestParams> {
};

/**
 * @test
 *       verify the proper errors are reported if requested Cluster was not
 * found when bootstrapping
 */
TEST_P(ClusterSetBootstrapClusterNotFoundErrorTest,
       ClusterSetBootstrapClusterNotFoundError) {
  const unsigned bootstrap_cluster_id = GetParam().bootstrap_cluster_id;
  const unsigned bootstrap_node_id = GetParam().bootstrap_node_id;

  create_clusterset(view_id, 0, /*primary_cluster_id*/ 0,
                    "bootstrap_clusterset.js", "", "",
                    /*simulate_cluster_not_found*/ true);

  std::vector<std::string> bootsrtap_params{
      "--bootstrap=127.0.0.1:" +
          std::to_string(clusterset_data_.clusters[bootstrap_cluster_id]
                             .nodes[bootstrap_node_id]
                             .classic_port),
      "--connect-timeout=1",
      "-d",
      bootstrap_directory.name(),
  };

  bootsrtap_params.insert(bootsrtap_params.end(),
                          GetParam().bootstrap_params.begin(),
                          GetParam().bootstrap_params.end());

  auto &router = launch_router_for_bootstrap(bootsrtap_params, EXIT_FAILURE);

  // verify that appropriate message was logged

  EXPECT_NO_THROW(router.wait_for_exit());
  EXPECT_THAT(router.get_full_output(),
              ::testing::HasSubstr(GetParam().expected_error));

  check_exit_code(router, EXIT_FAILURE);
}

INSTANTIATE_TEST_SUITE_P(
    ClusterSetBootstrapClusterNotFoundError,
    ClusterSetBootstrapClusterNotFoundErrorTest,
    ::testing::Values(
        // verify that using --conf-target-cluster=primary where PRIMARY
        // Cluster can't be found leads to a proper error
        // [@FR3.2.1]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=primary"},
            "Error: Could not reach Primary Cluster for the ClusterSet"},

        // verify that using --conf-target-cluster-by-name=foo where foo is
        // not a cluster leads to a proper error
        // [@FR3.4.1]
        // [@TS_R5_1/19]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster-by-name=foo"},
            "Error: Could not find Cluster with selected name: 'foo'"},
        // [@TS_R5_1/12]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name=primary"},
            "Error: Could not find Cluster with selected name: 'primary'"},
        // [@TS_R5_1/13]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name=current"},
            "Error: Could not find Cluster with selected name: 'current'"},
        // [@TS_R5_1/14]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name=''"},
            "Error: Could not find Cluster with selected name: ''"},
        // [@TS_R5_1/15]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name=\" \""},
            "Error: Could not find Cluster with selected name: '\" \"'"},
        // [@TS_R5_1/16]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name=0"},
            "Error: Could not find Cluster with selected name: '0'"},
        // [@TS_R5_1/1]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster-by-name=00000000-0000-0000-0000-"
             "0000000000c1"},
            "Error: Could not find Cluster with selected name: "
            "'00000000-0000-0000-0000-0000000000c1'"},
        // [@TS_R5_1/8]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 2,
            /*bootstrap_node_id*/ 1,
            {"--conf-target-cluster-by-name=00000000-0000-0000-0000-"
             "0000000000c3"},
            "Error: Could not find Cluster with selected name: "
            "'00000000-0000-0000-0000-0000000000c3'"},
        // [@TS_R5_1/19]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster-by-name=\"foo\""},
            "Error: Could not find Cluster with selected name: '\"foo\"'"}));

/**
 * @test
 *       verify that Router fails whene there is no Primary Cluster while doing
 * the bootstrap
 * [@TS_R7_1]
 */
TEST_F(RouterClusterSetBootstrapTest, ClusterSetBootstrapNoPrimaryError) {
  const unsigned non_existing_cluster_id{5};

  create_clusterset(view_id, 0, /*primary_cluster_id*/ non_existing_cluster_id,
                    "bootstrap_clusterset.js", "");

  std::vector<std::string> bootsrtap_params{
      "--bootstrap=127.0.0.1:" +
          std::to_string(clusterset_data_.clusters[0].nodes[0].classic_port),
      "--connect-timeout=1",
      "-d",
      bootstrap_directory.name(),
      "--conf-target-cluster",
      "primary",
  };

  auto &router = launch_router_for_bootstrap(bootsrtap_params, EXIT_FAILURE);

  // verify that appropriate message was logged
  EXPECT_NO_THROW(router.wait_for_exit());
  EXPECT_THAT(router.get_full_output(),
              ::testing::HasSubstr(
                  "Error: Could not reach Primary Cluster for the ClusterSet"));

  check_exit_code(router, EXIT_FAILURE);
}

class ClusterSetBootstrapParamsNoBootstrapErrorTest
    : public RouterClusterSetBootstrapTest,
      public ::testing::WithParamInterface<BootstrapParametersErrorTestParams> {
};

/**
 * @test
 *       verify that --conf-target-cluster and --conf-target-cluster-by-name
 * params are only valid for bootstrap
 */
TEST_P(ClusterSetBootstrapParamsNoBootstrapErrorTest,
       ClusterSetBootstrapParamsNoBootstrapError) {
  // const uint16_t server_port = port_pool_.get_next_available();
  std::vector<std::string> router_params;

  router_params.insert(router_params.end(), GetParam().bootstrap_params.begin(),
                       GetParam().bootstrap_params.end());

  auto &router = launch_router_for_bootstrap(router_params, EXIT_FAILURE);

  //  // verify that appropriate message was logged

  EXPECT_NO_THROW(router.wait_for_exit());
  EXPECT_THAT(router.get_full_output(),
              ::testing::HasSubstr(GetParam().expected_error));

  check_exit_code(router, EXIT_FAILURE);
}

INSTANTIATE_TEST_SUITE_P(
    ClusterSetBootstrapParamsNoBootstrapError,
    ClusterSetBootstrapParamsNoBootstrapErrorTest,
    ::testing::Values(
        // 0) verify that using --conf-target-cluster when
        // not bootstrapping leads to expected error
        // [@FR3.5]
        // [@TS_R8_1/1]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=primary"},
            "Error: Option --conf-target-cluster can only "
            "be used together with -B/--bootstrap"},
        // 1) verify that using --conf-target-cluster-by-name when not
        // bootstrapping leads to expected error
        // [@FR3.5]
        // [@TS_R8_1/2]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster-by-name=cluster-name-1"},
            "Error: Option --conf-target-cluster-by-name can only "
            "be used together with -B/--bootstrap"},
        // [@TS_R8_1/3]
        BootstrapParametersErrorTestParams{
            /*bootstrap_cluster_id*/ 0,
            /*bootstrap_node_id*/ 0,
            {"--conf-target-cluster=primary",
             "--conf-target-cluster-by-name=cluster-name-1"},
            "Error: Parameters '--conf-target-cluster' and "
            "'--conf-target-cluster-by-name' are mutually exclusive and can't "
            "be used together"}));

static int get_session_init_count(const uint16_t http_port) {
  std::string server_globals =
      MockServerRestClient(http_port).get_globals_as_json_string();

  return get_int_field_value(server_globals, "session_count");
}

/**
 * @test
 *       verify that when user bootstraps using non-writable node, bootstrap
 * failover will first go to the nodes of the Cluster who's role is reported as
 * PRIMARY in the metadata, regardless of the order of those nodes returned by
 * the query
 *
 * For this we have a following scenario:
 * ClusterSet with 3 clusters
 * Cluster 1 is REPLICA
 * Cluster 2 is REPLICA
 * Cluster 3 is PRIMARY
 *
 * We use first node of Cluster 2 to bootstrap. We expect the failover, as this
 * node is not writable. The first node we are expected to failover to is the
 * first node of Cluster 3. We never expect to try to connect to Cluster 1.
 */
TEST_F(RouterClusterSetBootstrapTest, PrimaryClusterQueriedFirst) {
  const int target_cluster_id = 1;
  const int primary_cluster_id = 2;
  const std::string expected_target_cluster =
      "00000000-0000-0000-0000-0000000000g2";

  create_clusterset(view_id, target_cluster_id, primary_cluster_id,
                    "bootstrap_clusterset.js", "", expected_target_cluster);

  const unsigned bootstrap_node_id = 0;
  const std::string target_cluster_param = "--conf-target-cluster=current";

  // const auto &expected_output_strings = GetParam().expected_output_strings;

  std::vector<std::string> bootstrap_params = {
      "--bootstrap=127.0.0.1:" +
          std::to_string(clusterset_data_.clusters[target_cluster_id]
                             .nodes[bootstrap_node_id]
                             .classic_port),
      "-d", bootstrap_directory.name(), target_cluster_param,
      "--logger.level=debug"};

  auto &router = launch_router_for_bootstrap(bootstrap_params, EXIT_SUCCESS);

  check_exit_code(router, EXIT_SUCCESS);

  // check that the only nodes that we connected to during the bootstrap are the
  // one used as a -B parameter (first node of the second cluster) and the
  // primary node (first node of the third cluster)
  for (size_t cluster_id = 0; cluster_id < clusterset_data_.clusters.size();
       ++cluster_id) {
    const auto &cluster = clusterset_data_.clusters[cluster_id];

    for (size_t node_id = 0; node_id < cluster.nodes.size(); ++node_id) {
      const int expected_session_count =
          (cluster_id == 1 && node_id == 0) || (cluster_id == 2 && node_id == 0)
              ? 1
              : 0;

      EXPECT_EQ(expected_session_count,
                get_session_init_count(cluster.nodes[node_id].http_port));
    }
  }
}

static constexpr const unsigned long max_supported_version =
    MYSQL_ROUTER_VERSION_MAJOR * 10000 + MYSQL_ROUTER_VERSION_MINOR * 100 + 99;

struct ServerCompatTestParam {
  std::string description;
  std::string server_version;
  bool expect_failure;
  std::string expected_error_msg;
};

class CheckServerCompatibilityTest
    : public RouterClusterSetBootstrapTest,
      public ::testing::WithParamInterface<ServerCompatTestParam> {};

/**
 * @test
 *      Verifies that the server version is checked for compatibility when the
 * Router is bootstrapped against the ClusterSet
 */
TEST_P(CheckServerCompatibilityTest, Spec) {
  RecordProperty("Description", GetParam().description);

  create_clusterset(view_id, 0, 0, "bootstrap_clusterset.js");

  const auto http_port = clusterset_data_.clusters[0].nodes[0].http_port;
  const auto classic_port = clusterset_data_.clusters[0].nodes[0].classic_port;

  set_mock_server_version(http_port, GetParam().server_version);

  std::vector<std::string> bootstrap_params = {
      "--bootstrap=127.0.0.1:" + std::to_string(classic_port), "-d",
      bootstrap_directory.name()};

  const auto expected_exit_code =
      GetParam().expect_failure ? EXIT_FAILURE : EXIT_SUCCESS;
  auto &router =
      launch_router_for_bootstrap(bootstrap_params, expected_exit_code);
  check_exit_code(router, expected_exit_code);

  if (GetParam().expect_failure) {
    const std::string router_console_output = router.get_full_output();
    EXPECT_TRUE(
        pattern_found(router_console_output, GetParam().expected_error_msg))
        << router_console_output;
  }
}

INSTANTIATE_TEST_SUITE_P(
    Spec, CheckServerCompatibilityTest,
    ::testing::Values(
        ServerCompatTestParam{
            "Server is the same version as Router - bootstrap OK",
            std::to_string(MYSQL_ROUTER_VERSION_MAJOR) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_MINOR) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_PATCH),
            false, ""},
        ServerCompatTestParam{
            "Server major version is highier than Router - bootstrap should "
            "fail",
            std::to_string(MYSQL_ROUTER_VERSION_MAJOR + 1) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_MINOR) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_PATCH),
            true,
            "Error: Unsupported MySQL Server version '.*'. Maximal supported "
            "version is '" +
                std::to_string(max_supported_version) + "'."},
        ServerCompatTestParam{
            "Server minor version is highier than Router - bootstrap should "
            "fail",
            std::to_string(MYSQL_ROUTER_VERSION_MAJOR) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_MINOR + 1) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_PATCH),
            true,
            "Error: Unsupported MySQL Server version '.*'. Maximal supported "
            "version is '" +
                std::to_string(max_supported_version) + "'."},
        ServerCompatTestParam{
            "Server patch version is highier than Router - bootstrap OK",
            std::to_string(MYSQL_ROUTER_VERSION_MAJOR) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_MINOR) + "." +
                std::to_string(MYSQL_ROUTER_VERSION_PATCH + 1),
            false, ""}));

int main(int argc, char *argv[]) {
  init_windows_sockets();
  ProcessManager::set_origin(Path(argv[0]).dirname());
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}