Ejemplo n.º 1
0
 def test_commit(self):
     # Sanity check
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '0')
Ejemplo n.º 2
0
 def test_abort(self):
     # Sanity check
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t0.abort(USER), 'User Abort')
     self.assertEqual(store.get('a'), None)
Ejemplo n.º 3
0
 def test_staff_multiple_write_abort(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_put('a', '1'), 'Success') 
     self.assertEqual(t0.perform_put('a', '2'), 'Success') 
     self.assertEqual(t0.perform_put('a', '3'), 'Success')
     self.assertEqual(t0.abort(USER), 'User Abort')
     self.assertEqual(store.get('a'), None) 
Ejemplo n.º 4
0
 def test_staff_multiple_write_commit(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_put('a', '1'), 'Success') 
     self.assertEqual(t0.perform_put('a', '2'), 'Success') 
     self.assertEqual(t0.perform_put('a', '3'), 'Success')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '3')
Ejemplo n.º 5
0
 def test_abort(self):
     # Sanity check
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t0.abort(USER), 'User Abort')
     self.assertEqual(store.get('a'), None)
Ejemplo n.º 6
0
 def test_commit(self):
     # Sanity check
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '0')
Ejemplo n.º 7
0
 def test_ww(self):
     # Should pass after 1.1
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t1.perform_put('a', '1'), None)
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '0')
Ejemplo n.º 8
0
 def test_ww(self):
     # Should pass after 1.1
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t1.perform_put('a', '1'), None)
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '0')
Ejemplo n.º 9
0
 def test_abort_queue(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t1.perform_get('a'), None)
     self.assertEqual(t1.perform_put('b', '1'), 'Success')
     self.assertEqual(t1.abort(USER), 'User Abort')
     self.assertEqual(store.get('a'), '0')
     self.assertEqual(store.get('b'), None)
Ejemplo n.º 10
0
 def test_multiple_read(self):
     # Sanity check
     lock_table = {}
     store = InMemoryKVStore()
     store.put('a', '0')
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t1.perform_get('a'), '0')
     self.assertEqual(t2.perform_get('a'), '0')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.abort(USER), 'User Abort')
     self.assertEqual(t2.perform_get('a'), '0')
Ejemplo n.º 11
0
 def test_multiple_read(self):
     # Sanity check
     lock_table = {}
     store = InMemoryKVStore()
     store.put('a', '0')
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t1.perform_get('a'), '0')
     self.assertEqual(t2.perform_get('a'), '0')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.abort(USER), 'User Abort')
     self.assertEqual(t2.perform_get('a'), '0')
Ejemplo n.º 12
0
    def test_staff_deadlock_two_cycles(self):
        lock_table = {}
        store = InMemoryKVStore()
        t2 = TransactionHandler(lock_table, 2, store)
        t4 = TransactionHandler(lock_table, 4, store)
        t6 = TransactionHandler(lock_table, 6, store)
        t8 = TransactionHandler(lock_table, 8, store)
        coordinator = TransactionCoordinator(lock_table)
        self.assertEqual(coordinator.detect_deadlocks(), None)
        # t2 has S lock on a; t4 wants X lock
        self.assertEqual(t2.perform_get('a'), 'No such key')
        self.assertEqual(t4.perform_put('a', 'a1'), None)
        # t4 has S lock on b; t2 wants X lock
        self.assertEqual(t4.perform_get('b'), 'No such key')
        self.assertEqual(t2.perform_put('b', 'b1'), None)
        # t6 has S lock on a; t8 wants X lock
        self.assertEqual(t6.perform_get('c'), 'No such key')
        self.assertEqual(t8.perform_put('c', 'c1'), None)
        # t8 has S lock on b; t6 wants X lock
        self.assertEqual(t8.perform_get('d'), 'No such key')
        self.assertEqual(t6.perform_put('d', 'd1'), None)

        abort_id = coordinator.detect_deadlocks()
        self.assertTrue(abort_id == 2 or abort_id == 4 or abort_id == 6 or abort_id == 8)

        abort_id = coordinator.detect_deadlocks()
        self.assertTrue(abort_id == 2 or abort_id == 4 or abort_id == 6 or abort_id == 8)
Ejemplo n.º 13
0
 def test_deadlock_rw_rw(self):
     # Should pass after 2
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     coordinator = TransactionCoordinator(lock_table)
     # self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     # self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t0.perform_get('b'), 'No such key')
     self.assertEqual(t0.perform_put('a', 'a0'), 'Success')
     self.assertEqual(t0.perform_put('b', 'b0'), 'Success')
     # self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t0.commit(), 'Transaction Completed')
     # self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t1.perform_get('a'), 'a0')  # T1 R(a)
     self.assertEqual(t2.perform_get('b'), 'b0')  # T2 R(b)
     # self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t1.perform_put('b', 'b1'), None)  # T1 W(b)
     # self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t1.check_lock(), None)
     self.assertEqual(t2.perform_put('a', 'a1'), None)  # T2 W(a)
     abort_id = coordinator.detect_deadlocks()
     self.assertTrue(abort_id == 1 or abort_id == 2)
