@Test
public void testPopulateResourcesForRegexpMetrics() throws Exception {

  setUpCommonMocks();
  TestStreamProvider streamProvider = new TestStreamProvider(MULTIPLE_COMPONENT_REGEXP_METRICS_FILE_PATH);
  injectCacheEntryFactoryWithStreamProvider(streamProvider);
  TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
  ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
  TimelineMetricCacheProvider cacheProviderMock = EasyMock.createMock(TimelineMetricCacheProvider.class);
  TimelineMetricCache cacheMock = EasyMock.createMock(TimelineMetricCache.class);
  expect(cacheProviderMock.getTimelineMetricsCache()).andReturn(cacheMock).anyTimes();
  Map<String, Map<String, PropertyInfo>> propertyIds =
    new HashMap<String, Map<String, PropertyInfo>>() {{
      put("RESOURCEMANAGER", new HashMap<String, PropertyInfo>() {{
        put("metrics/yarn/Queue/$1.replaceAll(\"([.])\",\"/\")/AvailableMB",
          new PropertyInfo("yarn.QueueMetrics.Queue=(.+).AvailableMB", true, false));
      }});
    }};
  AMSPropertyProvider propertyProvider = new AMSComponentPropertyProvider(
    propertyIds,
    streamProvider,
    sslConfiguration,
    cacheProviderMock,
    metricHostProvider,
    CLUSTER_NAME_PROPERTY_ID,
    COMPONENT_NAME_PROPERTY_ID
  );
  String propertyId1 = "metrics/yarn/Queue/root/AvailableMB";
  Resource resource = new ResourceImpl(Resource.Type.Component);
  resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
  resource.setProperty(HOST_NAME_PROPERTY_ID, "h1");// should be set?
  resource.setProperty(COMPONENT_NAME_PROPERTY_ID, "RESOURCEMANAGER");
  Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
  temporalInfoMap.put(propertyId1, new TemporalInfoImpl(1416528759233L, 1416531129231L, 1L));
  Request request = PropertyHelper.getReadRequest(
    Collections.singleton(propertyId1), temporalInfoMap);
  Set<Resource> resources =
    propertyProvider.populateResources(Collections.singleton(resource), request, null);
  Assert.assertEquals(1, resources.size());
  Resource res = resources.iterator().next();
  Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next());
  Assert.assertNotNull(properties);
  URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false);
  uriBuilder.addParameter("metricNames", "yarn.QueueMetrics.Queue=root.AvailableMB");
  uriBuilder.addParameter("appId", "RESOURCEMANAGER");
  uriBuilder.addParameter("startTime", "1416528759233");
  uriBuilder.addParameter("endTime", "1416531129231");
  Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec());
  Number[][] val = (Number[][]) res.getPropertyValue("metrics/yarn/Queue/root/AvailableMB");
  Assert.assertNotNull("No value for property metrics/yarn/Queue/root/AvailableMB", val);
  Assert.assertEquals(238, val.length);
}