예제 #1
0
    def receive(self, num_msgs):
        start_time = time.time()
        timeout_stats = 'cherami_client_python.{}.receive.timeout'.format(
            self.tchannel.name)
        duration_stats = 'cherami_client_python.{}.receive.duration'.format(
            self.tchannel.name)

        msgs = []
        end_time = time.time() + self.timeout_seconds
        while len(msgs) < num_msgs:
            seconds_remaining = end_time - time.time()
            if seconds_remaining <= 0:
                stats.count(timeout_stats, 1)
                stats.timing(duration_stats,
                             util.time_diff_in_ms(start_time, time.time()))
                return msgs
            try:
                msgs.append(
                    self.msg_queue.get(block=True, timeout=seconds_remaining))
                self.msg_queue.task_done()

                util.stats_count(self.tchannel.name,
                                 'consumer_msg_queue.dequeue', None, 1)
            except queue.Empty:
                pass
        stats.timing(duration_stats,
                     util.time_diff_in_ms(start_time, time.time()))
        return msgs
예제 #2
0
def stats_count(client_name, stats_name, hostport, count):
    overall_stats = 'cherami_client_python.{}.{}'.format(
        client_name, stats_name)
    stats.count(overall_stats, count)

    if hostport:
        hostport_stats = 'cherami_client_python.{}.{}.{}'\
                            .format(client_name, hostport.replace('.', '_').replace(':', '_'), stats_name)
        stats.count(hostport_stats, count)
예제 #3
0
 def test_count_sample(self):
     stats.count('foo', 1, 0.5)
     line = mockserver.readline()
     self.assertEqual(line, 'foo:1|c|@0.500000')
예제 #4
0
 def test_count(self):
     stats.count('foo', 1)
     line = mockserver.readline()
     self.assertEqual(line, 'foo:1|c')
예제 #5
0
 def test_count_sample(self):
     stats.count('foo', 1, 0.5)
     line = mockserver.readline()
     self.assertEqual(line, 'foo:1|c|@0.500000')
예제 #6
0
 def test_count(self):
     stats.count('foo', 1)
     line = mockserver.readline()
     self.assertEqual(line, 'foo:1|c')