def test_finished_collection_stateless(self):
     meter_provider = metrics.MeterProvider()
     meter = meter_provider.get_meter(__name__)
     processor = Processor(False, meter_provider.resource)
     aggregator = SumAggregator()
     metric = metrics.Counter("available memory", "available memory",
                              "bytes", int, meter)
     aggregator.update(1.0)
     labels = ()
     _batch_map = {}
     _batch_map[(metric, SumAggregator, tuple(), labels)] = aggregator
     processor._batch_map = _batch_map
     processor.finished_collection()
     self.assertEqual(len(processor._batch_map), 0)
 def test_checkpoint_set(self):
     meter_provider = metrics.MeterProvider()
     meter = meter_provider.get_meter(__name__)
     processor = Processor(True, meter_provider.resource)
     aggregator = SumAggregator()
     metric = metrics.Counter("available memory", "available memory",
                              "bytes", int, meter)
     aggregator.update(1.0)
     labels = ()
     _batch_map = {}
     _batch_map[(metric, SumAggregator, tuple(), labels)] = aggregator
     processor._batch_map = _batch_map
     records = processor.checkpoint_set()
     self.assertEqual(len(records), 1)
     self.assertEqual(records[0].instrument, metric)
     self.assertEqual(records[0].labels, labels)
     self.assertEqual(records[0].aggregator, aggregator)
 def test_processor_process_not_exists(self):
     meter_provider = metrics.MeterProvider()
     meter = meter_provider.get_meter(__name__)
     processor = Processor(True, meter_provider.resource)
     aggregator = SumAggregator()
     metric = metrics.Counter("available memory", "available memory",
                              "bytes", int, meter)
     labels = ()
     _batch_map = {}
     batch_key = (metric, SumAggregator, tuple(), labels)
     aggregator.update(1.0)
     processor._batch_map = _batch_map
     record = metrics.Record(metric, labels, aggregator)
     processor.process(record)
     self.assertEqual(len(processor._batch_map), 1)
     self.assertIsNotNone(processor._batch_map.get(batch_key))
     self.assertEqual(processor._batch_map.get(batch_key).current, 0)
     self.assertEqual(processor._batch_map.get(batch_key).checkpoint, 1.0)