MetricsConfig extends SubsetConfiguration { static MetricsConfig create(String prefix) { return loadFirst(prefix, "hadoop-metrics2-" + StringUtils.toLowerCase(prefix) + ".properties", DEFAULT_FILE_NAME); } MetricsConfig(Configuration c, String prefix); @Override MetricsConfig subset(String prefix); @Override Object getProperty(String key); @Override void clear(); @Override String toString();  }
@Test public void testCommon() throws Exception { String filename = getTestFilename("test-metrics2"); new ConfigBuilder() .add("*.foo", "default foo") .add("p1.*.bar", "p1 default bar") .add("p1.t1.*.bar", "p1.t1 default bar") .add("p1.t1.i1.name", "p1.t1.i1.name") .add("p1.t1.42.bar", "p1.t1.42.bar") .add("p1.t2.i1.foo", "p1.t2.i1.foo") .add("p2.*.foo", "p2 default foo") .save(filename); MetricsConfig mc = MetricsConfig.create("p1", filename); LOG.debug("mc:"+ mc); Configuration expected = new ConfigBuilder() .add("*.bar", "p1 default bar") .add("t1.*.bar", "p1.t1 default bar") .add("t1.i1.name", "p1.t1.i1.name") .add("t1.42.bar", "p1.t1.42.bar") .add("t2.i1.foo", "p1.t2.i1.foo") .config; assertEq(expected, mc); testInstances(mc); }
@Test public void testMissingFiles() { MetricsConfig config = MetricsConfig.create("JobTracker", "non-existent.properties"); assertTrue(config.isEmpty()); }