コード例 #1
0
 def test_publish(self):
     publisher = StatsPublisher()
     publisher.socket = mock.MagicMock()
     stat = {'subtopic': 1, 'foo': 'bar'}
     publisher.publish('foobar', stat)
     publisher.socket.send_multipart.assert_called_with(
         ['stat.foobar.1', json.dumps(stat)])
コード例 #2
0
 def __init__(self,
              endpoint,
              pubsub_endoint,
              stats_endpoint,
              ssh_server,
              delay=1.):
     self.topic = 'watcher.'
     self.delay = delay
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = ioloop.IOLoop.instance()  # events coming from circusd
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx,
                                endpoint=endpoint,
                                ssh_server=ssh_server)
     self.cmds = get_commands()
     self._pids = defaultdict(list)
     self._callbacks = dict()
     self.publisher = StatsPublisher(stats_endpoint, self.ctx)
     self.running = False  # should the streamer be running?
     self.stopped = False  # did the collect started yet?
     self.circus_pids = {}
     self.sockets = []
コード例 #3
0
    def test_publish_silent_zmq_errors_when_socket_closed(self):
        publisher = StatsPublisher()
        publisher.socket = mock.MagicMock()
        publisher.socket.closed = True
        publisher.socket.send_multipart.side_effect = zmq.ZMQError()

        stat = {'subtopic': 1, 'foo': 'bar'}
        publisher.publish('foobar', stat)
コード例 #4
0
    def test_publish_reraise_zmq_errors(self):
        publisher = StatsPublisher()
        publisher.socket = mock.MagicMock()
        publisher.socket.closed = False
        publisher.socket.send_multipart.side_effect = zmq.ZMQError()

        stat = {'subtopic': 1, 'foo': 'bar'}
        self.assertRaises(zmq.ZMQError, publisher.publish, 'foobar', stat)
コード例 #5
0
 def __init__(self, endpoint, pubsub_endoint, stats_endpoint,
              ssh_server=None, delay=1., loop=None):
     self.topic = b'watcher.'
     self.delay = delay
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = loop or ioloop.IOLoop.current()
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx, endpoint=endpoint,
                                ssh_server=ssh_server)
     self.cmds = get_commands()
     self.publisher = StatsPublisher(stats_endpoint, self.ctx)
     self._initialize()
コード例 #6
0
 def __init__(self, endpoint, pubsub_endoint, stats_endpoint):
     self.topic = 'watcher.'
     self.ctx = zmq.Context()
     self.pubsub_endpoint = pubsub_endoint
     self.sub_socket = self.ctx.socket(zmq.SUB)
     self.sub_socket.setsockopt(zmq.SUBSCRIBE, self.topic)
     self.sub_socket.connect(self.pubsub_endpoint)
     self.loop = ioloop.IOLoop()
     self.substream = zmqstream.ZMQStream(self.sub_socket, self.loop)
     self.substream.on_recv(self.handle_recv)
     self.client = CircusClient(context=self.ctx, endpoint=endpoint)
     self.cmds = get_commands()
     self.watchers = defaultdict(list)
     self._pids = defaultdict(list)
     self.running = False
     self.stopped = False
     self.lock = threading.RLock()
     self.results = Queue.Queue()
     self.stats = StatsCollector(self)
     self.publisher = StatsPublisher(self, stats_endpoint, context=self.ctx)
コード例 #7
0
 def setUp(self):
     self.publisher = StatsPublisher()
     self.origin_socket = self.publisher.socket
     self.publisher.socket = mock.MagicMock()