Ejemplo n.º 14
0
 def test_multi_deadlock(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     t3 = TransactionHandler(lock_table, 3, store)
     t4 = TransactionHandler(lock_table, 4, store)
     coordinator = TransactionCoordinator(lock_table)
     self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t0.perform_put('a', 'apple'), 'Success')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.perform_get('a'), 'apple')
     self.assertEqual(t2.perform_get('a'), 'apple')
     self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t1.perform_put('a', 'banana'), None)
     self.assertEqual(t2.perform_put('a', 'pear'), None)
     self.assertEqual(t3.perform_put('a', 'cherry'), None)
     self.assertEqual(t4.perform_put('a', 'orange'), None)
     aid = coordinator.detect_deadlocks()
     self.assertTrue(aid == 2 or aid == 1)
     self.assertEqual(t2.check_lock(), None)
     self.assertEqual(t1.abort(USER), 'User Abort')
     self.assertEqual(t2.check_lock(), 'Success')
     self.assertEqual(t2.perform_get('a'), 'pear')
     self.assertEqual(t3.check_lock(), None)
     self.assertEqual(t4.check_lock(), None)
     aa = coordinator.detect_deadlocks()
     self.assertEqual(aa, None)
Ejemplo n.º 15
0
    def test_staff_block_read_write_read(self):
        lock_table = {}
        store = InMemoryKVStore()
        t0 = TransactionHandler(lock_table, 0, store)
        t1 = TransactionHandler(lock_table, 1, store)
        t2 = TransactionHandler(lock_table, 2, store)
        t3 = TransactionHandler(lock_table, 3, store)

        self.assertEqual(t0.perform_put('a', '0'), 'Success')

        self.assertEqual(t1.perform_get('a'), None)
        self.assertEqual(t2.perform_put('a', '2'), None)  
        self.assertEqual(t3.perform_get('a'), None)

        self.assertEqual(t0.commit(), 'Transaction Completed')

        self.assertEqual(t1.check_lock(), '0')
        self.assertEqual(t2.check_lock(), None)
        self.assertEqual(t3.check_lock(), None)

        self.assertEqual(t1.commit(), 'Transaction Completed')

        self.assertEqual(t2.check_lock(), 'Success')
        self.assertEqual(t3.check_lock(), None)

        self.assertEqual(t2.commit(), 'Transaction Completed')

        self.assertEqual(t3.check_lock(), '2')
Ejemplo n.º 16
0
 def test_1_thread_on_multiple_keys(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     t3 = TransactionHandler(lock_table, 3, store)
     self.assertEqual(t0.perform_get('apple'), 'No such key')
     self.assertEqual(t1.perform_get('apple'), 'No such key')
     self.assertEqual(t2.perform_get('apple'), 'No such key')
     self.assertEqual(t0.perform_put('apple', '11'), None)
     self.assertEqual(t0.check_lock(), None)
     self.assertEqual(t1.commit(), 'Transaction Completed')
     self.assertEqual(t0.check_lock(), None)
     self.assertEqual(t2.commit(), 'Transaction Completed')
     self.assertEqual(t0.check_lock(), "Success")
     self.assertEqual(t0.perform_get('apple'), '11')
     self.assertEqual(t0.perform_put('apple', "10000"), 'Success')
     self.assertEqual(t0.perform_get('apple'), '10000')
     self.assertEqual(t0.perform_put("banana", '22'), "Success")
     self.assertEqual(t0.perform_get('banana'), '22')
     self.assertEqual(t1.perform_get('apple'), None)
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.check_lock(), '10000')
     self.assertEqual(t1.perform_get("apple"), "10000")
     self.assertEqual(t2.perform_get("apple"), "10000")
     self.assertEqual(t3.perform_get("apple"), "10000")
Ejemplo n.º 17
0
 def test_staff_read_x_lock(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_put('a', '1'), 'Success') 
     self.assertEqual(t0.perform_get('a'), '1') 
     self.assertEqual(t0.perform_put('a', '3'), 'Success')
Ejemplo n.º 18
0
 def test_rwr(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t1.perform_put('a', '1'), None)
     self.assertEqual(t2.perform_get('a'), None)
Ejemplo n.º 19
0
 def test_upgrade_in_put(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_get('apple'), 'No such key')
     self.assertEqual(t1.perform_put('apple', '333'), None)
     self.assertEqual(t0.perform_put('apple', 'aaa'), 'Success')
     self.assertEqual(t0.perform_get('apple'), 'aaa')
