def testRetryFetch(self, url_open_mock): stop_handler = bind_signal_handlers() config = Configuration() application_metric_map = ApplicationMetricMap("host","10.10.10.10") application_metric_map.clear() application_metric_map.put_metric("APP1", {"metric1":1}, 1) emitter = Emitter(config, application_metric_map, stop_handler) emitter.RETRY_SLEEP_INTERVAL = .001 emitter.submit_metrics() self.assertEqual(url_open_mock.call_count, 3) self.assertUrlData(url_open_mock)
def testRetryFetchAndRoundRobin(self, request_mock): stop_handler = bind_signal_handlers() request_mock.return_value = MagicMock() config = Configuration() application_metric_map = ApplicationMetricMap("host","10.10.10.10") application_metric_map.clear() application_metric_map.put_metric("APP1", {"metric1":1}, 1) emitter = Emitter(config, application_metric_map, stop_handler) emitter.RETRY_SLEEP_INTERVAL = .001 emitter.submit_metrics() self.assertEqual(request_mock.call_count, 9) self.assertUrlData(request_mock)
def test_submit_metrics(self, getresponse_mock, request_mock): request_mock.return_value = MagicMock() getresponse_mock.return_value = MagicMock() getresponse_mock.return_value.status = 200 stop_handler = bind_signal_handlers() config = Configuration() application_metric_map = ApplicationMetricMap("host", "10.10.10.10") application_metric_map.clear() application_metric_map.put_metric("APP1", {"metric1": 1}, 1) emitter = Emitter(config, application_metric_map, stop_handler) emitter.submit_metrics() self.assertEqual(request_mock.call_count, 1) self.assertUrlData(request_mock)
def testJavaHomeAvailableCheck(self, url_open_mock): url_open_mock.return_value = MagicMock() url_open_mock.return_value.getcode.return_value = 200 self.assertEqual(urllib2.urlopen(None, None).getcode(), 200) url_open_mock.reset_mock() stop_handler = bind_signal_handlers() config = Configuration() application_metric_map = ApplicationMetricMap("host","10.10.10.10") application_metric_map.clear() application_metric_map.put_metric("APP1", {"metric1":1}, 1) emitter = Emitter(config, application_metric_map, stop_handler) emitter.submit_metrics() self.assertEqual(url_open_mock.call_count, 1) self.assertUrlData(url_open_mock)