當前位置: 首頁>>代碼示例>>Python>>正文


Python MemcachedDatabase.rollback方法代碼示例

本文整理匯總了Python中database.memcached_database.MemcachedDatabase.rollback方法的典型用法代碼示例。如果您正苦於以下問題:Python MemcachedDatabase.rollback方法的具體用法?Python MemcachedDatabase.rollback怎麽用?Python MemcachedDatabase.rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在database.memcached_database.MemcachedDatabase的用法示例。


在下文中一共展示了MemcachedDatabase.rollback方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Communicator

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
class Communicator(Singleton):
    '''Interface between listeners and the application.'''

    def _initialize(self):
        self._database = MemcachedDatabase()
        self._action_manager = ActionManager()
        self._population_control = PopulationControl()
        self._admin_handler = AdminHandler()

    def execute_command(self, password, command, args):
        '''Execute client's command.'''

        try:
            if command in ["born", "give_birth"]:
                result = self._population_control.execute_command(password, command, args)
            elif command == "map_data":
                result = self._admin_handler.execute_command(password, command, args)
            else:
                result = self._action_manager.do_action(password, command, args)

            # Committing or rollbacking all changes after the completion of execution.
            self._database.commit()
            return result

        except Exception:
            self._database.rollback()
            raise
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:29,代碼來源:communicator.py

示例2: test_for_update

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_for_update(self):
        '''Tests of for_update flag works correctly.'''
        database = MemcachedDatabase()

        robot_id = "test_for_update_18762"
        robot = Robot(robot_id, "123")
        database.add_robot(robot, (10, 0))
        database.commit()

        new_robot = database.get_robot(robot_id, for_update=True)

        # Testing lock
        with self.assertRaises(LockAlreadyAquiredError):
            database.get_robot(robot_id, for_update=True)

        # Testing commit.
        new_robot.set_alive(False)

        # It shouldn't be changed yet.
        new_robot_2 = database.get_robot(robot_id)
        self.assertNotEqual(new_robot.get_alive(), new_robot_2.get_alive())

        # Actually committing changes.
        database.commit()
        new_robot_2 = database.get_robot(robot_id)
        self.assertEqual(new_robot.get_alive(), new_robot_2.get_alive())

        # Lock should be freed.
        database.get_robot(robot_id, for_update=True)
        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:32,代碼來源:test_get_robot.py

示例3: test_no_plant

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_no_plant(self):
        '''Tests when there's no plant to eat.'''
        action_manager = ActionManager()
        database = MemcachedDatabase()

        with self.assertRaises(NoPlantToEat):
            action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID])
        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:10,代碼來源:test_eat_action.py

示例4: test_locked

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_locked(self):
        '''Tests with a locked square.'''
        action_manager = ActionManager()
        database = MemcachedDatabase()

        database.get_square(TestEatAction.LOCATION, for_update=True)

        with self.assertRaises(LockAlreadyAquiredError):
            action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID])
        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:12,代碼來源:test_eat_action.py

示例5: test_locked_robot

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_locked_robot(self):
        '''Tests with a locked robot.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()
        database.get_robot(TestGiveBirth.ROBOT_ID, for_update=True)

        with self.assertRaises(LockAlreadyAquiredError):
            population_control.execute_command("123", "give_birth", [TestGiveBirth.ROBOT_ID])

        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:12,代碼來源:test_give_birth.py

示例6: test_rollback

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_rollback(self):
        '''Tests if calling rollback works correctly.'''
        database = MemcachedDatabase()

        new_robot = Robot("test_rollback_87162", "123")
        database.add_robot(new_robot, (1, 1))

        database.rollback()
        database.commit()

        with self.assertRaises(RobotNotFoundError):
            database.get_robot("test_rollback_87162")
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:14,代碼來源:test_add_robot.py

示例7: test_bad_argument

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_bad_argument(self):
        '''Tests when sending bad arguments to the action.'''
        action_manager = ActionManager()
        database = MemcachedDatabase()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID, None])
        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "eat", [TestEatAction.ROBOT_ID, "", 9])
        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:14,代碼來源:test_eat_action.py

示例8: test_with_parent

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_with_parent(self):
        '''Tests borning a robot with a parent.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()

        database.add_password("oijdnnh76153WEd")
        robot = Robot("test_with_parent_18873", "123")
        database.add_robot(robot, (14, 1))
        database.commit()

        population_control.execute_command("oijdnnh76153WEd", "born", ["test_with_parent_18873", "My Child"])

        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:15,代碼來源:test_born.py

