Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/cases/01-DataTypes/test_datatype_decimal2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ def test_decimal2(self):
Jira: None

History:
- 2025-10-17 Alex Duan Migrated from uncatalog/system-test/2-query/test_decimal1.py
- 2025-10-17 Alex Duan Migrated from uncatalog/system-test/2-query/test_decimal2.py
"""

self.check_decimal_ddl()
Expand Down
289 changes: 266 additions & 23 deletions test/cases/02-Databases/03-Alter/test_db_alter_option.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck, clusterComCheck
from new_test_framework.utils import tdLog, tdSql, sc, clusterComCheck, clusterComCheck, etool
Comment thread
DuanKuanJun marked this conversation as resolved.
Outdated


class TestDatabaseAlterOption:

def setup_class(cls):
tdLog.debug(f"start to execute {__file__}")

def test_database_alter_option(self):
"""Alter all options

1. Create database and inspect all option values.
2. Attempt to alter database with invalid options (expect failure).
3. Alter database with valid options and verify the changes.

Catalog:
- Database:Alter

Since: v3.0.0.0

Labels: common,ci

Jira: None

History:
- 2025-4-30 Simon Guan Migrated from tsim/db/alter_option.sim

"""


#
# ----------------------- sim -------------------
#
def do_sim_case(self):
clusterComCheck.checkDnodes(3)

tdLog.info(f"============= create database")
Expand Down Expand Up @@ -314,3 +297,263 @@ def test_database_alter_option(self):
tdSql.error(f"alter database db precision 'ns'")
tdSql.error(f"alter database db precision 'ys'")
tdSql.error(f"alter database db prec 'xs'")

print("do sim case ........................... [passed]")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The print function is used for logging test progress. It's better to use the project's standard logger, tdLog, for consistency and to allow for better log management (e.g., controlling log levels).

Suggested change
print("do sim case ........................... [passed]")
tdLog.info("do sim case ........................... [passed]")


#
# ----------------------- army -------------------
#
def prepare_database(self):
tdLog.info(f"prepare database")
tdSql.execute("DROP DATABASE IF EXISTS test")
tdSql.execute("CREATE DATABASE IF NOT EXISTS test")
tdSql.execute("USE test")

def check_alter_buffer_size(self):
tdLog.info(f"check alter buffer size")
tdSql.execute("ALTER DATABASE test buffer 789")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 8, '789')
tdSql.error("ALTER DATABASE test buffer 0",expectErrInfo="Invalid option", fullMatched=False)
tdSql.error("ALTER DATABASE test buffer 16385",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_cache_model(self):
tdLog.info(f"check alter cache model")
tdSql.execute("ALTER DATABASE test cachemodel 'last_row'")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 18, "last_row")
tdSql.execute("ALTER DATABASE test cachemodel 'last_value'")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 18, "last_value")
tdSql.execute("ALTER DATABASE test cachemodel 'both'")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 18, "both")
tdSql.execute("ALTER DATABASE test cachemodel 'none'")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 18, "none")

tdSql.error("ALTER DATABASE test cachemodel 'hash_value'",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_cache_size(self):
tdLog.info(f"check alter cache size")
tdSql.execute("ALTER DATABASE test cachesize 777")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 19, '777')

tdSql.error("ALTER DATABASE test cachesize 0",expectErrInfo="Invalid option", fullMatched=False)
tdSql.error("ALTER DATABASE test cachesize 65537",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_min_rows(self):
tdLog.info(f"check alter min rows")
tdSql.execute("ALTER DATABASE test minrows 231")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 11, '231')
tdSql.error("ALTER DATABASE test minrows 5000",expectErrInfo="Invalid database options", fullMatched=False)

tdSql.error("ALTER DATABASE test minrows 9",expectErrInfo="Invalid option", fullMatched=False)
tdSql.error("ALTER DATABASE test minrows 1000001",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_pages(self):
tdLog.info(f"check alter pages")
tdSql.execute("ALTER DATABASE test pages 256")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 10, '256')
tdSql.error("ALTER DATABASE test pages 0",expectErrInfo="Invalid option", fullMatched=False)


def check_alter_wal_level(self):
tdLog.info(f"check alter wal_level")
tdSql.execute("ALTER DATABASE test wal_level 1")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 20, '1')

tdSql.execute("ALTER DATABASE test wal_level 2")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 20, '2')

tdSql.error("ALTER DATABASE test wal_level 3",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_fsync(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The method name check_alter_fsync is inconsistent with the log message inside it, which refers to wal_fsync_period. To improve code readability and maintainability, the method name should accurately reflect the option it is testing. Please rename it to check_alter_wal_fsync_period and update the call site at line 492 accordingly.

Suggested change
def check_alter_fsync(self):
def check_alter_wal_fsync_period(self):

tdLog.info(f"check alter wal_fsync_period")
tdSql.execute("ALTER DATABASE test wal_fsync_period 1000")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 21, '1000')

tdSql.error("ALTER DATABASE test wal_fsync_period 180001",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_stt_trigger(self):
tdLog.info(f"check alter stt_trigger")
tdSql.execute("ALTER DATABASE test stt_trigger 5")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 24, '5')


tdSql.error("ALTER DATABASE test stt_trigger 18",expectErrInfo="Invalid option", fullMatched=False)

def check_alter_wal_retention_period(self):
tdLog.info(f"check alter wal_retention_period")
tdSql.execute("ALTER DATABASE test wal_retention_period 3600")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 22, '3600')


def check_alter_wal_retention_size(self):
tdLog.info(f"check alter wal_retention_size")
tdSql.execute("ALTER DATABASE test wal_retention_size 1000")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 23, '1000')

def check_alter_ss_keeplocal(self):
tdLog.info(f"check alter ss_keeplocal")
tdSql.execute("ALTER DATABASE test ss_keeplocal 2880m")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 30, '2880m')

def check_alter_ss_compact(self):
tdLog.info(f"check alter ss_compact")
tdSql.execute("ALTER DATABASE test ss_compact 1")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 31, '1')

tdSql.execute("ALTER DATABASE test ss_compact 0")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 31, '0')

tdSql.error("ALTER DATABASE test ss_compact 2",expectErrInfo="Invalid option", fullMatched=False)


def check_alter_keep_time_offset(self):
tdLog.info(f"check alter keep_time_offset")
tdSql.execute("ALTER DATABASE test keep_time_offset 22")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 28, '22')

def check_alter_compact_interval(self):
tdLog.info(f"check alter compact_interval")
tdSql.execute("ALTER DATABASE test compact_interval 1800d")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 34, '1800d')

tdSql.execute("ALTER DATABASE test compact_interval 1h")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 34, '1h')

def check_alter_compact_time_offset(self):
tdLog.info(f"check alter compact_time_offset")
tdSql.execute("ALTER DATABASE test compact_time_offset 18")
tdSql.query("select * from information_schema.ins_databases")
tdSql.checkData(2, 36, '18h')


def check_alter_unsupport_option(self):
tdLog.info(f"check alter unsupport option")
tdSql.error("ALTER DATABASE test COMP 1",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test DURATION 1",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test maxrows 1",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test encrypt_algorithm 'sm4'",expectErrInfo="Encryption is not allowed to be changed after database is created", fullMatched=False)
tdSql.error("ALTER DATABASE test vgroups 4",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test single_stable 1",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test schemaless 1",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test table_prefix 't'",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test table_suffix 't'",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test dnodes 'dnode1'",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test precision 'ms'",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test strict 'on'",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test pagesize 4096",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test tsdb_pagesize 4096",expectErrInfo="syntax error", fullMatched=False)
tdSql.error("ALTER DATABASE test retentions '1d:1d'",expectErrInfo="syntax error", fullMatched=False)

# run
def do_army_case(self):
tdLog.debug(f"start to excute {__file__}")

# prepare database
self.prepare_database()

# check alter buffer size
self.check_alter_buffer_size()

# check alter cache model
self.check_alter_cache_model()

# check alter cache size
self.check_alter_cache_size()

# check alter min rows
self.check_alter_min_rows()

# check alter pages
self.check_alter_pages()

# check alter wal_level
self.check_alter_wal_level()

# check alter wal_fsync_period
self.check_alter_fsync()

# check alter stt_trigger
self.check_alter_stt_trigger()

# check alter wal_retention_period
self.check_alter_wal_retention_period()

# check alter wal_retention_size
self.check_alter_wal_retention_size()

# check alter ss_keeplocal
self.check_alter_ss_keeplocal()

# check alter ss_compact
self.check_alter_ss_compact()

# check alter keep_time_offset
self.check_alter_keep_time_offset()

# check alter compact_interval
self.check_alter_compact_interval()

# check alter compact_time_offset
self.check_alter_compact_time_offset()

# check alter unsupport option
self.check_alter_unsupport_option()

print("do army case .......................... [passed]")
Comment thread
DuanKuanJun marked this conversation as resolved.

def test_db_alter_option(self):
"""Alter all options

1. Create database and inspect all option values.
2. Attempt to alter database with invalid options (expect failure).
3. Alter database with valid options and verify the changes.
4. Check alter buffer size
5. Check alter cache model
6. Check alter cache size
7. Check alter min rows
8. Check alter pages
9. Check alter wal_level
10. Check alter wal_fsync_period
11. Check alter stt_trigger
12. Check alter wal_retention_period
13. Check alter wal_retention_size
14. Check alter ss_keeplocal
15. Check alter ss_compact
16. Check alter keep_time_offset
17. Check alter compact_interval
18. Check alter compact_time_offset
19. Check alter unsupport option

Since: v3.0.0.0

Labels: common,ci

Jira: None

History:
- 2025-10-20 Alex Duan Migrated from uncatalog/army/alter/test_alter_db_option.py
- 2025-04-30 Simon Guan Migrated from tsim/db/alter_option.sim

"""
self.do_sim_case()
self.do_army_case()

Loading
Loading