コード例 #1
0
class TestStatsd(object):
    def setup(self):
        if StatsdOutput is None:
            raise SkipTest
        self.client_proxy = StatsdOutput('localhost')
        self.client = self.client_proxy.clients[0]

    def test_statsd_incr(self):
        ctx = patch.object(self.client, 'incr')
        with ctx:
            self.client_proxy.deliver({'fields': {'name': 'testing.statsd',
                                       'type': 'counter',
                                       'rate': '1'},
                            'payload': 2})

            method = self.client.incr
            eq_(len(method.call_args_list), 1)

            call_msg = method.call_args_list[0]
            eq_(call_msg[0], ('testing.statsd', 2.0, 1.0))

    def test_statsd_timing(self):
        ctx = patch.object(self.client, 'timing')
        with ctx:
            self.client_proxy.deliver({'fields': {'name': 'testing.statsd',
                                       'type': 'timer',
                                       'rate': '4'},
                            'payload': 5})

            method = self.client.timing
            eq_(len(method.call_args_list), 1)

            call_msg = method.call_args_list[0]
            eq_(call_msg[0], ('testing.statsd', 5.0, 4.0))

    def test_statsd_gauge(self):
        ctx = patch.object(self.client, 'gauge')
        with ctx:
            self.client_proxy.deliver({'fields': {'name': 'testing.statsd',
                                       'type': 'gauge',
                                       'rate': '8'},
                            'payload': 3})

            method = self.client.gauge
            eq_(len(method.call_args_list), 1)

            call_msg = method.call_args_list[0]
            eq_(call_msg[0], ('testing.statsd', 3.0, 8.0))
コード例 #2
0
 def setup(self):
     if StatsdOutput is None:
         raise SkipTest
     self.client_proxy = StatsdOutput('localhost')
     self.client = self.client_proxy.clients[0]