OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import unittest |
| 6 |
| 7 from infra_libs.ts_mon.common import monitors |
| 8 from infra_libs.ts_mon.common import pb_to_popo |
| 9 from infra_libs.ts_mon.protos import acquisition_network_device_pb2 |
| 10 from infra_libs.ts_mon.protos import acquisition_task_pb2 |
| 11 from infra_libs.ts_mon.protos import metrics_pb2 |
| 12 |
| 13 class PbToPopoTest(unittest.TestCase): |
| 14 |
| 15 def test_convert(self): |
| 16 task = acquisition_task_pb2.Task(service_name='service') |
| 17 network_device = acquisition_network_device_pb2.NetworkDevice( |
| 18 hostname='host', alertable=True) |
| 19 metric1 = metrics_pb2.MetricsData( |
| 20 name='m1', counter=200, task=task, |
| 21 units=metrics_pb2.MetricsData.Units.Value('SECONDS')) |
| 22 metric2 = metrics_pb2.MetricsData(name='m2', network_device=network_device, |
| 23 cumulative_double_value=123.456) |
| 24 collection = metrics_pb2.MetricsCollection(data=[metric1, metric2], |
| 25 start_timestamp_us=12345) |
| 26 |
| 27 popo = pb_to_popo.convert(collection) |
| 28 expected = { |
| 29 'data': [ |
| 30 { |
| 31 'name': 'm1', |
| 32 'counter': 200L, |
| 33 'task': { 'service_name': 'service' }, |
| 34 'units': 1 |
| 35 }, |
| 36 { |
| 37 'name': 'm2', |
| 38 'cumulative_double_value': 123.456, |
| 39 'network_device': { 'hostname': 'host', 'alertable': True } |
| 40 } |
| 41 ], |
| 42 'start_timestamp_us': 12345L |
| 43 } |
| 44 self.assertDictEqual(expected, popo) |
| 45 |
OLD | NEW |