@@ -529,5 +529,65 @@ def test_compact(self, db, cf):
529529 time .sleep (0.5 )
530530
531531
532+ class TestCheckpoint :
533+ """Tests for checkpoint operations."""
534+
535+ def test_checkpoint_creates_snapshot (self , db , cf , temp_db_path ):
536+ """Test that checkpoint creates a usable snapshot."""
537+ with db .begin_txn () as txn :
538+ txn .put (cf , b"key1" , b"value1" )
539+ txn .put (cf , b"key2" , b"value2" )
540+ txn .commit ()
541+
542+ checkpoint_dir = temp_db_path + "_checkpoint"
543+ try :
544+ db .checkpoint (checkpoint_dir )
545+ assert os .path .isdir (checkpoint_dir )
546+
547+ with tidesdb .TidesDB .open (checkpoint_dir ) as checkpoint_db :
548+ cp_cf = checkpoint_db .get_column_family ("test_cf" )
549+ with checkpoint_db .begin_txn () as txn :
550+ assert txn .get (cp_cf , b"key1" ) == b"value1"
551+ assert txn .get (cp_cf , b"key2" ) == b"value2"
552+ finally :
553+ shutil .rmtree (checkpoint_dir , ignore_errors = True )
554+
555+ def test_checkpoint_existing_dir_raises (self , db , cf , temp_db_path ):
556+ """Test that checkpoint to a non-empty directory raises error."""
557+ with db .begin_txn () as txn :
558+ txn .put (cf , b"key1" , b"value1" )
559+ txn .commit ()
560+
561+ checkpoint_dir = temp_db_path + "_checkpoint"
562+ try :
563+ db .checkpoint (checkpoint_dir )
564+
565+ with pytest .raises (tidesdb .TidesDBError ):
566+ db .checkpoint (checkpoint_dir )
567+ finally :
568+ shutil .rmtree (checkpoint_dir , ignore_errors = True )
569+
570+ def test_checkpoint_independence (self , db , cf , temp_db_path ):
571+ """Test that checkpoint is independent from the live database."""
572+ with db .begin_txn () as txn :
573+ txn .put (cf , b"key1" , b"original" )
574+ txn .commit ()
575+
576+ checkpoint_dir = temp_db_path + "_checkpoint"
577+ try :
578+ db .checkpoint (checkpoint_dir )
579+
580+ with db .begin_txn () as txn :
581+ txn .put (cf , b"key1" , b"modified" )
582+ txn .commit ()
583+
584+ with tidesdb .TidesDB .open (checkpoint_dir ) as checkpoint_db :
585+ cp_cf = checkpoint_db .get_column_family ("test_cf" )
586+ with checkpoint_db .begin_txn () as txn :
587+ assert txn .get (cp_cf , b"key1" ) == b"original"
588+ finally :
589+ shutil .rmtree (checkpoint_dir , ignore_errors = True )
590+
591+
532592if __name__ == "__main__" :
533593 pytest .main ([__file__ , "-v" ])
0 commit comments