def test_custom_counter(self): sock = self.patched['shumway.socket.socket'].mock_instance mr = shumway.MetricRelay('key') mr.set_counter( 'test', shumway.Counter('test', 'key', attributes={'k': 'v'}, tags=['foo::bar'])) mr.incr('test') mr.flush() metric = { 'key': 'key', 'attributes': { 'what': 'test', 'k': 'v' }, 'value': 1, 'type': 'metric', 'tags': ['foo::bar'] } sock.sendto.assert_called_once_with( json.dumps(metric).encode('utf-8'), mr._ffwd_address)
def test_flush_with_tags(self): send_metric = mock.Mock() C = shumway.Counter('test', 'key', tags=['test::tag']) C.incr() C.flush(send_metric) send_metric.assert_called_once_with({ 'key': 'key', 'attributes': { 'what': 'test' }, 'value': 1, 'tags': ['test::tag'], 'type': 'metric' })
def test_flush_with_attributes(self): send_metric = mock.Mock() C = shumway.Counter('test', 'key', attributes={'k': 'v'}) C.incr() C.flush(send_metric) send_metric.assert_called_once_with({ 'key': 'key', 'attributes': { 'what': 'test', 'k': 'v' }, 'resources': {}, 'value': 1, 'tags': [], 'type': 'metric' })
def test_incr_by_value(self): C = shumway.Counter('test', 'key') C.incr(3) self.assertEqual(C.value, 3)
def test_incr_twice(self): C = shumway.Counter('test', 'key') C.incr() C.incr() self.assertEqual(C.value, 2)
def test_intial_value(self): C = shumway.Counter('test', 'key', value=4) C.incr(4) self.assertEqual(C.value, 8)