本文整理匯總了Python中carbon.client.CarbonClientManager.startService方法的典型用法代碼示例。如果您正苦於以下問題:Python CarbonClientManager.startService方法的具體用法?Python CarbonClientManager.startService怎麽用?Python CarbonClientManager.startService使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類carbon.client.CarbonClientManager
的用法示例。
在下文中一共展示了CarbonClientManager.startService方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: CarbonClientManagerTest
# 需要導入模塊: from carbon.client import CarbonClientManager [as 別名]
# 或者: from carbon.client.CarbonClientManager import startService [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)