def test_build_push_memtable(): lsm = LSMStorage(72, 4) mem_table = lsm.build_memtable("table1") rec1 = Record(1, "name1", "412-760-0285") rec2 = Record(1, "name2", "412-760-0285") #should overwrite rec1 rec3 = Record(2, "name3", "412-760-0285") rec4 = Record(3, "name4", "412-760-0285") rec5 = Record(4, "name5", "412-760-0285") rec6 = Record(5, "name6sd", "413-760-0285") rec7 = Record(6, "name7sdf", "413-760-0285") rec8 = Record(7, "name1", "413-760-0285") rec9 = Record(8, "name1", "412-760-0285") mem_table.add_record(rec1) mem_table.add_record(rec2) mem_table.add_record(rec3) mem_table.add_record(rec4) mem_table.add_record(rec5) mem_table.add_record(rec6) mem_table.add_record(rec7) mem_table.add_record(rec8) print("mem_table.is_full: "+str(mem_table.is_full())+" (should be false)") mem_table.add_record(rec9) print("mem_table.is_full: "+str(mem_table.is_full())+" (should be true)") lsm.push_memtable(mem_table) mem_table = lsm.build_memtable("table1") rec1 = Record(1, "name1", "412-760-0285") rec2 = Record(2, "name222", "412-760-0285") rec3 = Record(3, "name122", "412-760-0285") mem_table.add_record(rec1) mem_table.add_record(rec2) mem_table.add_record(rec3) lsm.push_memtable(mem_table)
def test_write_to_L0(): table_name = "test_table" lsm = LSMStorage(72, 4) lsm.build_memtable(table_name) records = get_8_records(True) lower, upper = records[0].id, records[-1].id print("lower: "+str(lower)) print("upper: "+str(upper)) lsm.write_records_to_level_SST(records, table_name, lower, upper, "L0")
def test_second_L0_write(): table_name = "test_table" lsm = LSMStorage(72, 4) lsm.build_memtable(table_name) records = get_8_records(True) lower, upper = records[0].id, records[-1].id lsm.write_records_to_level_SST(records, table_name, lower, upper, "L0") recs2 = get_8_records(True)[0:4] recs2[0].client_name = "newname1" recs2[1].client_name = "newname2" lower, upper = recs2[0].id, recs2[-1].id lsm.write_records_to_level_SST(recs2, table_name, lower, upper, "L0")
def test_uneven_L0_write(): table_name = "test_table" lsm = LSMStorage(72, 4) lsm.build_memtable(table_name) records = get_8_records(True)[0:-1] lower, upper = records[0].id, records[-1].id print("lower: "+str(lower)) print("upper: "+str(upper)) lsm.write_records_to_level_SST(records, table_name, lower, upper, "L0") f = open("storage/test_table/L0/SST0/3_1", "rb+") b_arr2 = bytearray(f.read()) rec_id = int.from_bytes(b_arr2[0:4], byteorder="little", signed=True) print(rec_id) name = b_arr2[4:20].decode() print(name) phone = b_arr2[20:32].decode() print(phone)
def test_retrieve_in_L0(): table_name = "test_table" lsm = LSMStorage(72, 4) lsm.build_memtable(table_name) records = get_8_records(True) lower, upper = records[0].id, records[-1].id lsm.write_records_to_level_SST(records, table_name, lower, upper, "L0") recs2 = get_8_records(True)[0:4] recs2[0].client_name = "newname1" recs2[1].client_name = "newname2" lower, upper = recs2[0].id, recs2[-1].id lsm.write_records_to_level_SST(recs2, table_name, lower, upper, "L0") rec, ss = lsm.get_record(1, table_name) print(rec) rec2, ss2 = lsm.get_record(4, table_name) print(rec2)
def test_lsm(self): lsm = LSMStorage(72, 4) mem_table = lsm.build_memtable("table1") rec1 = Record(1, "name1", "412-760-0285") rec2 = Record(1, "name2", "412-760-0285") #should overwrite rec1 rec3 = Record(2, "name1", "412-760-0285") rec4 = Record(3, "name1", "412-760-0285") rec5 = Record(4, "name1", "412-760-0285") rec6 = Record(5, "name1", "413-760-0285") rec7 = Record(6, "name1", "413-760-0285") rec8 = Record(7, "name1", "413-760-0285") rec9 = Record(8, "name1", "412-760-0285") mem_table.add_record(rec1) mem_table.add_record(rec2) mem_table.add_record(rec3) mem_table.add_record(rec4) mem_table.add_record(rec5) mem_table.add_record(rec6) mem_table.add_record(rec7) mem_table.add_record(rec8) self.assertFalse(mem_table.is_full()) mem_table.add_record(rec9) self.assertTrue(mem_table.is_full())