Ejemplo n.º 1
0
        public void TestCreateLogMetricConf()
        {
            {
                var log = new CappedLog.CappedLog();
                var constLabels1 = new[] { "one", "1" }.ToKeyValuePairs();
                var constLabels2 = new[] { "one", "2" }.ToKeyValuePairs();
                var constLabels3 = new[] { "one", "1", "two", "2" }.ToKeyValuePairs();
                var constLabels4 = new[] { "on1", "1" }.ToKeyValuePairs();
                var labelNames1      = new[] { "three" };
                var labelNames2      = new[] { "three", "four" };
                var defaultCapacity1 = 10;
                var defaultCapacity2 = 20;
                var conf1            = new CappedLog.CappedLogConf(constLabels1, labelNames1, defaultCapacity1);
                var conf2            = new CappedLog.CappedLogConf(constLabels2, labelNames1, defaultCapacity2);
                var conf3            = new CappedLog.CappedLogConf(constLabels3, labelNames1, defaultCapacity1);
                var conf4            = new CappedLog.CappedLogConf(constLabels4, labelNames1, defaultCapacity1);
                var conf5            = new CappedLog.CappedLogConf(constLabels1, labelNames2, defaultCapacity1);

                Assert.IsTrue(conf1.ConstLabels.SequenceEqual(constLabels1));
                Assert.IsTrue(conf2.ConstLabels.SequenceEqual(constLabels2));
                Assert.IsTrue(conf1.LabelNames.SequenceEqual(labelNames1));
                Assert.IsTrue(conf2.LabelNames.SequenceEqual(labelNames1));
                Assert.AreEqual(conf1.DefaultCapacity, defaultCapacity1);
                Assert.AreEqual(conf2.DefaultCapacity, defaultCapacity2);

                Assert.AreNotEqual(conf1.Key, conf2.Key);
                Assert.AreNotEqual(conf1.Key, conf3.Key);
                Assert.AreNotEqual(conf1.Key, conf4.Key);
                Assert.AreNotEqual(conf1.Key, conf5.Key);
            }
        }
Ejemplo n.º 2
0
        private static void Init(out CappedLog.CappedLogScope scrape, out CappedLog.CappedLogConf conf2, out CappedLog.CappedLogConf conf3, out CappedLog.CappedLogConf conf1, out CappedLog.CappedLogMetric metric11, out CappedLog.CappedLogMetric metric12, out CappedLog.CappedLogMetric metric2, out CappedLog.CappedLogMetric metric3)
        {
            var log = new CappedLog.CappedLog();

            scrape = new CappedLog.CappedLogScope(log);
            var builder1 = new CappedLog.CappedLogConfBuilder()
                           .AddConstLabel("one", "1")
                           .AddConstLabels(new[] { "two", "2", "three", "3" })
                           .SetDefaultCapacity(10);

            conf2 = builder1.Clone()
                    .SetDefaultCapacity(20)
                    .AddLabelNames(new[] { "four", "five" })
                    .Build();
            conf3 = builder1
                    .AddLabelName("four")
                    .Build();
            conf1 = builder1
                    .AddLabelName("six")
                    .AddConstLabel("seven", "7")
                    .Build();
            var conf0 = builder1
                        .AddLabelName("nine")
                        .Build();
            var container0 = log.GetOrCreate(conf0);
            var container1 = scrape.GetOrCreate(conf1);
            var container2 = scrape.GetOrCreate(conf2);
            var container3 = scrape.GetOrCreate(conf3);

            try { scrape.GetOrCreate(conf0); Assert.Fail(); }
            catch { }
            Assert.AreNotEqual(container1, container2);
            Assert.AreNotEqual(container1, container3);
            Assert.AreNotEqual(container2, container3);
            Assert.AreNotEqual(container1, container0);
            Assert.AreNotEqual(container2, container0);
            Assert.AreNotEqual(container3, container0);

            metric11 = container1.GetMetric(new[] { "41", "61" });
            metric12 = container1.GetMetric(new[] { "42", "62" });
            metric2  = container2.GetMetric(new[] { "4", "5" });
            metric3  = container3.GetMetric(new[] { "4" });
        }