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


Python utils.server_is_master_with_slave函数代码示例

本文整理汇总了Python中test.utils.server_is_master_with_slave函数的典型用法代码示例。如果您正苦于以下问题:Python server_is_master_with_slave函数的具体用法?Python server_is_master_with_slave怎么用?Python server_is_master_with_slave使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_copy_db

    def test_copy_db(self):
        c = Connection(self.host, self.port)
        self.assertTrue(c.in_request())

        self.assertRaises(TypeError, c.copy_database, 4, "foo")
        self.assertRaises(TypeError, c.copy_database, "foo", 4)

        self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

        c.pymongo_test.test.drop()
        c.drop_database("pymongo_test1")
        c.drop_database("pymongo_test2")

        c.pymongo_test.test.insert({"foo": "bar"})

        # Due to SERVER-2329, databases may not disappear from a master in a
        # master-slave pair
        if not server_is_master_with_slave(c):
            self.assertFalse("pymongo_test1" in c.database_names())
            self.assertFalse("pymongo_test2" in c.database_names())

        c.copy_database("pymongo_test", "pymongo_test1")
        # copy_database() didn't accidentally end the request
        self.assertTrue(c.in_request())

        self.assertTrue("pymongo_test1" in c.database_names())
        self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

        c.end_request()
        self.assertFalse(c.in_request())
        c.copy_database("pymongo_test", "pymongo_test2", "%s:%d" % (self.host, self.port))
        # copy_database() didn't accidentally restart the request
        self.assertFalse(c.in_request())

        self.assertTrue("pymongo_test2" in c.database_names())
        self.assertEqual("bar", c.pymongo_test2.test.find_one()["foo"])

        if version.at_least(c, (1, 3, 3, 1)):
            c.drop_database("pymongo_test1")

            c.pymongo_test.add_user("mike", "password")

            self.assertRaises(
                OperationFailure, c.copy_database, "pymongo_test", "pymongo_test1", username="foo", password="bar"
            )
            if not server_is_master_with_slave(c):
                self.assertFalse("pymongo_test1" in c.database_names())

            self.assertRaises(
                OperationFailure, c.copy_database, "pymongo_test", "pymongo_test1", username="mike", password="bar"
            )

            if not server_is_master_with_slave(c):
                self.assertFalse("pymongo_test1" in c.database_names())

            if not is_mongos(c):
                # See SERVER-6427
                c.copy_database("pymongo_test", "pymongo_test1", username="mike", password="password")
                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
开发者ID:nickmilon,项目名称:mongo-python-driver,代码行数:60,代码来源:test_connection.py

示例2: drop_databases

    def drop_databases(self, database_names):
        cx = self.get_client()
        for test_db_name in database_names:
            yield cx.drop_database(test_db_name)

        # Due to SERVER-2329, databases may not disappear from a master
        # in a master-slave pair.
        if not (yield server_is_master_with_slave(cx)):
            start = time.time()

            # There may be a race condition in the server's dropDatabase. Wait
            # for it to update its namespaces.
            db_names = yield cx.database_names()
            while time.time() - start < 30:
                remaining_test_dbs = set(database_names).intersection(db_names)

                if not remaining_test_dbs:
                    # All test DBs are removed.
                    break

                yield self.pause(0.1)
                db_names = yield cx.database_names()

            for test_db_name in database_names:
                self.assertFalse(test_db_name in db_names, "%s not dropped" % test_db_name)
开发者ID:hackdog,项目名称:motor,代码行数:25,代码来源:motor_client_test_generic.py

示例3: drop_databases

    def drop_databases(self, database_names):
        for test_db_name in database_names:
            # Setup code has configured a short timeout, and the copying
            # has put Mongo under enough load that we risk timeouts here
            # unless we override. command() takes no network_timeout but
            # find_one does.
            self.sync_cx[test_db_name]['$cmd'].find_one(
                {'dropDatabase': 1}, network_timeout=30)

        # Due to SERVER-2329, databases may not disappear from a master
        # in a master-slave pair.
        if not server_is_master_with_slave(self.sync_cx):
            start = time.time()
            
            # There may be a race condition in the server's dropDatabase. Wait
            # for it to update its namespaces.
            db_names = self.sync_cx.database_names()
            while time.time() - start < 10:
                remaining_test_dbs = (
                    set(database_names).intersection(db_names))
                
                if not remaining_test_dbs:
                    # All test DBs are removed.
                    break

                db_names = self.sync_cx.database_names()
                
            for test_db_name in database_names:
                self.assertFalse(
                    test_db_name in db_names,
                    "%s not dropped" % test_db_name)