Ejemplo n.º 20
0
 def test_commit_abort_commit(self):
     # Should pass after 1.2
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.perform_get('a'), '0')
     self.assertEqual(t1.perform_put('a', '1'), 'Success')
     self.assertEqual(t1.perform_get('a'), '1')
     self.assertEqual(t1.abort(USER), 'User Abort')
     self.assertEqual(t2.perform_get('a'), '0')
     self.assertEqual(t2.perform_put('a', '2'), 'Success')
     self.assertEqual(t2.perform_get('a'), '2')
     self.assertEqual(t2.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '2')
Ejemplo n.º 21
0
 def test_commit_abort_commit(self):
     # Should pass after 1.2
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.perform_get('a'), '0')
     self.assertEqual(t1.perform_put('a', '1'), 'Success')
     self.assertEqual(t1.perform_get('a'), '1')
     self.assertEqual(t1.abort(USER), 'User Abort')
     self.assertEqual(t2.perform_get('a'), '0')
     self.assertEqual(t2.perform_put('a', '2'), 'Success')
     self.assertEqual(t2.perform_get('a'), '2')
     self.assertEqual(t2.commit(), 'Transaction Completed')
     self.assertEqual(store.get('a'), '2')
Ejemplo n.º 22
0
 def test_deadlock_identical(self):
     # Should pass after 2
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t2 = TransactionHandler(lock_table, 2, store)
     coordinator = TransactionCoordinator(lock_table)
     self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t0.perform_put('a', 'a0'), 'Success')
     self.assertEqual(t0.perform_put('b', 'b0'), 'Success')
     self.assertEqual(t2.perform_get('a'), None)
     self.assertEqual(t2.perform_get('b'), None)
Ejemplo n.º 23
0
 def test_unlock_rrw(self):
     # Should pass after 1.3
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')        # T0 R(a)
     self.assertEqual(t1.perform_get('a'), 'No such key')        # T1 R(a)
     self.assertEqual(t0.perform_put('a', '0'), None)            # T0 W(a)
     self.assertEqual(t0.check_lock(), None)
     self.assertEqual(t0.check_lock(), None)
     self.assertEqual(t1.commit(), 'Transaction Completed')
     self.assertEqual(t0.check_lock(), 'Success')
     self.assertEqual(t0.perform_get('a'), '0')
