#!/bin/sh

. "${TEST_SCRIPTS_DIR}/unit.sh"

define_test "3 nodes, 1 -> all healthy, debug logging"

export CTDB_TEST_LOGLEVEL=4

required_result <<EOF
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES (UNASSIGNED)
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [0]
${TEST_DATE_STAMP} 1 [539166]
${TEST_DATE_STAMP} 2 [0]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [539166]
${TEST_DATE_STAMP} 1 [-116718] -> 192.168.21.254 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-116718] -> 192.168.21.254 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-116971] -> 192.168.21.253 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-116971] -> 192.168.21.253 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-116971] -> 192.168.21.252 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-116971] -> 192.168.21.252 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-121110] -> 192.168.20.254 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-121110] -> 192.168.20.254 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.253 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.253 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.252 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.252 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.251 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.251 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.250 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-121363] -> 192.168.20.250 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-121110] -> 192.168.20.249 -> 0 [+0]
${TEST_DATE_STAMP} 1 [-121110] -> 192.168.20.249 -> 2 [+0]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}1 [-121363] -> 192.168.20.253 -> 0 [+0]
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [0]
${TEST_DATE_STAMP} 1 [417803]
${TEST_DATE_STAMP} 2 [0]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [417803]
${TEST_DATE_STAMP} 1 [-102557] -> 192.168.21.254 -> 0 [+14161]
${TEST_DATE_STAMP} 1 [-102557] -> 192.168.21.254 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-102810] -> 192.168.21.253 -> 0 [+14161]
${TEST_DATE_STAMP} 1 [-102810] -> 192.168.21.253 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-102810] -> 192.168.21.252 -> 0 [+14161]
${TEST_DATE_STAMP} 1 [-102810] -> 192.168.21.252 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-105234] -> 192.168.20.254 -> 0 [+15876]
${TEST_DATE_STAMP} 1 [-105234] -> 192.168.20.254 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-105234] -> 192.168.20.252 -> 0 [+16129]
${TEST_DATE_STAMP} 1 [-105234] -> 192.168.20.252 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-105738] -> 192.168.20.251 -> 0 [+15625]
${TEST_DATE_STAMP} 1 [-105738] -> 192.168.20.251 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-105738] -> 192.168.20.250 -> 0 [+15625]
${TEST_DATE_STAMP} 1 [-105738] -> 192.168.20.250 -> 2 [+0]
${TEST_DATE_STAMP} 1 [-105485] -> 192.168.20.249 -> 0 [+15625]
${TEST_DATE_STAMP} 1 [-105485] -> 192.168.20.249 -> 2 [+0]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}1 [-105738] -> 192.168.20.251 -> 2 [+0]
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [0]
${TEST_DATE_STAMP} 1 [312065]
${TEST_DATE_STAMP} 2 [0]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [312065]
${TEST_DATE_STAMP} 1 [-88396] -> 192.168.21.254 -> 0 [+14161]
${TEST_DATE_STAMP} 1 [-88396] -> 192.168.21.254 -> 2 [+14161]
${TEST_DATE_STAMP} 1 [-88649] -> 192.168.21.253 -> 0 [+14161]
${TEST_DATE_STAMP} 1 [-88649] -> 192.168.21.253 -> 2 [+14161]
${TEST_DATE_STAMP} 1 [-88649] -> 192.168.21.252 -> 0 [+14161]
${TEST_DATE_STAMP} 1 [-88649] -> 192.168.21.252 -> 2 [+14161]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.254 -> 0 [+15876]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.254 -> 2 [+15625]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.252 -> 0 [+16129]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.252 -> 2 [+15625]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.250 -> 0 [+15625]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.250 -> 2 [+16129]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.249 -> 0 [+15625]
${TEST_DATE_STAMP} 1 [-89609] -> 192.168.20.249 -> 2 [+15876]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}1 [-88649] -> 192.168.21.253 -> 0 [+14161]
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [14161]
${TEST_DATE_STAMP} 1 [223416]
${TEST_DATE_STAMP} 2 [0]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [223416]
${TEST_DATE_STAMP} 1 [-72520] -> 192.168.21.254 -> 0 [+30037]
${TEST_DATE_STAMP} 1 [-72520] -> 192.168.21.254 -> 2 [+14161]
${TEST_DATE_STAMP} 1 [-72520] -> 192.168.21.252 -> 0 [+30290]
${TEST_DATE_STAMP} 1 [-72520] -> 192.168.21.252 -> 2 [+14161]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.254 -> 0 [+30037]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.254 -> 2 [+15625]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.252 -> 0 [+30290]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.252 -> 2 [+15625]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.250 -> 0 [+29786]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.250 -> 2 [+16129]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.249 -> 0 [+29786]
${TEST_DATE_STAMP} 1 [-75448] -> 192.168.20.249 -> 2 [+15876]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}1 [-75448] -> 192.168.20.254 -> 2 [+15625]
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [14161]
${TEST_DATE_STAMP} 1 [147968]
${TEST_DATE_STAMP} 2 [15625]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [147968]
${TEST_DATE_STAMP} 1 [-58359] -> 192.168.21.254 -> 0 [+30037]
${TEST_DATE_STAMP} 1 [-58359] -> 192.168.21.254 -> 2 [+28322]
${TEST_DATE_STAMP} 1 [-58359] -> 192.168.21.252 -> 0 [+30290]
${TEST_DATE_STAMP} 1 [-58359] -> 192.168.21.252 -> 2 [+28322]
${TEST_DATE_STAMP} 1 [-59572] -> 192.168.20.252 -> 0 [+30290]
${TEST_DATE_STAMP} 1 [-59572] -> 192.168.20.252 -> 2 [+31501]
${TEST_DATE_STAMP} 1 [-59823] -> 192.168.20.250 -> 0 [+29786]
${TEST_DATE_STAMP} 1 [-59823] -> 192.168.20.250 -> 2 [+31754]
${TEST_DATE_STAMP} 1 [-59823] -> 192.168.20.249 -> 0 [+29786]
${TEST_DATE_STAMP} 1 [-59823] -> 192.168.20.249 -> 2 [+31501]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}1 [-59823] -> 192.168.20.250 -> 0 [+29786]
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [43947]
${TEST_DATE_STAMP} 1 [88145]
${TEST_DATE_STAMP} 2 [15625]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [88145]
${TEST_DATE_STAMP} 1 [-44198] -> 192.168.21.254 -> 0 [+44198]
${TEST_DATE_STAMP} 1 [-44198] -> 192.168.21.254 -> 2 [+28322]
${TEST_DATE_STAMP} 1 [-44198] -> 192.168.21.252 -> 0 [+44451]
${TEST_DATE_STAMP} 1 [-44198] -> 192.168.21.252 -> 2 [+28322]
${TEST_DATE_STAMP} 1 [-43947] -> 192.168.20.252 -> 0 [+45915]
${TEST_DATE_STAMP} 1 [-43947] -> 192.168.20.252 -> 2 [+31501]
${TEST_DATE_STAMP} 1 [-43947] -> 192.168.20.249 -> 0 [+45662]
${TEST_DATE_STAMP} 1 [-43947] -> 192.168.20.249 -> 2 [+31501]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP}1 [-44198] -> 192.168.21.254 -> 2 [+28322]
${TEST_DATE_STAMP}+++++++++++++++++++++++++++++++++++++++++
${TEST_DATE_STAMP}Selecting most imbalanced node from:
${TEST_DATE_STAMP} 0 [43947]
${TEST_DATE_STAMP} 1 [43947]
${TEST_DATE_STAMP} 2 [43947]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 0 [43947]
${TEST_DATE_STAMP} 0 [-28322] -> 192.168.21.253 -> 0 [+28322]
${TEST_DATE_STAMP} 0 [-28322] -> 192.168.21.253 -> 2 [+44198]
${TEST_DATE_STAMP} 0 [-29786] -> 192.168.20.253 -> 0 [+29786]
${TEST_DATE_STAMP} 0 [-29786] -> 192.168.20.253 -> 2 [+45662]
${TEST_DATE_STAMP} 0 [-29786] -> 192.168.20.250 -> 0 [+29786]
${TEST_DATE_STAMP} 0 [-29786] -> 192.168.20.250 -> 2 [+45915]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 1 [43947]
${TEST_DATE_STAMP} 1 [-28322] -> 192.168.21.252 -> 0 [+44451]
${TEST_DATE_STAMP} 1 [-28322] -> 192.168.21.252 -> 2 [+44198]
${TEST_DATE_STAMP} 1 [-29786] -> 192.168.20.252 -> 0 [+45915]
${TEST_DATE_STAMP} 1 [-29786] -> 192.168.20.252 -> 2 [+45662]
${TEST_DATE_STAMP} 1 [-29786] -> 192.168.20.249 -> 0 [+45662]
${TEST_DATE_STAMP} 1 [-29786] -> 192.168.20.249 -> 2 [+45662]
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} ----------------------------------------
${TEST_DATE_STAMP} CONSIDERING MOVES FROM 2 [43947]
${TEST_DATE_STAMP} 2 [-28322] -> 192.168.21.254 -> 0 [+44198]
${TEST_DATE_STAMP} 2 [-28322] -> 192.168.21.254 -> 2 [+28322]
${TEST_DATE_STAMP} 2 [-29786] -> 192.168.20.254 -> 0 [+45662]
${TEST_DATE_STAMP} 2 [-29786] -> 192.168.20.254 -> 2 [+29786]
${TEST_DATE_STAMP} 2 [-29786] -> 192.168.20.251 -> 0 [+45915]
${TEST_DATE_STAMP} 2 [-29786] -> 192.168.20.251 -> 2 [+29786]
${TEST_DATE_STAMP} ----------------------------------------
192.168.21.254 2
192.168.21.253 0
192.168.21.252 1
192.168.20.254 2
192.168.20.253 0
192.168.20.252 1
192.168.20.251 2
192.168.20.250 0
192.168.20.249 1
EOF

simple_test 0,0,0 <<EOF
192.168.20.249 1
192.168.20.250 1
192.168.20.251 1
192.168.20.252 1
192.168.20.253 1
192.168.20.254 1
192.168.21.252 1
192.168.21.253 1
192.168.21.254 1
EOF