开发者ID:ZoeyYoung,项目名称:motor,代码行数:31,代码来源:test_motor_client.py

示例4: test_fsync_lock_unlock

    def test_fsync_lock_unlock(self):
        if server_is_master_with_slave(client_context.client) and client_context.version.at_least(2, 3, 0):
            raise SkipTest("SERVER-7714")

        self.assertFalse(self.client.is_locked)
        # async flushing not supported on windows...
        if sys.platform not in ("cygwin", "win32"):
            self.client.fsync(async=True)
            self.assertFalse(self.client.is_locked)
        self.client.fsync(lock=True)
        self.assertTrue(self.client.is_locked)
        locked = True
        self.client.unlock()
        for _ in range(5):
            locked = self.client.is_locked
            if not locked:
                break
            time.sleep(1)
        self.assertFalse(locked)
开发者ID:rychipman,项目名称:mongo-python-driver,代码行数:19,代码来源:test_client.py

示例5: test_copy_db

    def test_copy_db(self):
        c = MongoClient(host, port)
        # Due to SERVER-2329, databases may not disappear
        # from a master in a master-slave pair.
        if server_is_master_with_slave(c):
            raise SkipTest("SERVER-2329")

        ctx = catch_warnings()
        try:
            warnings.simplefilter("ignore", DeprecationWarning)
            self.assertRaises(TypeError, c.copy_database, 4, "foo")
            self.assertRaises(TypeError, c.copy_database, "foo", 4)
            self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

            c.pymongo_test.test.drop()
            c.pymongo_test.test.insert({"foo": "bar"})

            c.drop_database("pymongo_test1")
            self.assertFalse("pymongo_test1" in c.database_names())

            c.copy_database("pymongo_test", "pymongo_test1")
            self.assertTrue("pymongo_test1" in c.database_names())
            self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
            c.drop_database("pymongo_test1")

            # XXX - SERVER-15318
            if not (version.at_least(c, (2, 6, 4)) and is_mongos(c)):
                self.assertFalse(c.in_request())
                c.copy_database("pymongo_test", "pymongo_test1",
                                "%s:%d" % (host, port))
                # copy_database() didn't accidentally restart the request
                self.assertFalse(c.in_request())

                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

            c.drop_database("pymongo_test1")
        finally:
            ctx.exit()
开发者ID:hedgepigdaniel,项目名称:mongo-python-driver,代码行数:39,代码来源:test_client.py

示例6: test_copy_db

    def test_copy_db(self):
        c = MongoClient(host, port)
        # Due to SERVER-2329, databases may not disappear
        # from a master in a master-slave pair.
        if server_is_master_with_slave(c):
            raise SkipTest("SERVER-2329")
        # We test copy twice; once starting in a request and once not. In
        # either case the copy should succeed (because it starts a request
        # internally) and should leave us in the same state as before the copy.
        c.start_request()

        self.assertRaises(TypeError, c.copy_database, 4, "foo")
        self.assertRaises(TypeError, c.copy_database, "foo", 4)

        self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

        c.pymongo_test.test.drop()
        c.drop_database("pymongo_test1")
        c.drop_database("pymongo_test2")
        self.assertFalse("pymongo_test1" in c.database_names())
        self.assertFalse("pymongo_test2" in c.database_names())

        c.pymongo_test.test.insert({"foo": "bar"})

        c.copy_database("pymongo_test", "pymongo_test1")
        # copy_database() didn't accidentally end the request
        self.assertTrue(c.in_request())

        self.assertTrue("pymongo_test1" in c.database_names())
        self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

        c.end_request()
        self.assertFalse(c.in_request())
        c.copy_database("pymongo_test", "pymongo_test2",
                        "%s:%d" % (host, port))
        # copy_database() didn't accidentally restart the request
        self.assertFalse(c.in_request())

        self.assertTrue("pymongo_test2" in c.database_names())
        self.assertEqual("bar", c.pymongo_test2.test.find_one()["foo"])

        # See SERVER-6427 for mongos
        if (version.at_least(c, (1, 3, 3, 1)) and
            not is_mongos(c) and server_started_with_auth(c)):

            c.drop_database("pymongo_test1")

            c.admin.add_user("admin", "password")
            c.admin.authenticate("admin", "password")
            try:
                c.pymongo_test.add_user("mike", "password")

                self.assertRaises(OperationFailure, c.copy_database,
                                  "pymongo_test", "pymongo_test1",
                                  username="foo", password="bar")
                self.assertFalse("pymongo_test1" in c.database_names())

                self.assertRaises(OperationFailure, c.copy_database,
                                  "pymongo_test", "pymongo_test1",
                                  username="mike", password="bar")
                self.assertFalse("pymongo_test1" in c.database_names())

                c.copy_database("pymongo_test", "pymongo_test1",
                                username="mike", password="password")
                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
            finally:
                # Cleanup
                remove_all_users(c.pymongo_test)
                c.admin.remove_user("admin")
                c.disconnect()
