1# Check the multiple slot add and remove commands
2
3source "../tests/includes/init-tests.tcl"
4
5proc cluster_allocate_with_continuous_slots {n} {
6    R 0 cluster ADDSLOTSRANGE 0 3276
7    R 1 cluster ADDSLOTSRANGE 3277 6552
8    R 2 cluster ADDSLOTSRANGE 6553 9828
9    R 3 cluster ADDSLOTSRANGE 9829 13104
10    R 4 cluster ADDSLOTSRANGE 13105 16383
11}
12
13proc cluster_create_with_continuous_slots {masters slaves} {
14    cluster_allocate_with_continuous_slots $masters
15    if {$slaves} {
16        cluster_allocate_slaves $masters $slaves
17    }
18    assert_cluster_state ok
19}
20
21
22test "Create a 5 nodes cluster" {
23    cluster_create_with_continuous_slots 5 5
24}
25
26test "Cluster should start ok" {
27    assert_cluster_state ok
28}
29
30set master1 [Rn 0]
31set master2 [Rn 1]
32set master3 [Rn 2]
33set master4 [Rn 3]
34set master5 [Rn 4]
35
36
37test "Continuous slots distribution" {
38    assert_match "* 0-3276*" [$master1 CLUSTER NODES]
39    assert_match "* 3277-6552*" [$master2 CLUSTER NODES]
40    assert_match "* 6553-9828*" [$master3 CLUSTER NODES]
41    assert_match "* 9829-13104*" [$master4 CLUSTER NODES]
42    assert_match "* 13105-16383*" [$master5 CLUSTER NODES]
43    assert_match "*0 3276*" [$master1 CLUSTER SLOTS]
44    assert_match "*3277 6552*" [$master2 CLUSTER SLOTS]
45    assert_match "*6553 9828*" [$master3 CLUSTER SLOTS]
46    assert_match "*9829 13104*" [$master4 CLUSTER SLOTS]
47    assert_match "*13105 16383*" [$master5 CLUSTER SLOTS]
48
49    $master1 CLUSTER DELSLOTSRANGE 3001 3050
50    assert_match "* 0-3000 3051-3276*" [$master1 CLUSTER NODES]
51    assert_match "*0 3000*3051 3276*" [$master1 CLUSTER SLOTS]
52
53    $master2 CLUSTER DELSLOTSRANGE 5001 5500
54    assert_match "* 3277-5000 5501-6552*" [$master2 CLUSTER NODES]
55    assert_match "*3277 5000*5501 6552*" [$master2 CLUSTER SLOTS]
56
57    $master3 CLUSTER DELSLOTSRANGE 7001 7100 8001 8500
58    assert_match "* 6553-7000 7101-8000 8501-9828*" [$master3 CLUSTER NODES]
59    assert_match "*6553 7000*7101 8000*8501 9828*" [$master3 CLUSTER SLOTS]
60
61    $master4 CLUSTER DELSLOTSRANGE 11001 12000 12101 12200
62    assert_match "* 9829-11000 12001-12100 12201-13104*" [$master4 CLUSTER NODES]
63    assert_match "*9829 11000*12001 12100*12201 13104*" [$master4 CLUSTER SLOTS]
64
65    $master5 CLUSTER DELSLOTSRANGE 13501 14000 15001 16000
66    assert_match "* 13105-13500 14001-15000 16001-16383*" [$master5 CLUSTER NODES]
67    assert_match "*13105 13500*14001 15000*16001 16383*" [$master5 CLUSTER SLOTS]
68}
69