示例#1
0
    def test_start_time_set(self):
        d = DistributionCell()
        d.update(3.1)

        name = MetricName('namespace', 'name1')
        mi = d.to_runner_api_monitoring_info(name, 'transform_id')
        self.assertGreater(mi.start_time.seconds, 0)
示例#2
0
  def test_basic_operations(self):
    d = DistributionCell()
    d.update(10)
    self.assertEqual(d.get_cumulative(),
                     DistributionData(10, 1, 10, 10))

    d.update(2)
    self.assertEqual(d.get_cumulative(),
                     DistributionData(12, 2, 2, 10))

    d.update(900)
    self.assertEqual(d.get_cumulative(),
                     DistributionData(912, 3, 2, 900))
示例#3
0
  def test_parallel_access(self):
    # We create NUM_THREADS threads that concurrently modify the distribution.
    threads = []
    d = DistributionCell()
    for _ in range(TestDistributionCell.NUM_THREADS):
      t = threading.Thread(target=TestDistributionCell._modify_distribution,
                           args=(d,))
      threads.append(t)
      t.start()

    for t in threads:
      t.join()

    total = (self.NUM_ITERATIONS * (self.NUM_ITERATIONS-1)/2 * self.NUM_THREADS)

    count = (self.NUM_ITERATIONS * self.NUM_THREADS)

    self.assertEqual(d.get_cumulative(),
                     DistributionData(total, count, 0,
                                      self.NUM_ITERATIONS - 1))
示例#4
0
    def test_parallel_access(self):
        # We create NUM_THREADS threads that concurrently modify the distribution.
        threads = []
        d = DistributionCell()
        for _ in range(TestDistributionCell.NUM_THREADS):
            t = threading.Thread(
                target=TestDistributionCell._modify_distribution, args=(d, ))
            threads.append(t)
            t.start()

        for t in threads:
            t.join()

        total = (self.NUM_ITERATIONS * (self.NUM_ITERATIONS - 1) // 2 *
                 self.NUM_THREADS)

        count = (self.NUM_ITERATIONS * self.NUM_THREADS)

        self.assertEqual(
            d.get_cumulative(),
            DistributionData(total, count, 0, self.NUM_ITERATIONS - 1))
示例#5
0
 def test_integer_only(self):
   d = DistributionCell()
   d.update(3.1)
   d.update(3.2)
   d.update(3.3)
   self.assertEqual(d.get_cumulative(),
                    DistributionData(9, 3, 3, 3))
示例#6
0
 def __init__(self, step_name):
     self.step_name = step_name
     self.counters = defaultdict(lambda: CounterCell())
     self.distributions = defaultdict(lambda: DistributionCell())
     self.gauges = defaultdict(lambda: GaugeCell())
示例#7
0
 def test_integer_only(self):
     d = DistributionCell()
     d.update(3.1)
     d.update(3.2)
     d.update(3.3)
     self.assertEqual(d.get_cumulative(), DistributionData(9, 3, 3, 3))
示例#8
0
    def test_basic_operations(self):
        d = DistributionCell()
        d.update(10)
        self.assertEqual(d.get_cumulative(), DistributionData(10, 1, 10, 10))

        d.update(2)
        self.assertEqual(d.get_cumulative(), DistributionData(12, 2, 2, 10))

        d.update(900)
        self.assertEqual(d.get_cumulative(), DistributionData(912, 3, 2, 900))