@@ -910,6 +910,164 @@ function tests.test_max_memory_usage()
910910 print (" PASS: test_max_memory_usage" )
911911end
912912
913+ function tests .test_sync_wal ()
914+ local path = " ./test_db_sync_wal"
915+ cleanup_db (path )
916+
917+ local db = tidesdb .TidesDB .open (path , {
918+ log_level = tidesdb .LogLevel .LOG_WARN ,
919+ })
920+ local cf_config = tidesdb .default_column_family_config ()
921+ cf_config .sync_mode = tidesdb .SyncMode .SYNC_NONE
922+ db :create_column_family (" test_cf" , cf_config )
923+ local cf = db :get_column_family (" test_cf" )
924+
925+ -- Write some data
926+ local txn = db :begin_txn ()
927+ txn :put (cf , " key1" , " value1" )
928+ txn :put (cf , " key2" , " value2" )
929+ txn :commit ()
930+ txn :free ()
931+
932+ -- Manually sync WAL
933+ cf :sync_wal ()
934+
935+ -- Verify data is still readable after sync
936+ local read_txn = db :begin_txn ()
937+ local v1 = read_txn :get (cf , " key1" )
938+ local v2 = read_txn :get (cf , " key2" )
939+ assert_eq (v1 , " value1" , " key1 should be readable after sync_wal" )
940+ assert_eq (v2 , " value2" , " key2 should be readable after sync_wal" )
941+ read_txn :free ()
942+
943+ db :drop_column_family (" test_cf" )
944+ db :close ()
945+ cleanup_db (path )
946+ print (" PASS: test_sync_wal" )
947+ end
948+
949+ function tests .test_purge_cf ()
950+ local path = " ./test_db_purge_cf"
951+ cleanup_db (path )
952+
953+ local db = tidesdb .TidesDB .open (path , {
954+ log_level = tidesdb .LogLevel .LOG_WARN ,
955+ })
956+ db :create_column_family (" test_cf" )
957+ local cf = db :get_column_family (" test_cf" )
958+
959+ -- Write some data
960+ local txn = db :begin_txn ()
961+ for i = 1 , 10 do
962+ txn :put (cf , string.format (" key:%04d" , i ), string.format (" value:%04d" , i ))
963+ end
964+ txn :commit ()
965+ txn :free ()
966+
967+ -- Purge column family (synchronous flush + compaction)
968+ cf :purge ()
969+
970+ -- Verify data is still readable after purge
971+ local read_txn = db :begin_txn ()
972+ local v1 = read_txn :get (cf , " key:0001" )
973+ local v10 = read_txn :get (cf , " key:0010" )
974+ assert_eq (v1 , " value:0001" , " key:0001 should be readable after purge_cf" )
975+ assert_eq (v10 , " value:0010" , " key:0010 should be readable after purge_cf" )
976+ read_txn :free ()
977+
978+ -- After purge, flushing and compacting should be done
979+ assert_eq (cf :is_flushing (), false , " should not be flushing after purge" )
980+ assert_eq (cf :is_compacting (), false , " should not be compacting after purge" )
981+
982+ db :drop_column_family (" test_cf" )
983+ db :close ()
984+ cleanup_db (path )
985+ print (" PASS: test_purge_cf" )
986+ end
987+
988+ function tests .test_purge_db ()
989+ local path = " ./test_db_purge_db"
990+ cleanup_db (path )
991+
992+ local db = tidesdb .TidesDB .open (path , {
993+ log_level = tidesdb .LogLevel .LOG_WARN ,
994+ })
995+ db :create_column_family (" cf_a" )
996+ db :create_column_family (" cf_b" )
997+ local cf_a = db :get_column_family (" cf_a" )
998+ local cf_b = db :get_column_family (" cf_b" )
999+
1000+ -- Write data to both CFs
1001+ local txn = db :begin_txn ()
1002+ txn :put (cf_a , " a_key1" , " a_value1" )
1003+ txn :put (cf_b , " b_key1" , " b_value1" )
1004+ txn :commit ()
1005+ txn :free ()
1006+
1007+ -- Purge entire database
1008+ db :purge ()
1009+
1010+ -- Verify data is still readable
1011+ local read_txn = db :begin_txn ()
1012+ local va = read_txn :get (cf_a , " a_key1" )
1013+ local vb = read_txn :get (cf_b , " b_key1" )
1014+ assert_eq (va , " a_value1" , " cf_a key should be readable after db purge" )
1015+ assert_eq (vb , " b_value1" , " cf_b key should be readable after db purge" )
1016+ read_txn :free ()
1017+
1018+ db :drop_column_family (" cf_a" )
1019+ db :drop_column_family (" cf_b" )
1020+ db :close ()
1021+ cleanup_db (path )
1022+ print (" PASS: test_purge_db" )
1023+ end
1024+
1025+ function tests .test_get_db_stats ()
1026+ local path = " ./test_db_db_stats"
1027+ cleanup_db (path )
1028+
1029+ local db = tidesdb .TidesDB .open (path , {
1030+ log_level = tidesdb .LogLevel .LOG_WARN ,
1031+ })
1032+ db :create_column_family (" cf_a" )
1033+ db :create_column_family (" cf_b" )
1034+ local cf_a = db :get_column_family (" cf_a" )
1035+ local cf_b = db :get_column_family (" cf_b" )
1036+
1037+ -- Write some data
1038+ local txn = db :begin_txn ()
1039+ txn :put (cf_a , " key1" , " value1" )
1040+ txn :put (cf_b , " key2" , " value2" )
1041+ txn :commit ()
1042+ txn :free ()
1043+
1044+ -- Get database-level stats
1045+ local db_stats = db :get_db_stats ()
1046+
1047+ -- Verify fields exist and have sensible values
1048+ assert_true (db_stats .num_column_families >= 2 , " should have at least 2 column families" )
1049+ assert_true (db_stats .total_memory > 0 , " total_memory should be > 0" )
1050+ assert_true (db_stats .resolved_memory_limit > 0 , " resolved_memory_limit should be > 0" )
1051+ assert_true (db_stats .memory_pressure_level >= 0 , " memory_pressure_level should be >= 0" )
1052+ assert_true (db_stats .global_seq >= 0 , " global_seq should be >= 0" )
1053+ assert_true (db_stats .flush_queue_size >= 0 , " flush_queue_size should be >= 0" )
1054+ assert_true (db_stats .compaction_queue_size >= 0 , " compaction_queue_size should be >= 0" )
1055+ assert_true (db_stats .total_sstable_count >= 0 , " total_sstable_count should be >= 0" )
1056+ assert_true (db_stats .total_data_size_bytes >= 0 , " total_data_size_bytes should be >= 0" )
1057+ assert_true (db_stats .num_open_sstables >= 0 , " num_open_sstables should be >= 0" )
1058+ assert_true (db_stats .txn_memory_bytes ~= nil , " txn_memory_bytes should exist" )
1059+ assert_true (db_stats .total_memtable_bytes ~= nil , " total_memtable_bytes should exist" )
1060+ assert_true (db_stats .total_immutable_count >= 0 , " total_immutable_count should be >= 0" )
1061+ assert_true (db_stats .flush_pending_count >= 0 , " flush_pending_count should be >= 0" )
1062+ assert_true (db_stats .available_memory ~= nil , " available_memory should exist" )
1063+
1064+ db :drop_column_family (" cf_a" )
1065+ db :drop_column_family (" cf_b" )
1066+ db :close ()
1067+ cleanup_db (path )
1068+ print (" PASS: test_get_db_stats" )
1069+ end
1070+
9131071-- Run all tests
9141072local function run_tests ()
9151073 print (" Running TidesDB Lua tests..." )
0 commit comments