当前位置: 首页>>代码示例>>Python>>正文


Python AccountBroker._commit_puts方法代码示例

本文整理汇总了Python中swift.account.backend.AccountBroker._commit_puts方法的典型用法代码示例。如果您正苦于以下问题:Python AccountBroker._commit_puts方法的具体用法?Python AccountBroker._commit_puts怎么用?Python AccountBroker._commit_puts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.account.backend.AccountBroker的用法示例。


在下文中一共展示了AccountBroker._commit_puts方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_load_old_pending_puts

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import _commit_puts [as 别名]
    def test_load_old_pending_puts(self):
        # pending puts from pre-storage-policy account brokers won't contain
        # the storage policy index
        tempdir = mkdtemp()
        broker_path = os.path.join(tempdir, 'test-load-old.db')
        try:
            broker = AccountBroker(broker_path, account='real')
            broker.initialize(Timestamp(1).internal)
            with open(broker_path + '.pending', 'a+b') as pending:
                pending.write(':')
                pending.write(pickle.dumps(
                    # name, put_timestamp, delete_timestamp, object_count,
                    # bytes_used, deleted
                    ('oldcon', Timestamp(200).internal,
                     Timestamp(0).internal,
                     896, 9216695, 0)).encode('base64'))

            broker._commit_puts()
            with broker.get() as conn:
                results = list(conn.execute('''
                    SELECT name, storage_policy_index FROM container
                '''))
            self.assertEqual(len(results), 1)
            self.assertEqual(dict(results[0]),
                             {'name': 'oldcon', 'storage_policy_index': 0})
        finally:
            rmtree(tempdir)
开发者ID:kvite,项目名称:swift,代码行数:29,代码来源:test_backend.py

示例2: test_half_upgraded_database

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import _commit_puts [as 别名]
    def test_half_upgraded_database(self, tempdir):
        db_path = os.path.join(tempdir, 'account.db')
        ts = itertools.count()
        ts = (Timestamp(t).internal for t in itertools.count(int(time())))

        broker = AccountBroker(db_path, account='a')
        broker.initialize(ts.next())

        self.assertTrue(broker.empty())

        # add a container (to pending file)
        broker.put_container('c', ts.next(), 0, 0, 0,
                             POLICIES.default.idx)

        real_get = broker.get
        called = []

        @contextmanager
        def mock_get():
            with real_get() as conn:

                def mock_executescript(script):
                    if called:
                        raise Exception('kaboom!')
                    called.append(script)

                conn.executescript = mock_executescript
                yield conn

        broker.get = mock_get

        try:
            broker._commit_puts()
        except Exception:
            pass
        else:
            self.fail('mock exception was not raised')

        self.assertEqual(len(called), 1)
        self.assert_('CREATE TABLE policy_stat' in called[0])

        # nothing was committed
        broker = AccountBroker(db_path, account='a')
        with broker.get() as conn:
            try:
                conn.execute('SELECT * FROM policy_stat')
            except sqlite3.OperationalError as err:
                self.assert_('no such table: policy_stat' in str(err))
            else:
                self.fail('half upgraded database!')
            container_count = conn.execute(
                'SELECT count(*) FROM container').fetchone()[0]
            self.assertEqual(container_count, 0)

        # try again to commit puts
        self.assertFalse(broker.empty())

        # full migration successful
        with broker.get() as conn:
            conn.execute('SELECT * FROM policy_stat')
            conn.execute('SELECT storage_policy_index FROM container')
开发者ID:kvite,项目名称:swift,代码行数:63,代码来源:test_backend.py


注:本文中的swift.account.backend.AccountBroker._commit_puts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。