### Question:
JmxCollector extends Collector implements Collector.Describable { public List<MetricFamilySamples> collect() { Config config = getLatestConfig(); MatchedRulesCache.StalenessTracker stalenessTracker = new MatchedRulesCache.StalenessTracker(); Receiver receiver = new Receiver(config, stalenessTracker); JmxScraper scraper = new JmxScraper(config.jmxUrl, config.username, config.password, config.ssl, config.whitelistObjectNames, config.blacklistObjectNames, receiver, jmxMBeanPropertyCache); long start = System.nanoTime(); double error = 0; if ((config.startDelaySeconds > 0) && ((start - createTimeNanoSecs) / 1000000000L < config.startDelaySeconds)) { throw new IllegalStateException("JMXCollector waiting for startDelaySeconds"); } try { scraper.doScrape(); } catch (Exception e) { error = 1; StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); LOGGER.severe("JMX scrape failed: " + sw.toString()); } config.rulesCache.evictStaleEntries(stalenessTracker); List<MetricFamilySamples> mfsList = new ArrayList<MetricFamilySamples>(); mfsList.addAll(receiver.metricFamilySamplesMap.values()); List<MetricFamilySamples.Sample> samples = new ArrayList<MetricFamilySamples.Sample>(); samples.add(new MetricFamilySamples.Sample( "jmx_scrape_duration_seconds", new ArrayList<String>(), new ArrayList<String>(), (System.nanoTime() - start) / 1.0E9)); mfsList.add(new MetricFamilySamples("jmx_scrape_duration_seconds", Type.GAUGE, "Time this JMX scrape took, in seconds.", samples)); samples = new ArrayList<MetricFamilySamples.Sample>(); samples.add(new MetricFamilySamples.Sample( "jmx_scrape_error", new ArrayList<String>(), new ArrayList<String>(), error)); mfsList.add(new MetricFamilySamples("jmx_scrape_error", Type.GAUGE, "Non-zero if this scrape failed.", samples)); samples = new ArrayList<MetricFamilySamples.Sample>(); samples.add(new MetricFamilySamples.Sample( "jmx_scrape_cached_beans", new ArrayList<String>(), new ArrayList<String>(), stalenessTracker.cachedCount())); mfsList.add(new MetricFamilySamples("jmx_scrape_cached_beans", Type.GAUGE, "Number of beans with their matching rule cached", samples)); return mfsList; } JmxCollector(File in);  JmxCollector(String yamlConfig);  JmxCollector(InputStream inputStream); List<MetricFamilySamples> collect(); List<MetricFamilySamples> describe(); static void main(String[] args);  }### Answer:
@Test public void testHelpFromPattern() throws Exception { JmxCollector jc = new JmxCollector( "\n---\nrules:\n- pattern: `^(hadoop)<service=DataNode, name=DataNodeActivity-ams-hdd001-50010><>replaceBlockOpMinTime:`\n name: foo\n help: bar $1".replace('`','"')).register(registry); for(Collector.MetricFamilySamples mfs : jc.collect()) { if (mfs.name.equals("foo") && mfs.help.equals("bar hadoop")) { return; } } fail("MetricFamilySamples foo with help 'bar hadoop' not found."); }