Exemplo n.º 1
0
        public virtual void TestTagOverflow()
        {
            MetricsTag t0 = Interns.Tag("t0", "t desc", "t value");

            for (int i = 0; i < MaxTagNames + 1; ++i)
            {
                Interns.Tag("t" + i, "t desc", "t value");
                if (i < MaxTagNames)
                {
                    NUnit.Framework.Assert.AreSame("t0 still there", t0, Interns.Tag("t0", "t desc",
                                                                                     "t value"));
                }
            }
            NUnit.Framework.Assert.AreNotSame("t0 is gone", t0, Interns.Tag("t0", "t desc", "t value"
                                                                            ));
            MetricsTag t1 = Interns.Tag("t1", "t desc", "t value");

            for (int i_1 = 0; i_1 < MaxTagValues; ++i_1)
            {
                Interns.Tag("t1", "t desc", "t value" + i_1);
                if (i_1 < MaxTagValues - 1)
                {
                    NUnit.Framework.Assert.AreSame("t1 is still there", t1, Interns.Tag("t1", "t desc"
                                                                                        , "t value"));
                }
            }
            NUnit.Framework.Assert.AreNotSame("t1 is gone", t1, Interns.Tag("t1", "t desc", "t value"
                                                                            ));
        }
Exemplo n.º 2
0
        public static List <MetricsTag> GetTags(List <Detection> list)
        {
            var results = new List <MetricsTag>();

            list
            .Where(x => !string.IsNullOrWhiteSpace(x.Tags))
            .ToList().ForEach(y =>
            {
                var id = y.Id;
                y.Tags.Split(";")
                .ToList().ForEach(z =>
                {
                    var tag = results.Where(t => t.Tag == z.ToUpper()).FirstOrDefault();
                    if (tag != null)
                    {
                        tag.Ids.Add(id);
                    }
                    else
                    {
                        var newTag = new MetricsTag()
                        {
                            Tag = z.ToUpper()
                        };
                        newTag.Ids.Add(id);
                        results.Add(newTag);
                    }
                });
            });

            return(results.OrderBy(x => x.Tag).ToList());
        }
Exemplo n.º 3
0
        public virtual void TestTag()
        {
            MetricsTag tag = Interns.Tag("t", "t desc", "t value");

            NUnit.Framework.Assert.AreSame("same tag", tag, Interns.Tag("t", "t desc", "t value"
                                                                        ));
        }
Exemplo n.º 4
0
        public static List <MetricsTag> GetTags(IQueryable <Metadata> queryable)
        {
            var results = new List <MetricsTag>();

            queryable
            .Where(x => !string.IsNullOrWhiteSpace(x.tags))
            .ToList().ForEach(y =>
            {
                var id = y.id;
                y.tags.Split(";")
                .ToList().ForEach(z =>
                {
                    var tag = results.Where(t => t.Tag == z).FirstOrDefault();
                    if (tag != null)
                    {
                        tag.Ids.Add(id);
                    }
                    else
                    {
                        var newTag = new MetricsTag()
                        {
                            Tag = z
                        };
                        newTag.Ids.Add(id);
                        results.Add(newTag);
                    }
                });
            });

            return(results);
        }
Exemplo n.º 5
0
        public static void AssertTag(MetricsRecord record, string tagName, string expectedValue
                                     )
        {
            MetricsTag processIdTag = GetFirstTagByName(record, tagName);

            NUnit.Framework.Assert.IsNotNull(processIdTag);
            Assert.Equal(expectedValue, processIdTag.Value());
        }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a tag to the record builder. This functions removes duplication in
 /// case tag has already been created by the caller.
 /// </summary>
 /// <param name="tag">Tag to add.</param>
 /// <returns>Self reference.</returns>
 public IMetricsRecordBuilder Add(MetricsTag tag)
 {
     if (_recordBuilderFinalized)
     {
         throw new MetricsException("Record builder is already finalized. No more tags can be added.");
     }
     _tags.Add(tag);
     return(this);
 }
