#!/bin/bash

# TODO: remove 'sleep' after FLASH-635 is addressed
function cmd_ti_ci_cluster()
{
	local file="${1}"
	local args="${2}"
	shift 6

	local ti="${integrated}/ops/ti.sh"

	"${ti}" -k "${args}" "${file}" stop : fstop : up : sleep 5

	"${ti}" -k "${args}" "${file}" tpch/create 0.01 region : tpch/load 0.01 region : sleep 5
	"${ti}" -k "${args}" "${file}" mysql/nogc : syncing/speed_up : tpch/load 0.01 all : sleep 5 : tpch/tikv all tpch_0_01

	local mapped_db=$("${ti}" -k "${args}" "${file}" ch/mapped_database tpch_0_01)
	local mapped_table=$("${ti}" -k "${args}" "${file}" ch/mapped_table tpch_0_01 lineitem 'false')

	"${ti}" -k "${args}" "${file}" tpch/ch all tpch_0_01 : tpch/db

	"${ti}" -k "${args}" "${file}" verify/rows tpch_0_01 lineitem : tpch/rows
	"${ti}" -k "${args}" "${file}" verify/regions tpch_0_01 lineitem false : verify/consistency tpch_0_01 lineitem
	"${ti}" -k "${args}" "${file}" verify/regions tpch_0_01 lineitem true : verify/consistency tpch_0_01 lineitem

	"${ti}" -k "${args}" "${file}" syncing/test : sleep 3 : syncing/show : ch/queries

	"${ti}" -k "${args}" "${file}" fstop : up
}

set -euo pipefail
cmd_ti_ci_cluster "${@}"
