forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#9573] Apply Regex precompile to TagParser
- Loading branch information
1 parent
0f27aa2
commit aef0eb7
Showing
5 changed files
with
108 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...le/metric/src/test/java/com/navercorp/pinpoint/metric/web/utill/metric/TagParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.navercorp.pinpoint.metric.web.utill.metric; | ||
|
||
import com.navercorp.pinpoint.metric.common.model.Tag; | ||
import com.navercorp.pinpoint.metric.web.util.TagParser; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TagParserTest { | ||
|
||
@Test | ||
public void parseTagTest() { | ||
List<Tag> tagList = new ArrayList<>(); | ||
tagList.add(new Tag("A", "1")); | ||
tagList.add(new Tag("B", "2")); | ||
tagList.add(new Tag("C", "3")); | ||
|
||
List<Tag> result = new ArrayList<>(); | ||
result.add(TagParser.parseTag("A:1")); | ||
result.add(TagParser.parseTag("B:2")); | ||
result.add(TagParser.parseTag("C:3")); | ||
|
||
Assertions.assertEquals(tagList, result); | ||
} | ||
|
||
@Test | ||
public void parseTagsListTest() { | ||
List<Tag> tagList = new ArrayList<>(); | ||
tagList.add(new Tag("A", "1")); | ||
tagList.add(new Tag("B", "2")); | ||
tagList.add(new Tag("C", "3")); | ||
|
||
List<String> tags = new ArrayList<>(); | ||
tags.add("A:1"); | ||
tags.add("B:2"); | ||
tags.add("C:3"); | ||
|
||
List<Tag> result = TagParser.parseTags(tags); | ||
|
||
Assertions.assertEquals(tagList, result); | ||
} | ||
|
||
|
||
@Test | ||
public void parseTagsStringTest() { | ||
List<Tag> tagList = new ArrayList<>(); | ||
tagList.add(new Tag("device", "1")); | ||
tagList.add(new Tag("fstype", "2")); | ||
tagList.add(new Tag("mode", "3")); | ||
tagList.add(new Tag("path", "4")); | ||
|
||
String multiValueFieldTagString = "[\"device:1\",\"fstype:2\",\"mode:3\",\"path:4\"]"; | ||
List<Tag> result = TagParser.parseTags(multiValueFieldTagString); | ||
|
||
Assertions.assertEquals(tagList, result); | ||
} | ||
|
||
@Test | ||
public void parseTagsStringEmptyTest() { | ||
String multiValueFieldTagString = "[\"null\"]"; | ||
List<Tag> result = TagParser.parseTags(multiValueFieldTagString); | ||
|
||
Assertions.assertEquals(0, result.size()); | ||
} | ||
|
||
|
||
@Test | ||
public void toTagsStringTest() { | ||
String expect = "device:1,fstype:2,mode:3,path:4"; | ||
|
||
String jsonTagString = "{\"device\":\"1\",\"fstype\":\"2\",\"mode\":\"3\",\"path\":\"4\"}"; | ||
String result = TagParser.toTagStrings(jsonTagString); | ||
|
||
Assertions.assertEquals(expect, result); | ||
} | ||
|
||
@Test | ||
public void toTagsStringEmptyTest() { | ||
String jsonTagStrings = "{}"; | ||
String result = TagParser.toTagStrings(jsonTagStrings); | ||
|
||
Assertions.assertEquals("", result); | ||
} | ||
} |