Пример #1
0
        public virtual void TestNullTag()
        {
            MetricsCache  cache = new MetricsCache();
            MetricsRecord mr    = MakeRecord("r", Arrays.AsList(MakeTag("t", null)), Arrays.AsList
                                                 (MakeMetric("m", 0), MakeMetric("m1", 1)));

            MetricsCache.Record cr = cache.Update(mr);
            Assert.True("t value should be null", null == cr.GetTag("t"));
        }
Пример #2
0
        public virtual void TestGet()
        {
            MetricsCache cache = new MetricsCache();

            NUnit.Framework.Assert.IsNull("empty", cache.Get("r", Arrays.AsList(MakeTag("t",
                                                                                        "t"))));
            MetricsRecord mr = MakeRecord("r", Arrays.AsList(MakeTag("t", "t")), Arrays.AsList
                                              (MakeMetric("m", 1)));

            cache.Update(mr);
            MetricsCache.Record cr = cache.Get("r", mr.Tags());
            Log.Debug("tags=" + mr.Tags() + " cr=" + cr);
            NUnit.Framework.Assert.IsNotNull("Got record", cr);
            Assert.Equal("contains 1 metric", 1, cr.Metrics().Count);
            CheckMetricValue("new metric value", cr, "m", 1);
        }
Пример #3
0
        public virtual void TestOverflow()
        {
            MetricsCache cache = new MetricsCache();

            MetricsCache.Record      cr;
            ICollection <MetricsTag> t0 = Arrays.AsList(MakeTag("t0", "0"));

            for (int i = 0; i < MetricsCache.MaxRecsPerNameDefault + 1; ++i)
            {
                cr = cache.Update(MakeRecord("r", Arrays.AsList(MakeTag("t" + i, string.Empty + i
                                                                        )), Arrays.AsList(MakeMetric("m", i))));
                CheckMetricValue("new metric value", cr, "m", i);
                if (i < MetricsCache.MaxRecsPerNameDefault)
                {
                    NUnit.Framework.Assert.IsNotNull("t0 is still there", cache.Get("r", t0));
                }
            }
            NUnit.Framework.Assert.IsNull("t0 is gone", cache.Get("r", t0));
        }
Пример #4
0
        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);
        }
Пример #5
0
 internal RecordCache(MetricsCache _enclosing)
 {
     this._enclosing = _enclosing;
 }