def test_record(self): d = DistributionSummary(self.tid, meter_type="D", writer=MemoryWriter()) self.assertTrue(d._writer.is_empty()) d.record(42) self.assertEqual("D:test:42", d._writer.last_line())
def test_record_multiple(self): t = DistributionSummary(DistributionSummaryTest.tid) t.record(42) t.record(2) t.record(7) self.assertEqual(t.count(), 3) self.assertEqual(t.total_amount(), 51)
def test_measure(self): t = DistributionSummary(DistributionSummaryTest.tid) t.record(42) t.record(2) t.record(7) ms = t._measure() def get_stat(s): return ms[DistributionSummaryTest.tid.with_stat(s)] self.assertEqual(len(ms), 4) self.assertEqual(get_stat('count'), 3) self.assertEqual(get_stat('totalAmount'), 51) self.assertEqual(get_stat('max'), 42) self.assertEqual(get_stat('totalOfSquares'), 42**2 + 2**2 + 7**2) self.assertEqual(t.count(), 0) self.assertEqual(t.total_amount(), 0)
def test_count_and_total_amount(self): """Avoid breaking the API.""" d = DistributionSummary(self.tid, writer=MemoryWriter()) self.assertTrue(d._writer.is_empty()) d.record(42) self.assertEqual(0, d.count()) self.assertEqual(0, d.total_amount())
def distribution_summary(self, name, tags=None): return self._new_meter(name, tags, lambda id: DistributionSummary(id), DistributionSummary, self.noopDistributionSummary)
def test_record_zero(self): d = DistributionSummary(self.tid, meter_type="D", writer=MemoryWriter()) d.record(0) self.assertEqual("D:test:0", d._writer.last_line())
def test_record_negative(self): d = DistributionSummary(self.tid, meter_type="D", writer=MemoryWriter()) d.record(-42) self.assertTrue(d._writer.is_empty())
def test_invalid_meter_type(self): with self.assertRaises(ValueError): DistributionSummary(self.tid, meter_type='x')
def test_record(self): t = DistributionSummary(DistributionSummaryTest.tid) t.record(42) self.assertEqual(t.count(), 1) self.assertEqual(t.total_amount(), 42)
def test_record_negative(self): t = DistributionSummary(DistributionSummaryTest.tid) t.record(-42) self.assertEqual(t.count(), 0) self.assertEqual(t.total_amount(), 0)
def pct_distribution_summary(self, name: str, tags: Optional[dict] = None) -> DistributionSummary: return DistributionSummary(self._new_meter(name, tags), meter_type="D", writer=self._writer)