|
@@ -18,6 +18,7 @@
|
|
|
|
|
|
package org.apache.hadoop.metrics2.lib;
|
|
|
|
|
|
+import org.junit.Ignore;
|
|
|
import org.junit.Test;
|
|
|
import static org.junit.Assert.*;
|
|
|
import static org.mockito.Mockito.*;
|
|
@@ -56,6 +57,46 @@ public class TestMetricsRegistry {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test adding metrics with whitespace in the name
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ public void testMetricsRegistryIllegalMetricNames() {
|
|
|
+ final MetricsRegistry r = new MetricsRegistry("test");
|
|
|
+ // Fill up with some basics
|
|
|
+ r.newCounter("c1", "c1 desc", 1);
|
|
|
+ r.newGauge("g1", "g1 desc", 1);
|
|
|
+ r.newQuantiles("q1", "q1 desc", "q1 name", "q1 val type", 1);
|
|
|
+ // Add some illegal names
|
|
|
+ expectMetricsException("Metric name 'badcount 2' contains "+
|
|
|
+ "illegal whitespace character", new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() { r.newCounter("badcount 2", "c2 desc", 2); }
|
|
|
+ });
|
|
|
+ expectMetricsException("Metric name 'badcount3 ' contains "+
|
|
|
+ "illegal whitespace character", new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() { r.newCounter("badcount3 ", "c3 desc", 3); }
|
|
|
+ });
|
|
|
+ expectMetricsException("Metric name ' badcount4' contains "+
|
|
|
+ "illegal whitespace character", new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() { r.newCounter(" badcount4", "c4 desc", 4); }
|
|
|
+ });
|
|
|
+ expectMetricsException("Metric name 'withtab5 ' contains "+
|
|
|
+ "illegal whitespace character", new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() { r.newCounter("withtab5 ", "c5 desc", 5); }
|
|
|
+ });
|
|
|
+ expectMetricsException("Metric name 'withnewline6\n' contains "+
|
|
|
+ "illegal whitespace character", new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() { r.newCounter("withnewline6\n", "c6 desc", 6); }
|
|
|
+ });
|
|
|
+ // Final validation
|
|
|
+ assertEquals("num metrics in registry", 3, r.metrics().size());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test the add by name method
|
|
|
*/
|
|
@@ -81,6 +122,7 @@ public class TestMetricsRegistry {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ @Ignore
|
|
|
private void expectMetricsException(String prefix, Runnable fun) {
|
|
|
try {
|
|
|
fun.run();
|