Ejemplo n.º 24
0
 def test_unlock_rrr(self):
     # Should pass after 1.3
     lock_table = {}
     store = InMemoryKVStore()
     coordinator = TransactionCoordinator(lock_table)
     self.assertEqual(coordinator.detect_deadlocks(), None)
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     t3 = TransactionHandler(lock_table, 3, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')        # T0 R(a)
     self.assertEqual(t1.perform_get('a'), 'No such key')        # T1 R(a)
     self.assertEqual(t2.perform_get('a'), 'No such key')
     self.assertEqual(t3.perform_put('a', '0'), None)            # T0 W(a)
     self.assertEqual(coordinator.detect_deadlocks(), None)
Ejemplo n.º 25
0
    def test_staff_lock_upgrade(self):
        lock_table = {}
        store = InMemoryKVStore()
        t0 = TransactionHandler(lock_table, 0, store)
        t1 = TransactionHandler(lock_table, 1, store)
        t2 = TransactionHandler(lock_table, 2, store)
        self.assertEqual(t0.perform_get('a'), 'No such key')
        self.assertEqual(t1.perform_get('a'), 'No such key')
        self.assertEqual(t2.perform_put('a', '1'), None)
        self.assertEqual(t0.perform_put('a', '1'), None)

        self.assertEqual(t1.commit(), 'Transaction Completed')
        self.assertEqual(t0.check_lock(), 'Success')

        self.assertEqual(t0.commit(), 'Transaction Completed')
        self.assertEqual(t2.check_lock(), 'Success')
Ejemplo n.º 26
0
    def test_staff_deadlock_ww_rw(self):
        lock_table = {}
        store = InMemoryKVStore()
        t0 = TransactionHandler(lock_table, 0, store)
        t1 = TransactionHandler(lock_table, 1, store)
        coordinator = TransactionCoordinator(lock_table)
        self.assertEqual(coordinator.detect_deadlocks(), None)
        # t0 has X lock on a; t1 wants X lock
        self.assertEqual(t0.perform_put('a', 'a0'), 'Success')
        self.assertEqual(t1.perform_put('a', 'a1'), None)
        # t1 has S lock on b; t0 wants X lock
        self.assertEqual(t1.perform_get('b'), 'No such key')
        self.assertEqual(t0.perform_put('b', 'b0'), None)

        abort_id = coordinator.detect_deadlocks()
        self.assertTrue(abort_id == 0 or abort_id == 1)
Ejemplo n.º 27
0
    def test_staff_deadlock_upgrade(self):
        lock_table = {}
        store = InMemoryKVStore()
        t2 = TransactionHandler(lock_table, 2, store)
        t4 = TransactionHandler(lock_table, 4, store)
        coordinator = TransactionCoordinator(lock_table)
        self.assertEqual(coordinator.detect_deadlocks(), None)
        # t2, t4 has S lock on a; t2 wants X lock
        self.assertEqual(t2.perform_get('a'), 'No such key')
        self.assertEqual(t4.perform_get('a'), 'No such key')
        self.assertEqual(t2.perform_put('a', 'a1'), None)
        # t4 now wants X lock
        self.assertEqual(t4.perform_put('a', 'a2'), None)

        abort_id = coordinator.detect_deadlocks()
        self.assertTrue(abort_id == 2 or abort_id == 4)
Ejemplo n.º 28
0
 def test_deadlock_gap_queue(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     t3 = TransactionHandler(lock_table, 3, store)
     coordinator = TransactionCoordinator(lock_table)
     self.assertEqual(coordinator.detect_deadlocks(), None)
     self.assertEqual(t2.perform_put('a', 'a0'), 'Success')
     self.assertEqual(t0.perform_get('a'), None)
     self.assertEqual(t3.perform_put('b', 'b0'), 'Success')
     self.assertEqual(t0.perform_get('b'), None)
     self.assertEqual(t1.perform_put('b', 'b1'), None)
     self.assertEqual(t2.perform_get('b'), None)
     abort_id = coordinator.detect_deadlocks()
     self.assertEqual(abort_id, None)
Ejemplo n.º 29
0
 def test_upgrade_s_x_multi(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     self.assertEqual(t0.perform_put('noob', '555'), 'Success')
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t0.perform_get('noob'), '555')
     self.assertEqual(t1.perform_get('noob'), '555')
     self.assertEqual(t2.perform_get('noob'), '555')
     self.assertEqual(t1.perform_put('noob', '111'), None)
     self.assertEqual(t1.check_lock(), None)
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.check_lock(), None)
     self.assertEqual(t2.commit(), 'Transaction Completed')
     self.assertEqual(t1.check_lock(), 'Success')
     self.assertEqual(t1.perform_get('noob'), '111')
Ejemplo n.º 30
0
 def test_single_abort(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     t3 = TransactionHandler(lock_table, 3, store)
     self.assertEqual(t0.perform_get('apple'), 'No such key')
     self.assertEqual(t1.perform_get('apple'), 'No such key')
     self.assertEqual(t2.perform_get('apple'), 'No such key')
     self.assertEqual(t0.perform_put('apple', '11'), None)
     self.assertEqual(t0.check_lock(), None)
     self.assertEqual(t1.commit(), 'Transaction Completed')
     self.assertEqual(t0.check_lock(), None)
     self.assertEqual(t2.commit(), 'Transaction Completed')
     self.assertEqual(t0.check_lock(), "Success")
     self.assertEqual(t0.perform_get('apple'), '11')
     self.assertEqual(t0.perform_get('banana'), 'No such key')
     self.assertEqual(t0.perform_put("banana", '22'), "Success")
     self.assertEqual(t1.perform_get('apple'), None)
     self.assertEqual(t0.abort(USER), 'User Abort')
     self.assertEqual(t1.check_lock(), 'No such key')
Ejemplo n.º 31
0
 def test_staff_fifo_queue(self):
     lock_table = {}
     store = InMemoryKVStore()
     t0 = TransactionHandler(lock_table, 0, store)
     t1 = TransactionHandler(lock_table, 1, store)
     t2 = TransactionHandler(lock_table, 2, store)
     t3 = TransactionHandler(lock_table, 3, store)
     t4 = TransactionHandler(lock_table, 4, store)
     self.assertEqual(t0.perform_get('a'), 'No such key')
     self.assertEqual(t0.perform_put('a', '0'), 'Success')        # T0 W(a)
     self.assertEqual(t1.perform_get('a'), None)                  # T1 R(a)
     self.assertEqual(t2.perform_put('a', '2'), None)
     self.assertEqual(t0.commit(), 'Transaction Completed')
     self.assertEqual(t1.check_lock(), '0')
     self.assertEqual(t1.perform_get('a'), '0')
     self.assertEqual(t3.perform_get('a'), None)
     self.assertEqual(t4.perform_get('a'), None)
     self.assertEqual(t1.commit(), 'Transaction Completed')
     self.assertEqual(t2.check_lock(), 'Success')
     self.assertEqual(t2.commit(), 'Transaction Completed')
     self.assertEqual(t3.check_lock(), '2')
     self.assertEqual(t4.check_lock(), '2')