private void CheckMetricValue(string description, MetricsCache.Record cr, string key, Number val) { Assert.Equal(description, val, cr.GetMetric(key)); NUnit.Framework.Assert.IsNotNull("metric not null", cr.GetMetricInstance(key)); Assert.Equal(description, val, cr.GetMetricInstance(key).Value ()); }
public virtual void TestUpdate() { MetricsCache cache = new MetricsCache(); MetricsRecord mr = MakeRecord("r", Arrays.AsList(MakeTag("t", "tv")), Arrays.AsList (MakeMetric("m", 0), MakeMetric("m1", 1))); MetricsCache.Record cr = cache.Update(mr); Org.Mockito.Mockito.Verify(mr).Name(); Org.Mockito.Mockito.Verify(mr).Tags(); Org.Mockito.Mockito.Verify(mr).Metrics(); Assert.Equal("same record size", cr.Metrics().Count, ((ICollection <AbstractMetric>)mr.Metrics()).Count); Assert.Equal("same metric value", 0, cr.GetMetric("m")); MetricsRecord mr2 = MakeRecord("r", Arrays.AsList(MakeTag("t", "tv")), Arrays.AsList (MakeMetric("m", 2), MakeMetric("m2", 42))); cr = cache.Update(mr2); Assert.Equal("contains 3 metric", 3, cr.Metrics().Count); CheckMetricValue("updated metric value", cr, "m", 2); CheckMetricValue("old metric value", cr, "m1", 1); CheckMetricValue("new metric value", cr, "m2", 42); MetricsRecord mr3 = MakeRecord("r", Arrays.AsList(MakeTag("t", "tv3")), Arrays.AsList (MakeMetric("m3", 3))); // different tag value cr = cache.Update(mr3); // should get a new record Assert.Equal("contains 1 metric", 1, cr.Metrics().Count); CheckMetricValue("updated metric value", cr, "m3", 3); // tags cache should be empty so far Assert.Equal("no tags", 0, cr.Tags().Count); // until now cr = cache.Update(mr3, true); Assert.Equal("Got 1 tag", 1, cr.Tags().Count); Assert.Equal("Tag value", "tv3", cr.GetTag("t")); CheckMetricValue("Metric value", cr, "m3", 3); }