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


Python AccountBroker.initialize方法代码示例

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


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

示例1: test_chexor

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_chexor(self):
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(Timestamp('1').internal)
     broker.put_container('a', Timestamp(1).internal,
                          Timestamp(0).internal, 0, 0,
                          POLICIES.default.idx)
     broker.put_container('b', Timestamp(2).internal,
                          Timestamp(0).internal, 0, 0,
                          POLICIES.default.idx)
     hasha = hashlib.md5(
         '%s-%s' % ('a', "%s-%s-%s-%s" % (
             Timestamp(1).internal, Timestamp(0).internal, 0, 0))
     ).digest()
     hashb = hashlib.md5(
         '%s-%s' % ('b', "%s-%s-%s-%s" % (
             Timestamp(2).internal, Timestamp(0).internal, 0, 0))
     ).digest()
     hashc = \
         ''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha, hashb)))
     self.assertEqual(broker.get_info()['hash'], hashc)
     broker.put_container('b', Timestamp(3).internal,
                          Timestamp(0).internal, 0, 0,
                          POLICIES.default.idx)
     hashb = hashlib.md5(
         '%s-%s' % ('b', "%s-%s-%s-%s" % (
             Timestamp(3).internal, Timestamp(0).internal, 0, 0))
     ).digest()
     hashc = \
         ''.join(('%02x' % (ord(a) ^ ord(b)) for a, b in zip(hasha, hashb)))
     self.assertEqual(broker.get_info()['hash'], hashc)
开发者ID:kvite,项目名称:swift,代码行数:32,代码来源:test_backend.py

示例2: test_policy_table_migration

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
    def test_policy_table_migration(self, tempdir):
        db_path = os.path.join(tempdir, 'account.db')

        # first init an acct DB without the policy_stat table present
        broker = AccountBroker(db_path, account='a')
        broker.initialize(Timestamp('1').internal)
        with broker.get() as conn:
            try:
                conn.execute('''
                    SELECT * FROM policy_stat
                    ''').fetchone()[0]
            except sqlite3.OperationalError as err:
                # confirm that the table really isn't there
                self.assert_('no such table: policy_stat' in str(err))
            else:
                self.fail('broker did not raise sqlite3.OperationalError '
                          'trying to select from policy_stat table!')

        # make sure we can HEAD this thing w/o the table
        stats = broker.get_policy_stats()
        self.assertEqual(len(stats), 0)

        # now do a PUT to create the table
        broker.put_container('o', Timestamp(time()).internal, 0, 0, 0,
                             POLICIES.default.idx)
        broker._commit_puts_stale_ok()

        # now confirm that the table was created
        with broker.get() as conn:
            conn.execute('SELECT * FROM policy_stat')

        stats = broker.get_policy_stats()
        self.assertEqual(len(stats), 1)
开发者ID:kvite,项目名称:swift,代码行数:35,代码来源:test_backend.py

