TextParser implements Parser { @Override public MetricFamily parse(long now) throws IOException { String line; if (lastLineReadFromStream != null) { line = lastLineReadFromStream; lastLineReadFromStream = null; } else { line = reader.readLine(); } if (line == null) { return null; } Context ctx = new Context(now); while (line != null) { line = line.trim(); try { if (parseLine(line, ctx)) { break; } } catch (Exception e) { LOG.debug("Failed to process line - it will be ignored: {}", line, e); } line = reader.readLine(); } if (!ctx.name.isEmpty()) { ctx.end(); } return ctx.metricFamily; } TextParser(final InputStream inputStream); @Override MetricFamily parse(long now);  }
@Test public void parseTextSuccessfully() throws IOException { try (InputStream is = ResourceUtils.readToStream("testdata/prometheus.txt")) { TextParser parser = new TextParser(is); MetricFamily mf; int mfNum = 0; while ((mf = parser.parse(now)) != null) { mfNum++; MetricFamily expected = expectedMfs.poll(); assertNotNull(expected); assertThat(mf, is(expected)); } assertThat(mfNum , is(3)); } }