本文整理汇总了Python中carbon.client.CarbonClientManager.stopClient方法的典型用法代码示例。如果您正苦于以下问题:Python CarbonClientManager.stopClient方法的具体用法?Python CarbonClientManager.stopClient怎么用?Python CarbonClientManager.stopClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类carbon.client.CarbonClientManager
的用法示例。
在下文中一共展示了CarbonClientManager.stopClient方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CarbonClientManagerTest
# 需要导入模块: from carbon.client import CarbonClientManager [as 别名]
# 或者: from carbon.client.CarbonClientManager import stopClient [as 别名]
class CarbonClientManagerTest(TestCase):
timeout = 1.0
def setUp(self):
self.router_mock = Mock(spec=DatapointRouter)
self.factory_mock = Mock(spec=CarbonPickleClientFactory)
self.client_mgr = CarbonClientManager(self.router_mock)
self.client_mgr.createFactory = lambda dest: self.factory_mock(dest, self.router_mock)
def test_start_service_installs_sig_ignore(self):
from signal import SIGHUP, SIG_IGN
with patch('signal.signal', new=Mock()) as signal_mock:
self.client_mgr.startService()
signal_mock.assert_called_once_with(SIGHUP, SIG_IGN)
def test_start_service_starts_factory_connect(self):
factory_mock = Mock(spec=CarbonPickleClientFactory)
factory_mock.started = False
self.client_mgr.client_factories[('127.0.0.1', 2003, 'a')] = factory_mock
self.client_mgr.startService()
factory_mock.startConnecting.assert_called_once_with()
def test_stop_service_waits_for_clients_to_disconnect(self):
dest = ('127.0.0.1', 2003, 'a')
self.client_mgr.startService()
self.client_mgr.startClient(dest)
disconnect_deferred = Deferred()
reactor.callLater(0.1, disconnect_deferred.callback, 0)
self.factory_mock.return_value.disconnect.return_value = disconnect_deferred
return self.client_mgr.stopService()
def test_start_client_instantiates_client_factory(self):
dest = ('127.0.0.1', 2003, 'a')
self.client_mgr.startClient(dest)
self.factory_mock.assert_called_once_with(dest, self.router_mock)
def test_start_client_ignores_duplicate(self):
dest = ('127.0.0.1', 2003, 'a')
self.client_mgr.startClient(dest)
self.client_mgr.startClient(dest)
self.factory_mock.assert_called_once_with(dest, self.router_mock)
def test_start_client_starts_factory_if_running(self):
dest = ('127.0.0.1', 2003, 'a')
self.client_mgr.startService()
self.client_mgr.startClient(dest)
self.factory_mock.return_value.startConnecting.assert_called_once_with()
def test_start_client_adds_destination_to_router(self):
dest = ('127.0.0.1', 2003, 'a')
self.client_mgr.startClient(dest)
self.router_mock.addDestination.assert_called_once_with(dest)
def test_stop_client_removes_destination_from_router(self):
dest = ('127.0.0.1', 2003, 'a')
self.client_mgr.startClient(dest)
self.client_mgr.stopClient(dest)
self.router_mock.removeDestination.assert_called_once_with(dest)