def test_successful_error_metric(self, mock_publish): c = Collector(self.config_object(), []) mock_socket = Mock() c._socket = mock_socket with patch.object(c, "log"): try: c.publish("metric", "bar") except DiamondException: pass for call in mock_publish.mock_calls: name, args, kwargs = call metric = args[0] self.assertEqual(metric.path, "servers.Collector.fullerite.collector_errors")
def test_successful_error_metric(self, mock_publish): c = Collector(self.config_object(), []) mock_socket = Mock() c._socket = mock_socket with patch.object(c, 'log'): try: c.publish('metric', "bar") except DiamondException: pass for call in mock_publish.mock_calls: name, args, kwargs = call metric = args[0] self.assertEqual(metric.path, "servers.Collector.qcollect.collector_errors")
def test_batch_size_flush(self): c = Collector(self.config_object(), []) mock_socket = Mock() c._socket = mock_socket c._reconnect = False c.config["max_buffer_size"] = 2 with patch.object(c, "log"): try: c.publish("metric1", 1) c.publish("metric2", 2) c.publish("metric3", 3) except DiamondException: pass self.assertEquals(mock_socket.sendall.call_count, 1) self.assertEquals(len(c.payload), 1)
def test_batch_size_flush(self): c = Collector(self.config_object(), []) mock_socket = Mock() c._socket = mock_socket c._reconnect = False c.config['max_buffer_size'] = 2 with patch.object(c, 'log'): try: c.publish('metric1', 1) c.publish('metric2', 2) c.publish('metric3', 3) except DiamondException: pass self.assertEquals(mock_socket.sendall.call_count, 1) self.assertEquals(len(c.payload), 1)
def test_can_publish_metric(self): c = Collector(self.config_object(), []) self.assertFalse(c.can_publish_metric()) c._socket = "socket" self.assertTrue(c.can_publish_metric())
def test_can_publish_metric(self): c = Collector(self.config_object(), []) self.assertFalse(c.can_publish_metric()) c._socket = "socket" self.assertTrue(c.can_publish_metric())