Skip to content

Commit

Permalink
[activemq_58] Added unit test to prefix formatter
Browse files Browse the repository at this point in the history
Added a simple unit test to the prefix formatter, when adding versionned
integration like activemq_58, it would be good to check that it's prefix
is correctly formatted here.
  • Loading branch information
Etienne LAFARGE committed Apr 24, 2015
1 parent 7218b33 commit 9dc8500
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static String formatDataName(String name){
String[] chunks = name.split("\\.");

// Escaping the prefix name
chunks[0] = chunks[0].replaceAll("[_A-Z0-9:-]", "");
chunks[0] = chunks[0].replaceAll("[A-Z0-9:_\\-]", "");

// Putting the chunks together (there's nothing in the standard library to do that :o )
String res = "";
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/datadog/jmxfetch/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.apache.log4j.Level;
import org.datadog.jmxfetch.reporter.ConsoleReporter;
import org.datadog.jmxfetch.reporter.StatsdReporter;
import org.datadog.jmxfetch.util.CustomLogger;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -396,6 +397,20 @@ public void testServiceCheckCRITICAL() throws Exception {
mbs.unregisterMBean(objectName);
}

@Test
public void testPrefixFormatter() throws Exception {
// Let's get a list of Strings to test (add real versionned check names
// here when you add new versionned check)
String[][] data = {
{"activemq_58.foo.bar12", "activemq.foo.bar12"},
{"test_package-X86_64-VER1:0.weird.metric_name", "testpackage.weird.metric_name" }
};

// Let's test them all
for(int i=0; i<data.length; ++i)
assertEquals(data[i][1], StatsdReporter.formatDataName(data[i][0]));
}

@Test
public void testApp() throws Exception {
// We expose a few metrics through JMX
Expand Down

0 comments on commit 9dc8500

Please sign in to comment.