Ejemplo n.º 1
0
        public void TestCreateContainer()
        {
            var log      = new CappedLog.CappedLog();
            var builder0 = new CappedLog.CappedLogConfBuilder()
                           .SetDefaultCapacity(10)
                           .SetConstLabel("one", "1");
            var builder1 = builder0.Clone()
                           .AddConstLabels(new[] { "two", "2", "three", "33" })
                           .SetConstLabel("three", "3")
            ;
            var conf0 = builder0
                        .AddConstLabels(new[] { "two", "20", "three", "30" })
                        .Build();
            var conf1 = builder1
                        .Build();
            var conf2 = builder1.Clone()
                        .AddLabelNames(new[] { "four", "five" })
                        .Build();
            var conf3 = builder1.Clone()
                        .AddLabelName("four")
                        .Build();
            var conf11 = builder1.Clone()
                         .AddLabelName("four")
                         .SetDefaultCapacity(20)
                         .Build();

            var container0 = log.Create(conf0);
            var container1 = log.Create(conf1);

            Assert.AreNotEqual(container1, container0);

            var container2 = log.Create(conf2);

            Assert.AreNotEqual(container2, container1);
            Assert.AreNotEqual(container2, container0);

            var container3 = log.GetOrCreate(conf3);

            Assert.AreNotEqual(container3, container0);
            Assert.AreNotEqual(container3, container1);
            Assert.AreNotEqual(container3, container2);

            Assert.ThrowsException <ArgumentException>(() => log.Create(conf2));
            Assert.ThrowsException <ArgumentException>(() => log.Create(conf11));

            var container11 = log.GetOrCreate(conf11);

            Assert.AreEqual(container11, container3);
        }
Ejemplo n.º 2
0
        public void TestCreateMetric()
        {
            var log      = new CappedLog.CappedLog();
            var builder0 = new CappedLog.CappedLogConfBuilder()
                           .SetDefaultCapacity(10)
                           .AddConstLabel("one", "1");
            var builder1 = builder0.Clone()
                           .AddConstLabels(new[] { "two", "2", "three", "3" });
            var conf0 = builder0
                        .AddConstLabels(new[] { "two", "20", "three", "30" })
                        .Build();
            var conf2 = builder1.Clone()
                        .SetDefaultCapacity(20)
                        .AddLabelNames(new[] { "four", "five" })
                        .Build();
            var conf3 = builder1
                        .AddLabelName("four")
                        .Build();
            var conf1 = builder1
                        .AddLabelName("six")
                        .Build();
            var container0 = log.GetOrCreate(conf0);
            var container1 = log.GetOrCreate(conf1);
            var container2 = log.GetOrCreate(conf2);
            var container3 = log.GetOrCreate(conf3);

            Assert.AreNotEqual(container0, container1);
            Assert.AreNotEqual(container0, container2);
            Assert.AreNotEqual(container0, container3);
            Assert.AreNotEqual(container1, container2);
            Assert.AreNotEqual(container1, container3);
            Assert.AreNotEqual(container2, container3);

            var metric0   = container0.GetMetric(new[] { "41", "61" });
            var metric11  = container1.GetMetric(new[] { "41", "61" });
            var metric12  = container1.GetMetric(new[] { "42", "62" });
            var metric111 = container1.GetMetric(new[] { "41", "61" });

            Assert.AreNotEqual(metric0, metric11);
            Assert.AreNotEqual(metric0, metric12);
            Assert.AreNotEqual(metric11, metric12);
            Assert.AreEqual(metric11, metric111);

            var metric2 = container2.GetMetric(new[] { "4", "5" });
            var metric3 = container3.GetMetric(new[] { "4" });

            Assert.AreEqual(metric11.Capacity, 10);
            Assert.AreEqual(metric12.Capacity, 10);
            Assert.AreEqual(metric2.Capacity, 20);
            Assert.AreEqual(metric3.Capacity, 10);

            Assert.IsTrue(metric0.Config.ConstLabels.SequenceEqual(new[] { "one", "1", "two", "20", "three", "30" }.ToKeyValuePairs()));
            Assert.IsTrue(metric11.Config.ConstLabels.SequenceEqual(new[] { "one", "1", "two", "2", "three", "3" }.ToKeyValuePairs()));

            Assert.IsTrue(metric11.Config.LabelNames.SequenceEqual(new[] { "four", "six" }));
            Assert.IsTrue(metric11.Labels.SequenceEqual(new[] { "41", "61" }));
            Assert.IsTrue(metric12.Config.LabelNames.SequenceEqual(new[] { "four", "six" }));
            Assert.IsTrue(metric12.Labels.SequenceEqual(new[] { "42", "62" }));

            Assert.IsTrue(metric2.Config.LabelNames.SequenceEqual(new[] { "four", "five" }));
            Assert.IsTrue(metric2.Labels.SequenceEqual(new[] { "4", "5" }));

            Assert.IsTrue(metric3.Config.LabelNames.SequenceEqual(new[] { "four" }));
            Assert.IsTrue(metric3.Labels.SequenceEqual(new[] { "4" }));
        }