static MetricsConfig loadFirst(String prefix, String... fileNames) {
    for (String fname : fileNames) {
      try {
        PropertiesConfiguration pcf = new PropertiesConfiguration();
        pcf.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
        FileHandler fh = new FileHandler(pcf);
        fh.setFileName(fname);
        fh.load();
        Configuration cf = pcf.interpolatedConfiguration();
        LOG.info("Loaded properties from {}", fname);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Properties: {}", toString(cf));
        }
        MetricsConfig mc = new MetricsConfig(cf, prefix);
        LOG.debug("Metrics Config: {}", mc);
        return mc;
      } catch (ConfigurationException e) {
        // Commons Configuration defines the message text when file not found
        if (e.getMessage().startsWith("Could not locate")) {
          LOG.debug("Could not locate file {}", fname, e);
          continue;
        }
        throw new MetricsConfigException(e);
      }
    }
    LOG.warn("Cannot locate configuration: tried " +
             Joiner.on(",").join(fileNames));
    // default to an empty configuration
    return new MetricsConfig(new PropertiesConfiguration(), prefix);
  }
@Test public void testLoadFirst() throws Exception {
    String filename = getTestFilename("hadoop-metrics2-p1");
    new ConfigBuilder().add("p1.foo", "p1foo").save(filename);

    MetricsConfig mc = MetricsConfig.create("p1");
    MetricsConfig mc2 = MetricsConfig.create("p1", "na1", "na2", filename);
    Configuration expected = new ConfigBuilder().add("foo", "p1foo").config;

    assertEq(expected, mc);
    assertEq(expected, mc2);
  }