summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2014-04-29 10:42:17 +0200
committerantirez <antirez@gmail.com>2014-04-29 10:42:17 +0200
commite1b129811af5010730108537fede2421dbc841fa (patch)
tree41874381a59a407df6a875ca8dff025cf4fb4dd4
parent0bcc7cb4bfe733e7ea12599a926e52aece3bfa50 (diff)
downloadredis-e1b129811af5010730108537fede2421dbc841fa.tar.gz
Cluster test: basic cluster nodes info access functions.
-rw-r--r--tests/cluster/cluster.tcl37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/cluster/cluster.tcl b/tests/cluster/cluster.tcl
index 685c501da..f85f96fd6 100644
--- a/tests/cluster/cluster.tcl
+++ b/tests/cluster/cluster.tcl
@@ -4,4 +4,41 @@
# This softare is released under the BSD License. See the COPYING file for
# more information.
+# Returns a parsed CLUSTER NODES output as a list of dictionaries.
+proc get_cluster_nodes id {
+ set lines [split [R $id cluster nodes] "\r\n"]
+ set nodes {}
+ foreach l $lines {
+ set l [string trim $l]
+ if {$l eq {}} continue
+ set args [split $l]
+ set node [dict create \
+ id [lindex $args 0] \
+ addr [lindex $args 1] \
+ flags [split [lindex $args 2] ,] \
+ slaveof [lindex $args 3] \
+ ping_sent [lindex $args 4] \
+ pong_recv [lindex $args 5] \
+ config_epoch [lindex $args 6] \
+ linkstate [lindex $args 7] \
+ slots [lrange $args 8 -1] \
+ ]
+ lappend nodes $node
+ }
+ return $nodes
+}
+
+# Test node for flag.
+proc has_flag {node flag} {
+ expr {[lsearch -exact [dict get $node flags] $flag] != -1}
+}
+
+# Returns the parsed myself node entry as a dictionary.
+proc get_myself id {
+ set nodes [get_cluster_nodes $id]
+ foreach n $nodes {
+ if {[has_flag $n myself]} {return $n}
+ }
+ return {}
+}