15-cluster-slots.tcl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. source "../tests/includes/init-tests.tcl"
  2. proc cluster_allocate_mixedSlots {n} {
  3. set slot 16383
  4. while {$slot >= 0} {
  5. set node [expr {$slot % $n}]
  6. lappend slots_$node $slot
  7. incr slot -1
  8. }
  9. for {set j 0} {$j < $n} {incr j} {
  10. R $j cluster addslots {*}[set slots_${j}]
  11. }
  12. }
  13. proc create_cluster_with_mixedSlot {masters slaves} {
  14. cluster_allocate_mixedSlots $masters
  15. if {$slaves} {
  16. cluster_allocate_slaves $masters $slaves
  17. }
  18. assert_cluster_state ok
  19. }
  20. test "Create a 5 nodes cluster" {
  21. create_cluster_with_mixedSlot 5 15
  22. }
  23. test "Cluster is up" {
  24. assert_cluster_state ok
  25. }
  26. test "Cluster is writable" {
  27. cluster_write_test 0
  28. }
  29. test "Instance #5 is a slave" {
  30. assert {[RI 5 role] eq {slave}}
  31. }
  32. test "client do not break when cluster slot" {
  33. R 0 config set client-output-buffer-limit "normal 33554432 16777216 60"
  34. if { [catch {R 0 cluster slots}] } {
  35. fail "output overflow when cluster slots"
  36. }
  37. }
  38. test "client can handle keys with hash tag" {
  39. set cluster [redis_cluster 127.0.0.1:[get_instance_attrib redis 0 port]]
  40. $cluster set foo{tag} bar
  41. $cluster close
  42. }
  43. if {$::tls} {
  44. test {CLUSTER SLOTS from non-TLS client in TLS cluster} {
  45. set slots_tls [R 0 cluster slots]
  46. set host [get_instance_attrib redis 0 host]
  47. set plaintext_port [get_instance_attrib redis 0 plaintext-port]
  48. set client_plain [redis $host $plaintext_port 0 0]
  49. set slots_plain [$client_plain cluster slots]
  50. $client_plain close
  51. # Compare the ports in the first row
  52. assert_no_match [lindex $slots_tls 0 3 1] [lindex $slots_plain 0 3 1]
  53. }
  54. }