Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
c4fbc1d3
Commit
c4fbc1d3
authored
Feb 18, 2014
by
antirez
Browse files
Sentinel test: info fields, master-slave setup, fixes.
parent
19b863c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/sentinel-tests/00-base.tcl
View file @
c4fbc1d3
...
@@ -3,3 +3,7 @@ test "Sentinels aren't monitoring any master" {
...
@@ -3,3 +3,7 @@ test "Sentinels aren't monitoring any master" {
assert
{[
S $id sentinel masters
]
eq
{}}
assert
{[
S $id sentinel masters
]
eq
{}}
}
}
}
}
test
"Sentinels can start monitoring a master"
{
create_redis_master_slave_cluster 3
}
tests/sentinel.tcl
View file @
c4fbc1d3
...
@@ -47,7 +47,12 @@ proc spawn_instance {type base_port count} {
...
@@ -47,7 +47,12 @@ proc spawn_instance {type base_port count} {
close $cfg
close $cfg
# Finally exec it and remember the pid for later cleanup.
# Finally exec it and remember the pid for later cleanup.
set sentinel_pid
[
exec ../../src/redis-sentinel $cfgfile &
]
if
{
$type
eq
"redis"
}
{
set prgname redis-server
}
else
{
set prgname redis-sentinel
}
set sentinel_pid
[
exec ../../src/$
{
prgname
}
$cfgfile &
]
lappend ::pids $sentinel_pid
lappend ::pids $sentinel_pid
# Check availability
# Check availability
...
@@ -133,6 +138,26 @@ proc R {n args} {
...
@@ -133,6 +138,26 @@ proc R {n args} {
[
dict get $r link
]
{*}
$args
[
dict get $r link
]
{*}
$args
}
}
proc get_info_field
{
info field
}
{
set fl
[
string length $field
]
append field :
foreach line
[
split $info
"
\n
"
]
{
set line
[
string trim $line
"
\r\n
"
]
if
{[
string range $line 0 $fl
]
eq $field
}
{
return
[
string range $line
[
expr
{
$fl
+1
}]
end
]
}
}
return
{}
}
proc SI
{
n field
}
{
get_info_field
[
S $n info
]
$field
}
proc RI
{
n field
}
{
get_info_field
[
R $n info
]
$field
}
# Iterate over IDs of sentinel or redis instances.
# Iterate over IDs of sentinel or redis instances.
proc foreach_sentinel_id
{
idvar code
}
{
proc foreach_sentinel_id
{
idvar code
}
{
upvar 1 $idvar id
upvar 1 $idvar id
...
@@ -148,6 +173,36 @@ proc foreach_redis_id {idvar code} {
...
@@ -148,6 +173,36 @@ proc foreach_redis_id {idvar code} {
}
}
}
}
# Get the specific attribute of the specified instance type, id.
proc get_instance_attrib
{
type id attrib
}
{
dict get
[
lindex
[
set ::$
{
type
}
_instances
]
$id
]
$attrib
}
# Create a master-slave cluster of the given number of total instances.
# The first instance
"0"
is the master, all others are configured as
# slaves.
proc create_redis_master_slave_cluster n
{
foreach_redis_id id
{
if
{
$id
== 0
}
{
# Our master.
R $id flushall
R $id slaveof no one
}
elseif
{
$id
< $n
}
{
R $id slaveof
[
get_instance_attrib redis 0 host
]
\
[
get_instance_attrib redis 0 port
]
}
else
{
# Instances not part of the cluster.
R $id slaveof no one
}
}
# Wait for all the slaves to sync.
wait_for_condition 100 50
{
[
RI 0 connected_slaves
]
==
(
$n-1
)
}
else
{
fail
"Unable to create a master-slaves cluster."
}
}
if
{[
catch main e
]}
{
if
{[
catch main e
]}
{
puts $::errorInfo
puts $::errorInfo
cleanup
cleanup
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment