|
@@ -22,7 +22,10 @@ import org.apache.ambari.server.controller.spi.Resource;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -68,5 +71,72 @@ public class PropertyHelperTest {
|
|
Assert.assertNotNull(info);
|
|
Assert.assertNotNull(info);
|
|
Assert.assertEquals("Hadoop:service=NameNode,name=JvmMetrics.MemHeapUsedM", info.getPropertyId());
|
|
Assert.assertEquals("Hadoop:service=NameNode,name=JvmMetrics.MemHeapUsedM", info.getPropertyId());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGetPropertyCategory() {
|
|
|
|
+ String propertyId = "metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)/AppsRunning";
|
|
|
|
+
|
|
|
|
+ String category = PropertyHelper.getPropertyCategory(propertyId);
|
|
|
|
+
|
|
|
|
+ Assert.assertEquals("metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)", category);
|
|
|
|
+
|
|
|
|
+ category = PropertyHelper.getPropertyCategory(category);
|
|
|
|
+
|
|
|
|
+ Assert.assertEquals("metrics/yarn/Queue", category);
|
|
|
|
+
|
|
|
|
+ category = PropertyHelper.getPropertyCategory(category);
|
|
|
|
+
|
|
|
|
+ Assert.assertEquals("metrics/yarn", category);
|
|
|
|
+
|
|
|
|
+ category = PropertyHelper.getPropertyCategory(category);
|
|
|
|
+
|
|
|
|
+ Assert.assertEquals("metrics", category);
|
|
|
|
+
|
|
|
|
+ category = PropertyHelper.getPropertyCategory(category);
|
|
|
|
+
|
|
|
|
+ Assert.assertNull(category);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGetCategories() {
|
|
|
|
+ String propertyId = "metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)/AppsRunning";
|
|
|
|
+
|
|
|
|
+ Set<String> categories = PropertyHelper.getCategories(Collections.singleton(propertyId));
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)"));
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics/yarn/Queue"));
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics/yarn"));
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics"));
|
|
|
|
+
|
|
|
|
+ String propertyId2 = "foo/bar/baz";
|
|
|
|
+ Set<String> propertyIds = new HashSet<String>();
|
|
|
|
+ propertyIds.add(propertyId);
|
|
|
|
+ propertyIds.add(propertyId2);
|
|
|
|
+
|
|
|
|
+ categories = PropertyHelper.getCategories(propertyIds);
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)"));
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics/yarn/Queue"));
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics/yarn"));
|
|
|
|
+ Assert.assertTrue(categories.contains("metrics"));
|
|
|
|
+ Assert.assertTrue(categories.contains("foo/bar"));
|
|
|
|
+ Assert.assertTrue(categories.contains("foo"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testContainsArguments() {
|
|
|
|
+ Assert.assertFalse(PropertyHelper.containsArguments("foo"));
|
|
|
|
+ Assert.assertFalse(PropertyHelper.containsArguments("foo/bar"));
|
|
|
|
+ Assert.assertFalse(PropertyHelper.containsArguments("foo/bar/baz"));
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue(PropertyHelper.containsArguments("foo/bar/$1/baz"));
|
|
|
|
+ Assert.assertTrue(PropertyHelper.containsArguments("foo/bar/$1/baz/$2"));
|
|
|
|
+ Assert.assertTrue(PropertyHelper.containsArguments("$1/foo/bar/$2/baz"));
|
|
|
|
+ Assert.assertTrue(PropertyHelper.containsArguments("$1/foo/bar/$2/baz/$3"));
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue(PropertyHelper.containsArguments("metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)"));
|
|
|
|
+
|
|
|
|
+ Assert.assertFalse(PropertyHelper.containsArguments("$X/foo/bar/$Y/baz/$Z"));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|