示例#1
0
class TestInternalMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "1"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.daemon._internal_publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteInternalMetric(self):
        metric = ["name", 0.0, "now", {}]
        internal_metric = ["name", 0.0, "now", {"internal": True}]
        self.metric_writer.write_metric(*metric)
        self.metric_writer.write_metric(*internal_metric)
        self.assertEquals([tuple(internal_metric)], self.daemon._internal_publisher.queue)
        self.assertEquals([tuple(metric), tuple(internal_metric)], self.daemon._publisher.queue)

    def testInternalPublisherIsNone(self):
        self.daemon._internal_publisher = None
        del os.environ["CONTROLPLANE_CONSUMER_URL"]
        self.assertIsNone(self.daemon.internalPublisher())

    def testInternalPublisherIsInstance(self):
        self.daemon._internal_publisher = None
        os.environ["CONTROLPLANE_CONSUMER_URL"] = "http://localhost"
        publisher = self.daemon.internalPublisher()
        from Products.ZenHub.metricpublisher.publisher import HttpPostPublisher

        self.assertIsInstance(publisher, HttpPostPublisher)
示例#2
0
class TestInternalMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "1"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.daemon._internal_publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteInternalMetric(self):
        metric = ["name", 0.0, "now", {}]
        internal_metric = ["name", 0.0, "now", {"internal": True}]
        self.metric_writer.write_metric(*metric)
        self.metric_writer.write_metric(*internal_metric)
        self.assertEquals([tuple(internal_metric)],
                          self.daemon._internal_publisher.queue)
        self.assertEquals(
            [tuple(metric), tuple(internal_metric)],
            self.daemon._publisher.queue)

    def testInternalPublisherIsNone(self):
        self.daemon._internal_publisher = None
        del os.environ["CONTROLPLANE_CONSUMER_URL"]
        self.assertIsNone(self.daemon.internalPublisher())

    def testInternalPublisherIsInstance(self):
        self.daemon._internal_publisher = None
        os.environ["CONTROLPLANE_CONSUMER_URL"] = "http://localhost"
        publisher = self.daemon.internalPublisher()
        from Products.ZenHub.metricpublisher.publisher import HttpPostPublisher
        self.assertIsInstance(publisher, HttpPostPublisher)
示例#3
0
class TestMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "0"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteMetric(self):
        metric = ["name", 0.0, "now", {}]
        self.metric_writer.write_metric(*metric)
        self.assertEquals([tuple(metric)], self.daemon._publisher.queue)
示例#4
0
class TestMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "0"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteMetric(self):
        metric = ["name", 0.0, "now", {}]
        self.metric_writer.write_metric(*metric)
        self.assertEquals([tuple(metric)], self.daemon._publisher.queue)