-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_wal.py
54 lines (45 loc) · 2.13 KB
/
test_wal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest, os
from wal import Wal
class WalTest(unittest.TestCase):
def test_wal_dir_created_or_exists(self):
Wal()
self.assertTrue(os.path.exists(Wal.WAL_DIR))
def test_wal_segment_created_or_exists(self):
first_segment_file = "00000000000000000001"
expected_segment_path = "{0}/{1}".format(Wal.WAL_DIR,first_segment_file)
Wal().write({"data":"demo segment"})
self.assertTrue(os.path.exists(expected_segment_path))
def test_wal_verify_segment_contents(self):
first_segment_file = "00000000000000000001"
expected_snapshot_memetable = {'00000000000000000001': 0}
test_data = {"data":"demo segment"}
expected_result = {'00000000000000000001': {'OP': 'PUT','SNAP': '00000000000000000001','data': 'demo segment'}}
expected_segment_path = "{0}/{1}".format(Wal.WAL_DIR,first_segment_file)
w = Wal()
w.write(test_data)
self.assertTrue(os.path.exists(expected_segment_path))
self.assertDictEqual(w.read(), expected_result)
self.assertDictEqual(w.snap_memtable, expected_snapshot_memetable)
def test_wal_verify_adding_two_segment(self):
first_segment_file = "00000000000000000001"
expected_snapshot_memetable = {'00000000000000000001': 0}
test_data = {"data":"demo segment"}
expected_result = {'00000000000000000001': {'OP': 'PUT','SNAP': '00000000000000000001','data': 'demo segment'}}
expected_segment_path = "{0}/{1}".format(Wal.WAL_DIR,first_segment_file)
w = Wal()
w.write(test_data)
test_data = {"data":"demo segment"}
w.write(test_data)
# self.assertTrue(os.path.exists(expected_segment_path))
# self.assertDictEqual(w.read(), expected_result)
# self.assertDictEqual(w.snap_memtable, expected_snapshot_memetable)
def test_cleanup_wal(self):
Wal().cleanup_wal()
self.assertFalse(os.path.exists(Wal.WAL_DIR))
def tearDown(self) -> None:
Wal().cleanup_wal()
@classmethod
def tearDownClass(cls):
Wal().cleanup_wal()
if __name__ == '__main__':
unittest.main()