2020-02-10 18:15:29 -05:00
|
|
|
foreach topology {mesh ring} {
|
2020-07-12 19:25:19 +00:00
|
|
|
|
|
|
|
foreach noforward [expr {[string equal $topology "mesh"] ? {no yes} : {no}}] {
|
2020-02-10 18:15:29 -05:00
|
|
|
start_server {tags {"multi-master"} overrides {hz 500 active-replica yes multi-master yes}} {
|
|
|
|
start_server {overrides {hz 500 active-replica yes multi-master yes}} {
|
|
|
|
start_server {overrides {hz 500 active-replica yes multi-master yes}} {
|
|
|
|
start_server {overrides {hz 500 active-replica yes multi-master yes}} {
|
|
|
|
|
|
|
|
for {set j 0} {$j < 4} {incr j} {
|
|
|
|
set R($j) [srv [expr 0-$j] client]
|
|
|
|
set R_host($j) [srv [expr 0-$j] host]
|
|
|
|
set R_port($j) [srv [expr 0-$j] port]
|
2020-07-12 19:25:19 +00:00
|
|
|
|
|
|
|
$R($j) config set multi-master-no-forward $noforward
|
2020-02-10 18:15:29 -05:00
|
|
|
}
|
|
|
|
|
2020-07-12 19:25:19 +00:00
|
|
|
set topology_name "$topology[expr {[string equal $noforward "yes"] ? " no-forward" : ""}]"
|
|
|
|
|
2020-02-10 18:15:29 -05:00
|
|
|
# Initialize as mesh
|
|
|
|
if [string equal $topology "mesh"] {
|
|
|
|
for {set j 0} {$j < 4} {incr j} {
|
|
|
|
for {set k 0} {$k < 4} {incr k} {
|
|
|
|
if $j!=$k {
|
|
|
|
$R($j) replicaof $R_host($k) $R_port($k)
|
|
|
|
after 100
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
#Else Ring
|
|
|
|
if [string equal $topology "ring"] {
|
|
|
|
$R(0) replicaof $R_host(3) $R_port(3)
|
|
|
|
after 100
|
|
|
|
$R(1) replicaof $R_host(0) $R_port(0)
|
|
|
|
after 100
|
|
|
|
$R(2) replicaof $R_host(1) $R_port(1)
|
|
|
|
after 100
|
|
|
|
$R(3) replicaof $R_host(2) $R_port(2)
|
|
|
|
}
|
|
|
|
|
2020-07-12 19:25:19 +00:00
|
|
|
test "$topology_name all nodes up" {
|
2020-05-31 22:50:30 -04:00
|
|
|
for {set j 0} {$j < 4} {incr j} {
|
|
|
|
wait_for_condition 50 100 {
|
2020-05-31 23:22:25 -04:00
|
|
|
[string match {*master_global_link_status:up*} [$R($j) info replication]]
|
2020-05-31 22:50:30 -04:00
|
|
|
} else {
|
|
|
|
fail "Multimaster group didn't connect up in a reasonable period of time"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 18:15:29 -05:00
|
|
|
|
2020-07-12 19:25:19 +00:00
|
|
|
test "$topology_name replicates to all nodes" {
|
2020-02-10 18:15:29 -05:00
|
|
|
$R(0) set testkey foo
|
|
|
|
after 500
|
2020-05-11 09:37:42 +00:00
|
|
|
for {set n 0} {$n < 4} {incr n} {
|
2020-05-31 22:50:30 -04:00
|
|
|
wait_for_condition 50 100 {
|
2020-05-11 09:37:42 +00:00
|
|
|
[$R($n) get testkey] == "foo"
|
|
|
|
} else {
|
|
|
|
fail "Failed to replicate to $n"
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 18:15:29 -05:00
|
|
|
}
|
|
|
|
|
2020-07-12 19:25:19 +00:00
|
|
|
test "$topology_name replicates only once" {
|
2020-02-10 18:15:29 -05:00
|
|
|
$R(0) set testkey 1
|
|
|
|
after 500
|
2020-05-31 22:50:30 -04:00
|
|
|
#wait_for_condition 50 100 {
|
|
|
|
# [$R(1) get testkey] == 1 && [$R(2) get testkey] == 1
|
|
|
|
#} else {
|
|
|
|
# fail "Set failed to replicate"
|
|
|
|
#}
|
2020-02-10 18:15:29 -05:00
|
|
|
$R(1) incr testkey
|
|
|
|
after 500
|
|
|
|
$R(2) incr testkey
|
|
|
|
after 500
|
2020-05-11 09:22:27 +00:00
|
|
|
for {set n 0} {$n < 4} {incr n} {
|
2020-05-31 22:50:30 -04:00
|
|
|
wait_for_condition 100 100 {
|
2020-05-11 09:22:27 +00:00
|
|
|
[$R($n) get testkey] == 3
|
|
|
|
} else {
|
|
|
|
fail "node $n did not replicate"
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 18:15:29 -05:00
|
|
|
}
|
|
|
|
|
2020-07-12 19:25:19 +00:00
|
|
|
test "$topology_name transaction replicates only once" {
|
2020-02-10 18:15:29 -05:00
|
|
|
for {set j 0} {$j < 1000} {incr j} {
|
|
|
|
$R(0) set testkey 1
|
|
|
|
$R(0) multi
|
|
|
|
$R(0) incr testkey
|
|
|
|
$R(0) incr testkey
|
|
|
|
$R(0) exec
|
2020-05-11 09:22:27 +00:00
|
|
|
for {set n 0} {$n < 4} {incr n} {
|
2020-05-31 22:50:30 -04:00
|
|
|
wait_for_condition 50 100 {
|
2020-05-11 09:22:27 +00:00
|
|
|
[$R($n) get testkey] == 3
|
|
|
|
} else {
|
|
|
|
fail "node $n failed to replicate"
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 18:15:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-12 19:25:19 +00:00
|
|
|
}
|