Exemplo n.º 1
0
    def test_populate_buckets_underflow(self):
        pb = metrics_pb2.MetricsData()
        m = metrics.DistributionMetric('test')
        d = distribution.Distribution(
            distribution.FixedWidthBucketer(10, num_finite_buckets=10))
        d.add(-5)
        d.add(-1000000)

        m._populate_value(pb, d, 1234)
        self.assertEquals([], pb.distribution.bucket)
        self.assertEquals(2, pb.distribution.underflow)
        self.assertEquals(0, pb.distribution.overflow)
        self.assertEquals(-500002.5, pb.distribution.mean)
Exemplo n.º 2
0
    def test_populate_custom(self):
        pb = metrics_pb2.MetricsData()
        m = metrics.DistributionMetric('test')
        m._populate_value(
            pb, distribution.Distribution(distribution.GeometricBucketer(4)),
            1234)
        self.assertEquals(
            pb.distribution.spec_type,
            metrics_pb2.PrecomputedDistribution.CUSTOM_PARAMETERIZED)
        self.assertEquals(0, pb.distribution.width)
        self.assertEquals(4, pb.distribution.growth_factor)
        self.assertEquals(100, pb.distribution.num_buckets)

        m._populate_value(
            pb, distribution.Distribution(distribution.FixedWidthBucketer(10)),
            1234)
        self.assertEquals(
            pb.distribution.spec_type,
            metrics_pb2.PrecomputedDistribution.CUSTOM_PARAMETERIZED)
        self.assertEquals(10, pb.distribution.width)
        self.assertEquals(0, pb.distribution.growth_factor)
        self.assertEquals(100, pb.distribution.num_buckets)
Exemplo n.º 3
0
    def test_populate_canonical(self):
        pb = metrics_pb2.MetricsData()
        m = metrics.DistributionMetric('test')
        m._populate_value(
            pb, distribution.Distribution(distribution.GeometricBucketer()),
            1234)
        self.assertEquals(
            pb.distribution.spec_type,
            metrics_pb2.PrecomputedDistribution.CANONICAL_POWERS_OF_10_P_0_2)

        m._populate_value(
            pb, distribution.Distribution(distribution.GeometricBucketer(2)),
            1234)
        self.assertEquals(
            pb.distribution.spec_type,
            metrics_pb2.PrecomputedDistribution.CANONICAL_POWERS_OF_2)

        m._populate_value(
            pb, distribution.Distribution(distribution.GeometricBucketer(10)),
            1234)
        self.assertEquals(
            pb.distribution.spec_type,
            metrics_pb2.PrecomputedDistribution.CANONICAL_POWERS_OF_10)