system sh/stop_dnodes.sh


system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c commitLog -v 0
system sh/cfg.sh -n dnode1 -c meterMetaKeepTimer -v 1
system sh/cfg.sh -n dnode1 -c metricMetaKeepTimer -v 1
system sh/exec.sh -n dnode1 -s start

sleep 3000
sql connect
print ======================== dnode1 start

$i = 0
$dbPrefix = rs_db
$tbPrefix = rs_tb
$mtPrefix = rs_mt
$stPrefix = rs_st
$tbNum = 10
$rowNum = 20
$totalNum = 200

$db = $dbPrefix
$tb = $tbPrefix . $i
$mt = $mtPrefix
$stm = $stPrefix . m
$stt = $stPrefix . t

print =============== step1
sql create database $db
sql use $db

sql create table $mt (ts timestamp, tbcol int, tbcol2 int ) TAGS(tgcol bool)
$i = 0
while $i < 10
  $tb = $tbPrefix . $i
  sql create table $tb using $mt tags( 0 )  

  $x = -1440
  $y = 0
  while $y < $rowNum
    $ms = $x . m 
    sql insert into $tb values (now $ms , $y , $y ) 
    $x = $x + 1
	$y = $y + 1
  endw 
  
  $i = $i + 1
endw 

print =============== step2
$i = 0
$tb = $tbPrefix . $i

sql select count(*) from $tb interval(1d)
print ===>rows $rows, data $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 20 then
  return -1
endi  

sql select count(*) from $mt interval(1d)
print ===>rows $rows, data $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 200 then
  return -1
endi  

print =============== step3
sql create table $stt as select count(*) from $tb interval(1d)
sql create table $stm as select count(*) from $mt interval(1d)

print sleep 22 seconds
sleep 22000 

sql select * from $stt
print select count(*) from $stt ===> $data00 $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 20 then
  return -1
endi  

sql select * from $stm
print select * from $stm ===> $data00 $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 200 then
  return -1
endi  

print =============== step4
system sh/exec.sh -n dnode1 -s stop
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c commitLog -v 0
system sh/cfg.sh -n dnode1 -c meterMetaKeepTimer -v 1
system sh/cfg.sh -n dnode1 -c metricMetaKeepTimer -v 1
system sh/exec.sh -n dnode1 -s start

print =============== step5
print ==> sleep 8 seconds to renew cache
sleep 8000


print =============== step6
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol bigint, tbcol2 bigint  ) TAGS(tgcol int)
$i = 0
while $i < 5
  $tb = $tbPrefix . $i
  sql create table $tb using $mt tags( 0 )  
  
  $x = -1440
  $y = 0
  while $y < $rowNum
    $ms = $x . m 
    sql insert into $tb values (now $ms , $y , $y ) 
    $x = $x + 1
	$y = $y + 1
  endw 
  
  $i = $i + 1
endw 


print =============== step7

sql select count(*) from $tb interval(1d)
print ===>rows $rows, data $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 20 then
  return -1
endi  

sql select count(*) from $mt interval(1d)
print ===>rows $rows, data $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 100 then
  return -1
endi  

print =============== step8
sql create table $stt as select count(*) from $tb interval(1d)
sql create table $stm as select count(*) from $mt interval(1d)

print sleep 22 seconds
sleep 22000 

sql select * from $stt
sleep 1000
print ===>rows $rows, data $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 20 then
  return -1
endi  

sql select * from $stm
print ===>rows $rows, data $data01
if $rows != 1 then
  return -1
endi  
if $data01 != 100 then
  return -1
endi  