示例3: test_reclaim

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_reclaim(self):
     broker = AccountBroker(':memory:', account='test_account')
     broker.initialize(Timestamp('1').internal)
     broker.put_container('c', Timestamp(time()).internal, 0, 0, 0,
                          POLICIES.default.idx)
     with broker.get() as conn:
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 0").fetchone()[0], 1)
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 1").fetchone()[0], 0)
     broker.reclaim(Timestamp(time() - 999).internal, time())
     with broker.get() as conn:
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 0").fetchone()[0], 1)
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 1").fetchone()[0], 0)
     sleep(.00001)
     broker.put_container('c', 0, Timestamp(time()).internal, 0, 0,
                          POLICIES.default.idx)
     with broker.get() as conn:
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 0").fetchone()[0], 0)
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 1").fetchone()[0], 1)
     broker.reclaim(Timestamp(time() - 999).internal, time())
     with broker.get() as conn:
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 0").fetchone()[0], 0)
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 1").fetchone()[0], 1)
     sleep(.00001)
     broker.reclaim(Timestamp(time()).internal, time())
     with broker.get() as conn:
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 0").fetchone()[0], 0)
         self.assertEqual(conn.execute(
             "SELECT count(*) FROM container "
             "WHERE deleted = 1").fetchone()[0], 0)
     # Test reclaim after deletion. Create 3 test containers
     broker.put_container('x', 0, 0, 0, 0, POLICIES.default.idx)
     broker.put_container('y', 0, 0, 0, 0, POLICIES.default.idx)
     broker.put_container('z', 0, 0, 0, 0, POLICIES.default.idx)
     broker.reclaim(Timestamp(time()).internal, time())
     # self.assertEqual(len(res), 2)
     # self.assert_(isinstance(res, tuple))
     # containers, account_name = res
     # self.assert_(containers is None)
     # self.assert_(account_name is None)
     # Now delete the account
     broker.delete_db(Timestamp(time()).internal)
     broker.reclaim(Timestamp(time()).internal, time())
开发者ID:kvite,项目名称:swift,代码行数:62,代码来源:test_backend.py

示例4: test_policy_stats_tracking

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
    def test_policy_stats_tracking(self):
        ts = (Timestamp(t).internal for t in itertools.count(int(time())))
        broker = AccountBroker(':memory:', account='a')
        broker.initialize(ts.next())

        # policy 0
        broker.put_container('con1', ts.next(), 0, 12, 2798641, 0)
        broker.put_container('con1', ts.next(), 0, 13, 8156441, 0)
        # policy 1
        broker.put_container('con2', ts.next(), 0, 7, 5751991, 1)
        broker.put_container('con2', ts.next(), 0, 8, 6085379, 1)

        stats = broker.get_policy_stats()
        self.assertEqual(len(stats), 2)
        self.assertEqual(stats[0]['object_count'], 13)
        self.assertEqual(stats[0]['bytes_used'], 8156441)
        self.assertEqual(stats[1]['object_count'], 8)
        self.assertEqual(stats[1]['bytes_used'], 6085379)

        # Break encapsulation here to make sure that there's only 2 rows in
        # the stats table. It's possible that there could be 4 rows (one per
        # put_container) but that they came out in the right order so that
        # get_policy_stats() collapsed them down to the right number. To prove
        # that's not so, we have to go peek at the broker's internals.
        with broker.get() as conn:
            nrows = conn.execute(
                "SELECT COUNT(*) FROM policy_stat").fetchall()[0][0]
        self.assertEqual(nrows, 2)
开发者ID:kvite,项目名称:swift,代码行数:30,代码来源:test_backend.py

