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


Python Server.reset方法代碼示例

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


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

示例1: ServerTestCase

# 需要導入模塊: from mongo_orchestration.servers import Server [as 別名]
# 或者: from mongo_orchestration.servers.Server import reset [as 別名]

#.........這裏部分代碼省略.........
            self.assertTrue(item in info)

        self.assertTrue(info['mongodb_uri'].find(info['uri']))
        self.assertTrue(info['mongodb_uri'].find('mongodb://') == 0)
        fd_log, log_path = tempfile.mkstemp()
        os.close(fd_log)
        db_path = tempfile.mkdtemp()
        params = {'logpath': log_path, 'dbpath': db_path}
        server2 = Server(self.mongod, params)
        server2.start()
        info2 = server2.info()
        for param, value in params.items():
            self.assertTrue(info2['procInfo']['params'].get(param, value) == value)
        server2.stop()
        info = server2.info()
        self.assertEqual(len(info['serverInfo']), 0)
        self.assertEqual(len(info['statuses']), 0)
        self.assertEqual(info['orchestration'], 'servers')
        server2.cleanup()

    def test_command(self):
        self.assertRaises(pymongo.errors.PyMongoError, self.server.run_command, 'serverStatus', None, False)
        self.server.start(30)
        self.assertEqual(self.server.run_command('serverStatus', arg=None, is_eval=False).get('ok', -1), 1)
        self.assertEqual(self.server.run_command('db.getName()', arg=None, is_eval=True), 'admin')

    def test_start(self):
        self.assertNotIn('pid', self.server.info()['procInfo'])
        self.assertTrue(self.server.start(30))
        self.assertTrue(self.server.info()['procInfo']['pid'] > 0)

        fake_server = Server('fake_proc_', {})
        self.assertRaises(OSError, fake_server.start, 5)
        fake_server.cleanup()

    def test_start_with_repair(self):
        self.server.cleanup()
        self.server = Server(self.mongod, {"journal": False})
        self.server.start(30)
        os.kill(self.server.pid, 9)
        self.assertTrue(self.server._is_locked)
        self.assertTrue(self.server.start(20))

    def test_stop(self):
        self.assertTrue(self.server.start(60))
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server = self.server.hostname.split(':')[0]
        s.connect((server, self.server.cfg['port']))
        self.assertTrue(self.server.stop())
        self.assertRaises(socket.error, s.connect, (server, self.server.cfg['port']))

    def test_restart(self):
        self.assertTrue(self.server.start(30))
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server = self.server.hostname.split(':')[0]
        s.connect((server, self.server.cfg['port']))
        s.shutdown(0)
        s.close()
        self.assertTrue(self.server.restart(30))
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((server, self.server.cfg['port']))
        s.shutdown(0)
        s.close()

    def test_is_alive(self):
        self.server.start()
        self.assertTrue(self.server.is_alive)
        self.server.stop()
        self.assertFalse(self.server.is_alive)
        self.server.restart()
        self.assertTrue(self.server.is_alive)

    def test_set_parameter(self):
        cfg = {"setParameter": {"textSearchEnabled": True,
                                "enableTestCommands": 1}}
        server = Server(self.mongod, cfg)
        server.start()
        c = pymongo.MongoClient(server.hostname)
        c.foo.bar.insert({"data": "text stuff"})
        # No Exception.
        c.foo.bar.ensure_index([("data", pymongo.TEXT)])
        # No Exception.
        c.admin.command("sleep", secs=1)

    def test_cleanup(self):
        self.server.start(80)
        self.assertTrue(os.path.exists(self.server.cfg['dbpath']))
        self.assertTrue(os.path.exists(self.server.config_path))
        self.server.stop()
        self.server.cleanup()
        self.assertFalse(os.path.exists(self.server.cfg['dbpath']))
        self.assertFalse(os.path.exists(self.server.config_path))

    def test_reset(self):
        self.server.stop()
        self.assertRaises(pymongo.errors.ConnectionFailure,
                          pymongo.MongoClient, self.server.hostname)
        self.server.reset()
        # No ConnectionFailure.
        pymongo.MongoClient(self.server.hostname)
開發者ID:jyemin,項目名稱:mongo-orchestration,代碼行數:104,代碼來源:test_servers.py


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