"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/cluster/tests/15-cluster-slots.tcl" (21 Sep 2022, 2816 Bytes) of package /linux/misc/redis-7.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 source "../tests/includes/init-tests.tcl"
    2 
    3 proc cluster_allocate_mixedSlots {n} {
    4     set slot 16383
    5     while {$slot >= 0} {
    6         set node [expr {$slot % $n}]
    7         lappend slots_$node $slot
    8         incr slot -1
    9     }
   10     for {set j 0} {$j < $n} {incr j} {
   11         R $j cluster addslots {*}[set slots_${j}]
   12     }
   13 }
   14 
   15 proc create_cluster_with_mixedSlot {masters slaves} {
   16     cluster_allocate_mixedSlots $masters
   17     if {$slaves} {
   18         cluster_allocate_slaves $masters $slaves
   19     }
   20     assert_cluster_state ok
   21 }
   22 
   23 test "Create a 5 nodes cluster" {
   24     create_cluster_with_mixedSlot 5 15
   25 }
   26 
   27 test "Cluster is up" {
   28     assert_cluster_state ok
   29 }
   30 
   31 test "Cluster is writable" {
   32     cluster_write_test 0
   33 }
   34 
   35 test "Instance #5 is a slave" {
   36     assert {[RI 5 role] eq {slave}}
   37 }
   38 
   39 test "client do not break when cluster slot" {
   40     R 0 config set client-output-buffer-limit "normal 33554432 16777216 60"
   41     if { [catch {R 0 cluster slots}] } {
   42         fail "output overflow when cluster slots"
   43     }
   44 }
   45 
   46 test "client can handle keys with hash tag" {
   47     set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
   48     $cluster set foo{tag} bar
   49     $cluster close
   50 }
   51 
   52 test "slot migration is valid from primary to another primary" {
   53     set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
   54     set key order1
   55     set slot [$cluster cluster keyslot $key]
   56     array set nodefrom [$cluster masternode_for_slot $slot]
   57     array set nodeto [$cluster masternode_notfor_slot $slot]
   58 
   59     assert_equal {OK} [$nodefrom(link) cluster setslot $slot node $nodeto(id)]
   60     assert_equal {OK} [$nodeto(link) cluster setslot $slot node $nodeto(id)]
   61 }
   62 
   63 test "slot migration is invalid from primary to replica" {
   64     set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
   65     set key order1
   66     set slot [$cluster cluster keyslot $key]
   67     array set nodefrom [$cluster masternode_for_slot $slot]
   68 
   69     # Get replica node serving slot.
   70     set replicanodeinfo [$cluster cluster replicas $nodefrom(id)]
   71     puts $replicanodeinfo
   72     set args [split $replicanodeinfo " "]
   73     set replicaid [lindex [split [lindex $args 0] \{] 1]
   74     puts $replicaid
   75 
   76     catch {[$nodefrom(link) cluster setslot $slot node $replicaid]} err
   77     assert_match "*Target node is not a master" $err
   78 }
   79 
   80 if {$::tls} {
   81     test {CLUSTER SLOTS from non-TLS client in TLS cluster} {
   82         set slots_tls [R 0 cluster slots]
   83         set host [get_instance_attrib redis 0 host]
   84         set plaintext_port [get_instance_attrib redis 0 plaintext-port]
   85         set client_plain [redis $host $plaintext_port 0 0]
   86         set slots_plain [$client_plain cluster slots]
   87         $client_plain close
   88         # Compare the ports in the first row
   89         assert_no_match [lindex $slots_tls 0 3 1] [lindex $slots_plain 0 3 1]
   90     }
   91 }