コード例 #1
0
def process_request(data):
    if data.startswith('wyd'):
        return transactions._transaction_manager.transaction_statuses
    elif data.startswith('BEGIN TRANSACTION'):
        return transactions.begin_transaction()
    elif data.startswith('COMMIT'):
        txn_id = int(data.split()[1])
        return transactions.commit(txn_id)
    elif data.startswith('ROLLBACK'):
        txn_id = int(data.split()[1])
        return transactions.rollback(txn_id)
    elif data.startswith('TRANSACTION'):
        words = data.split()
        txn_id = int(words[1])
        if not txn_id in transactions._transaction_manager.transactions:
            return "txn %s does not exist yet" % txn_id
        operation = words[2]
        row_id = int(words[3])

        if operation == 'READ':
            return access.read(txn_id, row_id)
        elif operation == 'WRITE':
            value = words[4]
            return access.write(txn_id, row_id, value)
コード例 #2
0
    def test_prefers_transaction_specific_value(self):
        storage.write_row(1, 'main', 1, {'value': 'test'}, 1)
        storage.write_row(2, 'main', 1, {'value': 'updated'}, 1)

        response = access.read(2, 1)
        self.assertEqual(response, {1: {'value': 'updated'}})
コード例 #3
0
    def test_returns_stored_value(self):
        storage.write_row(1, 'main', 1, {'value': 'test'}, 1)
        storage.write_row(2, 'main', 1, {'value': 'updated'}, 1)

        response = access.read(1, 1)
        self.assertEqual(response, {1: {'value': 'test'}})
コード例 #4
0
 def test_returns_none_if_data_does_not_exist(self):
     response = access.read(1, 1)
     self.assertEqual(response, {1: None})
コード例 #5
0
    def test_fails_gracefully_if_read_lock_collision(self):
        with patch('pokedb.locks.get_locks_for_read',
                   side_effect=LockException):
            response = access.read(1, 1)

        self.assertEqual(response, "Lock collision for read")
コード例 #6
0
    def test_calls_lock_module_to_take_out_locks(self):
        with patch('pokedb.locks.get_locks_for_read') as mock_lock:
            access.read(1, 1)

        mock_lock.assert_called_once_with(1, 'main', [1])