예제 #1
0
 def test_panoptes_influxdb_connection_ping_exception(self):
     with patch(
             'yahoo_panoptes.consumers.influxdb.consumer.PanoptesInfluxDBConnection.ping',
             Mock(side_effect=Exception)):
         with self.assertRaises(SystemExit):
             PanoptesInfluxDBConsumer.factory()
             unittest.main(exit=False)
예제 #2
0
    def test_panoptes_influxdb_consumer(self):
        """Test sending metrics through the InfluxDB client"""

        output_data_file = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            u'output/influx_line00.data')

        output_data = open(output_data_file).read()

        MockPanoptesConsumer.files = [
            u'consumers/influxdb/input/metrics_group00.json',
        ]

        with requests_mock.Mocker() as m:
            m.register_uri('POST',
                           "http://127.0.0.1:8086/write",
                           status_code=204)
            PanoptesInfluxDBConsumer.factory()
            self.assertEquals(m.last_request.body.decode("utf-8"), output_data)

        # Fail on first write to try _send_one_by_one
        with requests_mock.Mocker() as m:
            m.register_uri('POST',
                           "http://127.0.0.1:8086/write",
                           response_list=[{
                               u'status_code': 400
                           }, {
                               u'status_code': 204
                           }])
            PanoptesInfluxDBConsumer.factory()
            self.assertEquals(m.last_request.body.decode("utf-8"), output_data)
예제 #3
0
 def test_influxdb_consumer_parser_exception(self):
     mock_argument_parser = Mock()
     attributes = {u'parse_known_args.side_effect': Exception}
     mock_argument_parser.configure_mock(**attributes)
     with patch(
             'yahoo_panoptes.consumers.influxdb.consumer.argparse.ArgumentParser',
             mock_argument_parser):
         with self.assertRaises(SystemExit):
             PanoptesInfluxDBConsumer.factory()
             unittest.main(exit=False)
예제 #4
0
    def test_panoptes_influxdb_consumer(self):
        "Default Test"

        output_data_file = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            'output/influx_line00.data')

        output_data = open(output_data_file).read()

        MockPanoptesConsumer.files = [
            'consumers/influxdb/input/metrics_group00.json',
            'consumers/influxdb/input/metrics_group01.json',
            'consumers/influxdb/input/metrics_group02.json'
        ]

        with requests_mock.Mocker() as m:
            m.register_uri(requests_mock.POST,
                           "http://localhost:8086/write",
                           status_code=204)

            PanoptesInfluxDBConsumer.factory()

            self.assertEquals(m.last_request.body, output_data)
예제 #5
0
 def test_panoptes_influxdb_consumer02(self):
     """Test with bad PanoptesContext"""
     with self.assertRaises(SystemExit):
         PanoptesInfluxDBConsumer.factory()
예제 #6
0
 def test_panoptes_influxdb_consumer_bad_context(self):
     """Test with bad PanoptesContext"""
     with self.assertRaises(SystemExit):
         PanoptesInfluxDBConsumer.factory()
         unittest.main(exit=False)
예제 #7
0
 def test_influxdb_consumer_bad_configuration_file(self):
     with self.assertRaises(SystemExit):
         PanoptesInfluxDBConsumer('non.existent.config.file')
         unittest.main(exit=False)