public void CreateMetrics_CountAgg_ReturnsExpected()
        {
            var opts          = new CloudFoundryForwarderOptions();
            var stats         = new OpenCensusStats();
            var tagsComponent = new TagsComponent();
            var tagger        = tagsComponent.Tagger;
            var ep            = new SpringBootMetricWriter(opts, stats);

            IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes);

            SetupTestView(stats, Count.Create(), testMeasure, "test.test1");

            ITagContext context1 = tagger
                                   .EmptyBuilder
                                   .Put(TagKey.Create("a"), TagValue.Create("v1"))
                                   .Put(TagKey.Create("b"), TagValue.Create("v1"))
                                   .Put(TagKey.Create("c"), TagValue.Create("v1"))
                                   .Build();

            long allKeyssum = 0;

            for (int i = 0; i < 10; i++)
            {
                allKeyssum = allKeyssum + i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1);
            }

            var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1"));

            Assert.NotNull(viewData);
            var aggMap = viewData.AggregationMap;

            Assert.Single(aggMap);

            var tagValues = aggMap.Keys.Single();
            var data      = aggMap.Values.Single();

            Assert.NotNull(tagValues);
            Assert.NotNull(data);

            var result = ep.CreateMetrics(viewData, data, tagValues, 1L);

            Assert.NotNull(result);
            Assert.Single(result);
            var metric = result[0];

            Assert.Equal("test.test1.v1.v1.v1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("bytes", metric.Unit);
            Assert.Equal(10, metric.Value);
            var tags = metric.Tags;

            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);
        }
        public void CreateMetrics_DistributionAgg_ReturnsExpected()
        {
            var opts          = new CloudFoundryForwarderOptions();
            var stats         = new OpenCensusStats();
            var tagsComponent = new TagsComponent();
            var tagger        = tagsComponent.Tagger;
            var ep            = new SpringBootMetricWriter(opts, stats);

            IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Seconds);

            SetupTestView(stats, Distribution.Create(BucketBoundaries.Create(new List <double>()
            {
                0.0, 1.0, 5.0, 10.0, 100.0
            })), testMeasure, "test.test1");

            ITagContext context1 = tagger
                                   .EmptyBuilder
                                   .Put(TagKey.Create("a"), TagValue.Create("v1"))
                                   .Put(TagKey.Create("b"), TagValue.Create("v1"))
                                   .Put(TagKey.Create("c"), TagValue.Create("v1"))
                                   .Build();

            long allKeyssum = 0;

            for (int i = 0; i < 10; i++)
            {
                allKeyssum = allKeyssum + i;
                stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1);
            }

            var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1"));

            Assert.NotNull(viewData);
            var aggMap = viewData.AggregationMap;

            Assert.Single(aggMap);

            var tagValues = aggMap.Keys.Single();
            var data      = aggMap.Values.Single();

            Assert.NotNull(tagValues);
            Assert.NotNull(data);

            var result = ep.CreateMetrics(viewData, data, tagValues, 1L);

            Assert.NotNull(result);
            Assert.Equal(4, result.Count);

            var metric = result[0];

            Assert.Equal("test.test1.v1.v1.v1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.Equal((double)allKeyssum / 10.0, metric.Value);
            var tags = metric.Tags;

            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);

            metric = result[1];
            Assert.Equal("test.test1.max.v1.v1.v1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.Equal(9, metric.Value);
            tags = metric.Tags;
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);

            metric = result[2];
            Assert.Equal("test.test1.min.v1.v1.v1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.Equal(0, metric.Value);
            tags = metric.Tags;
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);

            metric = result[3];
            Assert.Equal("test.test1.stddev.v1.v1.v1", metric.Name);
            Assert.Equal(1L, metric.Timestamp);
            Assert.Equal("gauge", metric.Type);
            Assert.Equal("seconds", metric.Unit);
            Assert.InRange(metric.Value, 2.0d, 3.0d);
            tags = metric.Tags;
            Assert.Equal("v1", tags["a"]);
            Assert.Equal("v1", tags["b"]);
            Assert.Equal("v1", tags["c"]);
        }