forked from gupta-suyash/cs451-551-fall24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rollback.py
48 lines (32 loc) · 1.2 KB
/
test_rollback.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
from lstore.db import Database
from lstore.query import Query
from lstore.transaction import Transaction
from lstore.transaction_worker import TransactionWorker
from random import choice, randint, sample, seed
def main():
db = Database()
db.open('./CS451')
# Getting the existing Grades table
grades_table = db.create_table('Grades', 5, 0)
query = Query(grades_table)
keys = []
records = {}
for i in range(0, 10):
key = 92106429 + i
keys.append(key)
records[key] = [key, randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20), randint(i * 20, (i + 1) * 20)]
record = [0, 1, 2, 3, 4]
transaction = Transaction()
worker = TransactionWorker()
transaction.add_query(query.insert, grades_table, *record)
transaction.add_query(query.select, grades_table, record[0], 0, [1, 1, 1, 1, 1])
transaction.add_query(query.insert, grades_table, *record)
worker.add_transaction(transaction)
worker.run()
worker.join()
print(query.select(0, 0, [1, 1, 1, 1, 1]))
print(transaction.logs)
print(transaction.delete_logs)
print(transaction.update_logs)
if __name__ == "__main__":
main()