16
16
from quixstreams .state .rocksdb .windowed .serialization import append_integer
17
17
18
18
19
- @pytest .fixture
20
- def corrupted_db (tmp_path ):
21
- """
22
- Create a corrupted RocksDB database in a temporary directory.
23
- """
24
- rdict = Rdict (path = tmp_path .as_posix ())
25
- # Write something and flush so that the .sst file is created
26
- rdict [b"key" ] = b"value"
27
- rdict .flush ()
28
- # Delete the .sst file
29
- next (tmp_path .glob ("*.sst" )).unlink ()
30
-
31
-
32
19
class TestRocksDBStorePartition :
33
20
def test_open_db_locked_retries (self , store_partition_factory , executor ):
34
21
db1 = store_partition_factory ("db" )
@@ -83,8 +70,12 @@ def test_open_arbitrary_exception_fails(self, store_partition_factory):
83
70
assert str (raised .value ) == "some exception"
84
71
85
72
def test_db_corrupted_fails_with_no_changelog (
86
- self , store_partition_factory , corrupted_db
73
+ self , store_partition_factory , tmp_path
87
74
):
75
+ # Initialize and corrupt the database by messing with the MANIFEST
76
+ Rdict (path = tmp_path .as_posix ())
77
+ next (tmp_path .glob ("MANIFEST*" )).write_bytes (b"" )
78
+
88
79
with pytest .raises (
89
80
RocksDBCorruptedError ,
90
81
match = (
@@ -95,8 +86,12 @@ def test_db_corrupted_fails_with_no_changelog(
95
86
store_partition_factory (changelog_producer = None )
96
87
97
88
def test_db_corrupted_fails_with_on_corrupted_recreate_false (
98
- self , store_partition_factory , corrupted_db
89
+ self , store_partition_factory , tmp_path
99
90
):
91
+ # Initialize and corrupt the database by messing with the MANIFEST
92
+ Rdict (path = tmp_path .as_posix ())
93
+ next (tmp_path .glob ("MANIFEST*" )).write_bytes (b"" )
94
+
100
95
with pytest .raises (
101
96
RocksDBCorruptedError ,
102
97
match = re .escape (
@@ -107,7 +102,19 @@ def test_db_corrupted_fails_with_on_corrupted_recreate_false(
107
102
):
108
103
store_partition_factory ()
109
104
110
- def test_db_corrupted_recreated (self , store_partition_factory , corrupted_db ):
105
+ def test_db_corrupted_manifest_file (self , store_partition_factory , tmp_path ):
106
+ Rdict (path = tmp_path .as_posix ()) # initialize db
107
+ next (tmp_path .glob ("MANIFEST*" )).write_bytes (b"" ) # write random bytes
108
+
109
+ store_partition_factory (options = RocksDBOptions (on_corrupted_recreate = True ))
110
+
111
+ def test_db_corrupted_sst_file (self , store_partition_factory , tmp_path ):
112
+ rdict = Rdict (path = tmp_path .as_posix ()) # initialize db
113
+ rdict [b"key" ] = b"value" # write something
114
+ rdict .flush () # flush creates .sst file
115
+ rdict .close () # required to release the lock
116
+ next (tmp_path .glob ("*.sst" )).unlink () # delete the .sst file
117
+
111
118
store_partition_factory (options = RocksDBOptions (on_corrupted_recreate = True ))
112
119
113
120
def test_create_and_get_column_family (self , store_partition : RocksDBStorePartition ):
0 commit comments