示例9: test_bad_direction

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_bad_direction(self):
        '''Sends an invalid direction as arguments.'''
        robot_id = "test_bad_direction_18445"
        robot = Robot(robot_id, "123")
        world = World()
        action_manager = ActionManager()
        database = MemcachedDatabase()

        world.add_robot(robot, (12, 6))
        database.commit()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id, "U"])

        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id, 988])

        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id, None])

        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action_manager.do_action("123", "move", [robot_id])

        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:32,代碼來源:test_move_action.py

示例10: test_bad_name

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_bad_name(self):
        '''Tries to born a robot with an invalid name. Should be fail.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()

        database.add_password("OIkdj981HJDJHcnm_1")
        database.add_password("OIkdj981HJDJHcnm_2")
        database.add_password("OIkdj981HJDJHcnm_3")
        database.add_password("OIkdj981HJDJHcnm_4")
        database.commit()

        long_name = "n" * (MAX_ROBOT_NAME + 1)
        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_1", "born", [None, long_name])
        database.rollback()

        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_2", "born", [None, None])
        database.rollback()

        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_3", "born", [None, b"some bytes"])
        database.rollback()

        with self.assertRaises(LongRobotNameError):
            population_control.execute_command("OIkdj981HJDJHcnm_4", "born", [None, database])
        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:29,代碼來源:test_born.py

示例11: test_not_enough_honor

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_not_enough_honor(self):
        '''Tests a robot with few honors, trying to give birth.'''
        population_control = PopulationControl()
        database = MemcachedDatabase()
        configs = Configs()

        robot = database.get_robot(TestGiveBirth.ROBOT_ID, for_update=True)
        robot.set_honor(configs.get_robots_birth_required_honor() - 1)
        database.commit()

        with self.assertRaises(NotEnoughHonorError):
            population_control.execute_command("123", "give_birth", [TestGiveBirth.ROBOT_ID])

        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:16,代碼來源:test_give_birth.py

示例12: test_moving_outside

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_moving_outside(self):
        '''Tests moving a robot to outside of the world.'''
        robot_id = "test_moving_outside_981165"
        robot = Robot(robot_id, "123")
        world = World()
        action_manager = ActionManager()
        database = MemcachedDatabase()

        world.add_robot(robot, (14, 2))
        database.commit()

        with self.assertRaises(InvalidLocationError):
            action_manager.do_action("123", "move", [robot_id, "E"])

        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:17,代碼來源:test_move_action.py

示例13: test_locked_square

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_locked_square(self):
        '''Tests with a already-locked square.'''
        database = MemcachedDatabase()
        robot = Robot("oi981872yuweu.9887", "123")
        robot.set_location((5, 0))
        robot.set_has_water(True)

        database.get_square((5, 0), for_update=True)

        action = WaterAction()

        with self.assertRaises(LockAlreadyAquiredError):
            action.do_action(robot, ["oi981872yuweu.9887"])

        # Freeing lock.
        database.rollback()
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:18,代碼來源:test_water_action.py

示例14: test_bad_arguments

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_bad_arguments(self):
        '''Calls the action with invalid arguments.'''
        action = InfoAction()
        database = MemcachedDatabase()
        robot = Robot("test_info_action_1293", "123")

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, [robot.get_id(), None])
        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, [robot.get_id(), "", "09"])
        database.rollback()

        with self.assertRaises(InvalidArgumentsError):
            action.do_action(robot, [robot.get_id(), []])
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:18,代碼來源:test_info_action.py

示例15: test_rollback

# 需要導入模塊: from database.memcached_database import MemcachedDatabase [as 別名]
# 或者: from database.memcached_database.MemcachedDatabase import rollback [as 別名]
    def test_rollback(self):
        '''Tests if changes rolls back correctly.'''
        database = MemcachedDatabase()

        robot_id = "test_rollback_18098"
        robot = Robot(robot_id, "123")
        database.add_robot(robot, (11, 0))
        database.commit()

        new_robot = database.get_robot(robot_id, for_update=True)
        new_robot.set_alive(False)

        database.rollback()
        database.commit()

        new_robot_2 = database.get_robot(robot_id)
        self.assertNotEqual(new_robot.get_alive(), new_robot_2.get_alive())
開發者ID:aidin36,項目名稱:beneath-a-binary-sky,代碼行數:19,代碼來源:test_get_robot.py


注:本文中的database.memcached_database.MemcachedDatabase.rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。