system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4

system sh/cfg.sh -n dnode1 -c wallevel -v 2
system sh/cfg.sh -n dnode2 -c wallevel -v 2
system sh/cfg.sh -n dnode3 -c wallevel -v 2
system sh/cfg.sh -n dnode4 -c wallevel -v 2

system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1
system sh/cfg.sh -n dnode2 -c numOfMnodes -v 1
system sh/cfg.sh -n dnode3 -c numOfMnodes -v 1
system sh/cfg.sh -n dnode4 -c numOfMnodes -v 1

system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode2 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode3 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode4 -c mnodeEqualVnodeNum -v 4

system sh/cfg.sh -n dnode1 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode2 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode3 -c numOfTotalVnodes -v 4
system sh/cfg.sh -n dnode4 -c numOfTotalVnodes -v 4

system sh/cfg.sh -n dnode1 -c maxVgroupsPerDb -v 8
system sh/cfg.sh -n dnode2 -c maxVgroupsPerDb -v 8
system sh/cfg.sh -n dnode3 -c maxVgroupsPerDb -v 8
system sh/cfg.sh -n dnode4 -c maxVgroupsPerDb -v 8

system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode3 -c maxTablesPerVnode -v 4
system sh/cfg.sh -n dnode4 -c maxTablesPerVnode -v 4

print ========= start dnodes
system sh/exec.sh -n dnode1 -s start
sleep 3000
sql connect
sql create dnode $hostname2
system sh/exec.sh -n dnode2 -s start

$loop = 0
begin:

    $db = db . $loop
	
	print ======== step1 $loop
	sql create database $db
	sql use $db
	
	sql create table t11 (ts timestamp, i int)
	sql insert into t11 values(now, 1 )
	sql create table t12 (ts timestamp, i int)
	sql insert into t12 values(now, 1 )
	sql create table t13 (ts timestamp, i int)
	sql insert into t13 values(now, 1 )
	sql create table t14 (ts timestamp, i int)
	sql insert into t14 values(now, 1 )
	sleep 1200

	sql create table t21 (ts timestamp, i int)
	sql insert into t21 values(now, 1 )
	sql create table t22 (ts timestamp, i int)
	sql insert into t22 values(now, 1 )
	sql create table t23 (ts timestamp, i int)
	sql insert into t23 values(now, 1 )
	sql create table t24 (ts timestamp, i int)
	sql insert into t24 values(now, 1 )
	sleep 1200

	sql create table t31 (ts timestamp, i int)
	sql insert into t31 values(now, 1 )
	sql create table t32 (ts timestamp, i int)
	sql insert into t32 values(now, 1 )
	sql create table t33 (ts timestamp, i int)
	sql insert into t33 values(now, 1 )
	sql create table t34 (ts timestamp, i int)
	sql insert into t34 values(now, 1 )
	sleep 1200

	sql create table t41 (ts timestamp, i int)
	sql insert into t41 values(now, 1 )
	sql create table t42 (ts timestamp, i int)
	sql insert into t42 values(now, 1 )
	sql create table t43 (ts timestamp, i int)
	sql insert into t43 values(now, 1 )
	sql create table t44 (ts timestamp, i int)
	sql insert into t44 values(now, 1 )
	sleep 1200

	sql create table t51 (ts timestamp, i int)
	sql insert into t51 values(now, 1 )
	sql create table t52 (ts timestamp, i int)
	sql insert into t52 values(now, 1 )
	sql create table t53 (ts timestamp, i int)
	sql insert into t53 values(now, 1 )
	sql create table t54 (ts timestamp, i int)
	sql insert into t54 values(now, 1 )
	sleep 1200

	sql create table t61 (ts timestamp, i int)
	sql insert into t61 values(now, 1 )
	sql create table t62 (ts timestamp, i int)
	sql insert into t62 values(now, 1 )
	sql create table t63 (ts timestamp, i int)
	sql insert into t63 values(now, 1 )
	sql create table t64 (ts timestamp, i int)
	sql insert into t64 values(now, 1 )
	sleep 1200

	sql create table t71 (ts timestamp, i int)
	sql insert into t71 values(now, 1 )
	sql create table t72 (ts timestamp, i int)
	sql insert into t72 values(now, 1 )
	sql create table t73 (ts timestamp, i int)
	sql insert into t73 values(now, 1 )
	sql create table t74 (ts timestamp, i int)
	sql insert into t74 values(now, 1 )
	sleep 1200

	sql create table t81 (ts timestamp, i int)
	sql insert into t81 values(now, 1 )
	sql create table t82 (ts timestamp, i int)
	sql insert into t82 values(now, 1 )
	sql create table t83 (ts timestamp, i int)
	sql insert into t83 values(now, 1 )
	sql create table t84 (ts timestamp, i int)
	sql insert into t84 values(now, 1 )
	sleep 1200

	sql show dnodes
	print dnode1 openVnodes $data2_1
	print dnode2 openVnodes $data2_2
	if $data2_1 != 4 then
		return -1
	endi
	if $data2_2 != 4 then
		return -1
	endi

	print ======== step2 $loop
	
	system sh/exec.sh -n dnode2 -s stop
	sleep 1000
	print ==> drop database $db 
	sql drop database $db 
	
	print ======== step3 $loop
	sleep 2000
	system sh/exec.sh -n dnode2 -s start
	sleep 15000

	sql show dnodes
	print dnode1 openVnodes $data2_1 $data4_1
	print dnode2 openVnodes $data2_2 $data4_2
	if $data2_1 != 0 then
		return -1
	endi
	if $data2_2 != 0 then
		return -1
	endi
	if $data4_1 != ready then
		return -1
	endi
	if $data4_2 != ready then
		return -1
	endi
	
	print ===> test times : $loop
    if $loop > 3 then	  
	  return 0
	endi

	$loop = $loop + 1

	sql reset query cache
	sleep 1000
	
goto begin
  
system sh/exec.sh -n dnode1 -s stop  -x SIGINT
system sh/exec.sh -n dnode2 -s stop  -x SIGINT
system sh/exec.sh -n dnode3 -s stop  -x SIGINT
system sh/exec.sh -n dnode4 -s stop  -x SIGINT
system sh/exec.sh -n dnode5 -s stop  -x SIGINT
system sh/exec.sh -n dnode6 -s stop  -x SIGINT
system sh/exec.sh -n dnode7 -s stop  -x SIGINT
system sh/exec.sh -n dnode8 -s stop  -x SIGINT