88from karapace .client import Client
99from karapace .config import set_config_defaults
1010from karapace .key_format import is_key_in_canonical_format
11- from karapace .schema_backup import SchemaBackup , serialize_schema_message
11+ from karapace .schema_backup import SchemaBackup , serialize_record
1212from karapace .utils import Expiration
1313from pathlib import Path
1414from tests .integration .utils .cluster import RegistryDescription
@@ -51,7 +51,7 @@ async def test_backup_get(
5151 }
5252 )
5353 sb = SchemaBackup (config , str (backup_location ))
54- sb .export (serialize_schema_message )
54+ sb .export (serialize_record )
5555
5656 # The backup file has been created
5757 assert os .path .exists (backup_location )
@@ -68,6 +68,43 @@ async def test_backup_get(
6868 assert lines == 1
6969
7070
71+ async def test_backup_restore_and_get_non_schema_topic (
72+ kafka_servers : KafkaServers ,
73+ tmp_path : Path ,
74+ ) -> None :
75+ test_topic_name = new_random_name ("non-schemas" )
76+
77+ config = set_config_defaults (
78+ {
79+ "bootstrap_uri" : kafka_servers .bootstrap_servers ,
80+ "topic_name" : test_topic_name ,
81+ }
82+ )
83+
84+ # Restore from backup
85+ test_data_path = Path ("tests/integration/test_data/" )
86+ restore_location = test_data_path / "test_restore_non_schema_topic_v2.log"
87+ sb = SchemaBackup (config , str (restore_location ))
88+ sb .restore_backup ()
89+
90+ # Get the backup
91+ backup_location = tmp_path / "non_schemas_topic.log"
92+ sb = SchemaBackup (config , str (backup_location ))
93+ sb .export (serialize_record )
94+ # The backup file has been created
95+ assert os .path .exists (backup_location )
96+
97+ restore_file_content = None
98+ with open (restore_location , "r" , encoding = "utf8" ) as fp :
99+ restore_file_content = fp .read ()
100+ backup_file_content = None
101+ with open (backup_location , "r" , encoding = "utf8" ) as fp :
102+ backup_file_content = fp .read ()
103+ assert restore_file_content is not None
104+ assert backup_file_content is not None
105+ assert restore_file_content == backup_file_content
106+
107+
71108def _assert_canonical_key_format (
72109 bootstrap_servers : str ,
73110 schemas_topic : str ,
@@ -86,7 +123,6 @@ def _assert_canonical_key_format(
86123 while raw_msgs :
87124 for _ , messages in raw_msgs .items ():
88125 for message in messages :
89- print (message )
90126 key = json .loads (message .key )
91127 assert is_key_in_canonical_format (key ), f"Not in canonical format: { key } "
92128 raw_msgs = consumer .poll ()
0 commit comments