开发者ID:quantopian,项目名称:mongo-python-driver,代码行数:71,代码来源:test_client.py

示例7: test_copy_db

    def test_copy_db(self):
        c = MongoClient(self.host, self.port)
        # We test copy twice; once starting in a request and once not. In
        # either case the copy should succeed (because it starts a request
        # internally) and should leave us in the same state as before the copy.
        c.start_request()

        self.assertRaises(TypeError, c.copy_database, 4, "foo")
        self.assertRaises(TypeError, c.copy_database, "foo", 4)

        self.assertRaises(InvalidName, c.copy_database, "foo", "$foo")

        c.pymongo_test.test.drop()
        c.drop_database("pymongo_test1")
        c.drop_database("pymongo_test2")

        c.pymongo_test.test.insert({"foo": "bar"})

        # Due to SERVER-2329, databases may not disappear from a master in a
        # master-slave pair
        if not server_is_master_with_slave(c):
            self.assertFalse("pymongo_test1" in c.database_names())
            self.assertFalse("pymongo_test2" in c.database_names())

        c.copy_database("pymongo_test", "pymongo_test1")
        # copy_database() didn't accidentally end the request
        self.assertTrue(c.in_request())

        self.assertTrue("pymongo_test1" in c.database_names())
        self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])

        c.end_request()
        self.assertFalse(c.in_request())
        c.copy_database("pymongo_test", "pymongo_test2",
                        "%s:%d" % (self.host, self.port))
        # copy_database() didn't accidentally restart the request
        self.assertFalse(c.in_request())

        self.assertTrue("pymongo_test2" in c.database_names())
        self.assertEqual("bar", c.pymongo_test2.test.find_one()["foo"])

        if version.at_least(c, (1, 3, 3, 1)):
            c.drop_database("pymongo_test1")

            c.pymongo_test.add_user("mike", "password")

            self.assertRaises(OperationFailure, c.copy_database,
                              "pymongo_test", "pymongo_test1",
                              username="foo", password="bar")
            if not server_is_master_with_slave(c):
                self.assertFalse("pymongo_test1" in c.database_names())

            self.assertRaises(OperationFailure, c.copy_database,
                              "pymongo_test", "pymongo_test1",
                              username="mike", password="bar")

            if not server_is_master_with_slave(c):
                self.assertFalse("pymongo_test1" in c.database_names())

            if not is_mongos(c):
                # See SERVER-6427
                c.copy_database("pymongo_test", "pymongo_test1",
                                username="mike", password="password")
                self.assertTrue("pymongo_test1" in c.database_names())
                self.assertEqual("bar", c.pymongo_test1.test.find_one()["foo"])
开发者ID:DaBbleR23,项目名称:mongo-python-driver,代码行数:65,代码来源:test_client.py