示例5: test_load_old_pending_puts

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [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

示例6: test_get_info

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
    def test_get_info(self):
        # Test AccountBroker.get_info
        broker = AccountBroker(':memory:', account='test1')
        broker.initialize(normalize_timestamp('1'))

        info = broker.get_info()
        self.assertEqual(info['account'], 'test1')
        self.assertEqual(info['hash'], '00000000000000000000000000000000')

        info = broker.get_info()
        self.assertEqual(info['container_count'], 0)

        broker.put_container('c1', normalize_timestamp(time()), 0, 0, 0)
        info = broker.get_info()
        self.assertEqual(info['container_count'], 1)

        sleep(.00001)
        broker.put_container('c2', normalize_timestamp(time()), 0, 0, 0)
        info = broker.get_info()
        self.assertEqual(info['container_count'], 2)

        sleep(.00001)
        broker.put_container('c2', normalize_timestamp(time()), 0, 0, 0)
        info = broker.get_info()
        self.assertEqual(info['container_count'], 2)

        sleep(.00001)
        broker.put_container('c1', 0, normalize_timestamp(time()), 0, 0)
        info = broker.get_info()
        self.assertEqual(info['container_count'], 1)

        sleep(.00001)
        broker.put_container('c2', 0, normalize_timestamp(time()), 0, 0)
        info = broker.get_info()
        self.assertEqual(info['container_count'], 0)
开发者ID:10389030,项目名称:swift,代码行数:37,代码来源:test_backend.py

示例7: test_double_check_trailing_delimiter

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_double_check_trailing_delimiter(self):
     # Test AccountBroker.list_containers_iter for an
     # account that has an odd container with a trailing delimiter
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(normalize_timestamp('1'))
     broker.put_container('a', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('a-', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('a-a', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('a-a-a', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('a-a-b', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('a-b', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('b', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('b-a', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('b-b', normalize_timestamp(time()), 0, 0, 0)
     broker.put_container('c', normalize_timestamp(time()), 0, 0, 0)
     listing = broker.list_containers_iter(15, None, None, None, None)
     self.assertEqual(len(listing), 10)
     self.assertEqual([row[0] for row in listing],
                      ['a', 'a-', 'a-a', 'a-a-a', 'a-a-b', 'a-b', 'b',
                       'b-a', 'b-b', 'c'])
     listing = broker.list_containers_iter(15, None, None, '', '-')
     self.assertEqual(len(listing), 5)
     self.assertEqual([row[0] for row in listing],
                      ['a', 'a-', 'b', 'b-', 'c'])
     listing = broker.list_containers_iter(15, None, None, 'a-', '-')
     self.assertEqual(len(listing), 4)
     self.assertEqual([row[0] for row in listing],
                      ['a-', 'a-a', 'a-a-', 'a-b'])
     listing = broker.list_containers_iter(15, None, None, 'b-', '-')
     self.assertEqual(len(listing), 2)
     self.assertEqual([row[0] for row in listing], ['b-a', 'b-b'])
开发者ID:10389030,项目名称:swift,代码行数:33,代码来源:test_backend.py

示例8: tearDown

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def tearDown(self):
     AccountBroker.create_account_stat_table = \
         self._imported_create_account_stat_table
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(normalize_timestamp('1'))
     with broker.get() as conn:
         conn.execute('SELECT metadata FROM account_stat')
开发者ID:10389030,项目名称:swift,代码行数:9,代码来源:test_backend.py

示例9: tearDown

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def tearDown(self):
     AccountBroker.create_container_table = \
         self._imported_create_container_table
     AccountBroker._initialize = self._imported_initialize
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(Timestamp('1').internal)
     with broker.get() as conn:
         conn.execute('SELECT storage_policy_index FROM container')
开发者ID:kvite,项目名称:swift,代码行数:10,代码来源:test_backend.py

示例10: test_get_policy_stats

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
    def test_get_policy_stats(self):
        ts = (Timestamp(t).internal for t in itertools.count(int(time())))
        broker = AccountBroker(':memory:', account='a')
        broker.initialize(ts.next())
        # check empty policy_stats
        self.assertTrue(broker.empty())
        policy_stats = broker.get_policy_stats()
        self.assertEqual(policy_stats, {})

        # add some empty containers
        for policy in POLICIES:
            container_name = 'c-%s' % policy.name
            put_timestamp = ts.next()
            broker.put_container(container_name,
                                 put_timestamp, 0,
                                 0, 0,
                                 policy.idx)

            policy_stats = broker.get_policy_stats()
            stats = policy_stats[policy.idx]
            self.assertEqual(stats['object_count'], 0)
            self.assertEqual(stats['bytes_used'], 0)

        # update the containers object & byte count
        for policy in POLICIES:
            container_name = 'c-%s' % policy.name
            put_timestamp = ts.next()
            count = policy.idx * 100  # good as any integer
            broker.put_container(container_name,
                                 put_timestamp, 0,
                                 count, count,
                                 policy.idx)

            policy_stats = broker.get_policy_stats()
            stats = policy_stats[policy.idx]
            self.assertEqual(stats['object_count'], count)
            self.assertEqual(stats['bytes_used'], count)

        # check all the policy_stats at once
        for policy_index, stats in policy_stats.items():
            policy = POLICIES[policy_index]
            count = policy.idx * 100  # coupled with policy for test
            self.assertEqual(stats['object_count'], count)
            self.assertEqual(stats['bytes_used'], count)

        # now delete the containers one by one
        for policy in POLICIES:
            container_name = 'c-%s' % policy.name
            delete_timestamp = ts.next()
            broker.put_container(container_name,
                                 0, delete_timestamp,
                                 0, 0,
                                 policy.idx)

            policy_stats = broker.get_policy_stats()
            stats = policy_stats[policy.idx]
            self.assertEqual(stats['object_count'], 0)
            self.assertEqual(stats['bytes_used'], 0)
开发者ID:kvite,项目名称:swift,代码行数:60,代码来源:test_backend.py

示例11: test_account_stat_get_data

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_account_stat_get_data(self):
     stat = db_stats_collector.AccountStatsCollector(self.conf)
     account_db = AccountBroker("%s/acc.db" % self.accounts,
                                     account='test_acc')
     account_db.initialize()
     account_db.put_container('test_container', time.time(),
                                   None, 10, 1000)
     info = stat.get_data("%s/acc.db" % self.accounts)
     self.assertEquals('''"test_acc",1,10,1000\n''', info)
开发者ID:VenkataSeshadri,项目名称:slogging,代码行数:11,代码来源:test_db_stats_collector.py

示例12: test_empty

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_empty(self):
     # Test AccountBroker.empty
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(normalize_timestamp('1'))
     self.assert_(broker.empty())
     broker.put_container('o', normalize_timestamp(time()), 0, 0, 0)
     self.assert_(not broker.empty())
     sleep(.00001)
     broker.put_container('o', 0, normalize_timestamp(time()), 0, 0)
     self.assert_(broker.empty())
开发者ID:10389030,项目名称:swift,代码行数:12,代码来源:test_backend.py

示例13: test_empty

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_empty(self):
     # Test AccountBroker.empty
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(Timestamp('1').internal)
     self.assert_(broker.empty())
     broker.put_container('o', Timestamp(time()).internal, 0, 0, 0,
                          POLICIES.default.idx)
     self.assert_(not broker.empty())
     sleep(.00001)
     broker.put_container('o', 0, Timestamp(time()).internal, 0, 0,
                          POLICIES.default.idx)
     self.assert_(broker.empty())
开发者ID:kvite,项目名称:swift,代码行数:14,代码来源:test_backend.py

示例14: setUp

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def setUp(self):
     self._imported_create_account_stat_table = \
         AccountBroker.create_account_stat_table
     AccountBroker.create_account_stat_table = \
         premetadata_create_account_stat_table
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(normalize_timestamp('1'))
     exc = None
     with broker.get() as conn:
         try:
             conn.execute('SELECT metadata FROM account_stat')
         except BaseException as err:
             exc = err
     self.assert_('no such column: metadata' in str(exc))
开发者ID:10389030,项目名称:swift,代码行数:16,代码来源:test_backend.py

示例15: test_exception

# 需要导入模块: from swift.account.backend import AccountBroker [as 别名]
# 或者: from swift.account.backend.AccountBroker import initialize [as 别名]
 def test_exception(self):
     # Test AccountBroker throwing a conn away after exception
     first_conn = None
     broker = AccountBroker(':memory:', account='a')
     broker.initialize(normalize_timestamp('1'))
     with broker.get() as conn:
         first_conn = conn
     try:
         with broker.get() as conn:
             self.assertEqual(first_conn, conn)
             raise Exception('OMG')
     except Exception:
         pass
     self.assert_(broker.conn is None)
开发者ID:10389030,项目名称:swift,代码行数:16,代码来源:test_backend.py


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