Exemplo n.º 7
0
        private static void ShouldAcceptImpl(bool expectAcceptList, SubsetConfiguration conf
                                             , IList <MetricsTag> tags, bool[] expectedAcceptedSpec)
        {
            MetricsFilter globFilter  = NewGlobFilter(conf);
            MetricsFilter regexFilter = NewRegexFilter(conf);

            // Test acceptance of the tag list:
            Assert.Equal("accepts " + tags, expectAcceptList, globFilter.Accepts
                             (tags));
            Assert.Equal("accepts " + tags, expectAcceptList, regexFilter.
                         Accepts(tags));
            // Test results on each of the individual tags:
            int acceptedCount = 0;

            for (int i = 0; i < tags.Count; i++)
            {
                MetricsTag tag      = tags[i];
                bool       actGlob  = globFilter.Accepts(tag);
                bool       actRegex = regexFilter.Accepts(tag);
                Assert.Equal("accepts " + tag, expectedAcceptedSpec[i], actGlob
                             );
                // Both the filters should give the same result:
                Assert.Equal(actGlob, actRegex);
                if (actGlob)
                {
                    acceptedCount++;
                }
            }
            if (expectAcceptList)
            {
                // At least one individual tag should be accepted:
                Assert.True("No tag of the following accepted: " + tags, acceptedCount
                            > 0);
            }
            else
            {
                // At least one individual tag should be rejected:
                Assert.True("No tag of the following rejected: " + tags, acceptedCount
                            < tags.Count);
            }
        }
Exemplo n.º 8
0
        public override bool Accepts(MetricsTag tag)
        {
            // Accept if whitelisted
            Pattern ipat = includeTagPatterns[tag.Name()];

            if (ipat != null && ipat.Matcher(tag.Value()).Matches())
            {
                return(true);
            }
            // Reject if blacklisted
            Pattern epat = excludeTagPatterns[tag.Name()];

            if (epat != null && epat.Matcher(tag.Value()).Matches())
            {
                return(false);
            }
            // Reject if no match in whitelist only mode
            if (!includeTagPatterns.IsEmpty() && excludeTagPatterns.IsEmpty())
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 9
0
        public void TestMetricsTagClass()
        {
            const string    name          = "tagtest";
            const string    otherName     = "othertagtest";
            const string    desc          = "tagtestdesc";
            const string    otherDesc     = "othertagtestdesc";
            const string    tagValue      = "tagvalue";
            const string    otherTagValue = "othertagvalue";
            IMetricsFactory factory       = TangFactory.GetTang().NewInjector().GetInstance <IMetricsFactory>();

            IMetricsInfo info = new MetricsInfoImpl(name, desc);
            MetricsTag   tag  = factory.CreateTag(info, tagValue);

            Assert.Equal(name, tag.Name);
            Assert.Equal(desc, tag.Description);
            Assert.Equal(tagValue, tag.Value);

            MetricsTag sameTag = factory.CreateTag(info, tagValue);

            Assert.True(tag.Equals(sameTag));

            MetricsTag otherTag = factory.CreateTag(info, otherTagValue);

            Assert.False(tag.Equals(otherTag));

            otherTag = factory.CreateTag(new MetricsInfoImpl(otherName, desc), tagValue);
            Assert.False(tag.Equals(otherTag));

            otherTag = factory.CreateTag(new MetricsInfoImpl(name, otherDesc), otherTagValue);
            Assert.False(tag.Equals(otherTag));

            string expectedToString = "Tag Information: " + "Name: " + info.Name + ", Description: " + info.Description +
                                      ", Tag Value: " + tagValue;

            Assert.Equal(expectedToString, tag.ToString());
        }
Exemplo n.º 10
0
 public IMetricsRecordBuilder Add(MetricsTag tag)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 11
0
 public IMetricsRecordBuilder Add(MetricsTag tag)
 {
     _tagVals[tag.Name] = tag.Value;
     return(this);
 }
Exemplo n.º 12
0
 public override MetricsRecordBuilder Add(MetricsTag tag)
 {
     tags.AddItem(tag);
     return(this);
 }
Exemplo n.º 13
0
        private void SetAttrCacheTag(MetricsTag tag, int recNo)
        {
            string key = TagName(tag.Name(), recNo);

            attrCache[key] = new Attribute(key, tag.Value());
        }
Exemplo n.º 14
0
 /// <summary>Add an immutable metrics tag object</summary>
 /// <param name="tag">a pre-made tag object (potentially save an object construction)
 ///     </param>
 /// <returns>self</returns>
 public abstract MetricsRecordBuilder Add(MetricsTag tag);