示例8: test_copy_db

    def test_copy_db(self, done):
        # 1. Drop old test DBs
        # 2. Copy a test DB N times at once (we need to do it many times at
        #   once to make sure that GreenletPool's start_request() is properly
        #   isolating operations from each other)
        # 3. Create a username and password
        # 4. Copy a database using name and password
        is_ms = server_is_master_with_slave(self.sync_cx)
        ncopies = 10
        nrange = list(range(ncopies))
        test_db_names = ["pymongo_test%s" % i for i in nrange]
        cx = self.motor_connection(host, port)

        def check_copydb_results():
            db_names = self.sync_cx.database_names()
            for test_db_name in test_db_names:
                self.assertTrue(test_db_name in db_names)
                result = self.sync_cx[test_db_name].test_collection.find_one()
                self.assertTrue(result, "No results in %s" % test_db_name)
                self.assertEqual("bar", result.get("foo"), "Wrong result from %s: %s" % (test_db_name, result))

        def drop_all():
            for test_db_name in test_db_names:
                # Setup code has configured a short timeout, and the copying
                # has put Mongo under enough load that we risk timeouts here
                # unless we override.
                self.sync_cx[test_db_name]["$cmd"].find_one({"dropDatabase": 1}, network_timeout=30)

            if not is_ms:
                # Due to SERVER-2329, databases may not disappear from a master
                # in a master-slave pair
                db_names = self.sync_cx.database_names()
                for test_db_name in test_db_names:
                    self.assertFalse(test_db_name in db_names, "%s not dropped" % test_db_name)

        # 1. Drop old test DBs
        yield motor.Op(cx.drop_database, "pymongo_test")
        drop_all()

        # 2. Copy a test DB N times at once
        yield motor.Op(cx.pymongo_test.test_collection.insert, {"foo": "bar"})
        for test_db_name in test_db_names:
            cx.copy_database("pymongo_test", test_db_name, callback=(yield gen.Callback(key=test_db_name)))

        yield motor.WaitAllOps(test_db_names)
        check_copydb_results()

        drop_all()

        # 3. Create a username and password
        yield motor.Op(cx.pymongo_test.add_user, "mike", "password")

        yield AssertRaises(
            pymongo.errors.OperationFailure,
            cx.copy_database,
            "pymongo_test",
            "pymongo_test0",
            username="foo",
            password="bar",
        )

        yield AssertRaises(
            pymongo.errors.OperationFailure,
            cx.copy_database,
            "pymongo_test",
            "pymongo_test0",
            username="mike",
            password="bar",
        )

        # 4. Copy a database using name and password
        for test_db_name in test_db_names:
            cx.copy_database(
                "pymongo_test",
                test_db_name,
                username="mike",
                password="password",
                callback=(yield gen.Callback(test_db_name)),
            )

        yield motor.WaitAllOps(test_db_names)
        check_copydb_results()

        drop_all()
        done()
开发者ID:chiehwen,项目名称:motor,代码行数:85,代码来源:test_motor_client.py

示例9: test_copy_db

    def test_copy_db(self):
        # 1. Drop old test DBs
        # 2. Copy a test DB N times at once (we need to do it many times at
        #   once to make sure that GreenletPool's start_request() is properly
        #   isolating operations from each other)
        # 3. Create a username and password
        # 4. Copy a database using name and password
        is_ms = server_is_master_with_slave(self.sync_cx)
        ncopies = 10
        nrange = list(range(ncopies))
        test_db_names = ['pymongo_test%s' % i for i in nrange]

        def check_copydb_results():
            db_names = self.sync_cx.database_names()
            for test_db_name in test_db_names:
                self.assertTrue(test_db_name in db_names)
                result = self.sync_cx[test_db_name].test_collection.find_one()
                self.assertTrue(result, "No results in %s" % test_db_name)
                self.assertEqual("bar", result.get("foo"),
                    "Wrong result from %s: %s" % (test_db_name, result))

        def drop_all():
            for test_db_name in test_db_names:
                # Setup code has configured a short timeout, and the copying
                # has put Mongo under enough load that we risk timeouts here
                # unless we override.
                self.sync_cx[test_db_name]['$cmd'].find_one(
                    {'dropDatabase': 1}, network_timeout=30)

            if not is_ms:
                # Due to SERVER-2329, databases may not disappear from a master
                # in a master-slave pair
                db_names = self.sync_cx.database_names()
                for test_db_name in test_db_names:
                    self.assertFalse(
                        test_db_name in db_names,
                        "%s not dropped" % test_db_name)

        # 1. Drop old test DBs
        yield self.cx.drop_database('pymongo_test')
        drop_all()

        # 2. Copy a test DB N times at once
        yield self.cx.pymongo_test.test_collection.insert({"foo": "bar"})
        yield [
            self.cx.copy_database("pymongo_test", test_db_name)
            for test_db_name in test_db_names]

        check_copydb_results()
        drop_all()

        # 3. Create a username and password
        yield self.cx.pymongo_test.add_user("mike", "password")

        with assert_raises(pymongo.errors.OperationFailure):
            yield self.cx.copy_database(
                "pymongo_test", "pymongo_test0",
                username="foo", password="bar")

        with assert_raises(pymongo.errors.OperationFailure):
            yield self.cx.copy_database(
                "pymongo_test", "pymongo_test0",
                username="mike", password="bar")

        # 4. Copy a database using name and password
        if not self.cx.is_mongos:
            # See SERVER-6427
            yield [
                self.cx.copy_database(
                    "pymongo_test", test_db_name,
                    username="mike", password="password")
                for test_db_name in test_db_names]

            check_copydb_results()

        drop_all()
开发者ID:MeirKriheli,项目名称:motor,代码行数:76,代码来源:test_motor_client.py


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