コード例 #1
0
class TestMetricLinear(TestCase):
    def setUp(self):
        self.sli = SLIMetricReporter('test', {
                        "red": BelowCondition(5, 1),
                        "yellow": BelowCondition(3, 1)})

    def test_count_threshold(self):
        self.assertEquals(self.sli.count, 0)
        self.assertEquals(self.sli.counts["red"], 0)
        self.assertEquals(self.sli.counts["yellow"], 0)
        for i in range(1, 7):
            self.sli.update(7, i)
        self.assertEquals(self.sli.count, 6)
        self.assertEquals(self.sli.counts["red"], 4)
        self.assertEquals(self.sli.counts["yellow"], 2)
コード例 #2
0
class TestMetric(TestCase):
    def setUp(self):
        self.sli = SLIMetricReporter('test', {
                        "red": BelowCondition(5),
                        "yellow": BelowCondition(3)})

    def test_count_all(self):
        self.sli.update(1)
        self.sli.update(1)
        self.assertEquals(self.sli.count, 2)

    def test_count_error(self):
        self.sli.update(1)
        self.sli.update("error")
        self.assertEquals(self.sli.count, 2)
        self.assertEquals(self.sli.error, 1)
        self.assertEquals(self.sli.counts["red"], 1)

    def test_count_threshold(self):
        self.assertEquals(self.sli.count, 0)
        self.assertEquals(self.sli.counts["red"], 0)
        self.assertEquals(self.sli.counts["yellow"], 0)
        for i in range(1, 7):
            self.sli.update(i)
        self.assertEquals(self.sli.count, 6)
        self.assertEquals(self.sli.counts["red"], 4)
        self.assertEquals(self.sli.counts["yellow"], 2)

    def test_reports(self):
        self.test_count_threshold()
        rows = sorted(self.sli.flush(0, 0))
        self.assertEquals(
            [("test.count", 6, 0),
            ("test.count_red", 4, 0),
            ("test.count_yellow", 2, 0),
            ("test.error", 0, 0)],
            rows)

    def test_clear(self):
        self.sli.update(1)
        self.sli.update(1)
        self.assertEquals(self.sli.count, 2)
        self.sli.flush(0, 0)
        self.sli.update(1)
        self.assertEquals(self.sli.count, 1)