# Copyright 2023 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

=> DBGInvoke __clean_up_region()
=> DBGInvoke __enable_schema_sync_service('false')

=> DBGInvoke __drop_tidb_table(default, test)
=> DBGInvoke __drop_tidb_db(db3)
=> DBGInvoke __drop_tidb_db(db4)
=> DBGInvoke __drop_tidb_db(db5)
=> DBGInvoke __refresh_schemas()



# Mock test keep table name but use DatabaseTiFlash,
# can NOT create two tables with the same name, or they will
# share the same data path
=> DBGInvoke __mock_tidb_db(db3)
=> DBGInvoke __mock_tidb_db(db4)
=> DBGInvoke __mock_tidb_table(db3, test3, 'col_1 String')
=> DBGInvoke __mock_tidb_table(db4, test, 'col_1 String')
=> DBGInvoke __refresh_schemas()
=> DBGInvoke __refresh_mapped_table_schema(db3, test3)
=> DBGInvoke __refresh_mapped_table_schema(db4, test)
=> select tidb_name from system.databases where tidb_name like '%db%' and is_tombstone = 0
┌─tidb_name───┐
│ db3         │
│ db4         │
└─────────────┘

# Reset schema to mock that TiFlash process is stopped
# And then drop database and table in TiDB side
=> DBGInvoke __drop_tidb_db(db3);
=> DBGInvoke __drop_tidb_table(db4, test);
# Mock that TiFlash process starts and sync schema with TiDB
# db3 and db4.test should be tombstoned
=> DBGInvoke __refresh_schemas()

=> select tidb_name from system.databases where tidb_name like '%db%' and is_tombstone = 0
┌─tidb_name────┐
│ db4          │
└──────────────┘
=> DBGInvoke is_tombstone(db4, test)
┌─is_tombstone(db4, test)─┐
│ true                    │
└─────────────────────────┘

# Create db5
=> DBGInvoke __mock_tidb_db(db5)
=> DBGInvoke __refresh_schemas()
=> select tidb_name from system.databases where tidb_name like '%db%' and is_tombstone = 0
┌─tidb_name───┐
│ db4         │
│ db5         │
└─────────────┘
# Reset schema to mock that TiFlash process is stopped
# And then drop databases in TiDB side
=> DBGInvoke __drop_tidb_db(db5);
=> DBGInvoke __drop_tidb_db(db4);
# Mock that TiFlash process starts and sync schema with TiDB
=> DBGInvoke __refresh_schemas()
# db4 and db5 should be tombstoned
=> select tidb_name from system.databases where tidb_name like '%db%' and is_tombstone = 0

# Physical cleanup so that it won't make trouble for other tests
=> DBGInvoke __drop_tidb_table(default, test)
=> DBGInvoke __refresh_schemas()
