LogMessageParser implements Parser<LogMessage> { @Override public LogMessage parse(CharSequence text) { String string = text.toString(); Matcher gcMatcher = GC_PATTERN.matcher(string); if (gcMatcher.matches()) { return new GcLogMessage( "Full".equals(gcMatcher.group(1)) ? GcLogMessage.Type.FULL : GcLogMessage.Type.INCREMENTAL, ShortDuration.of(BigDecimal.valueOf(Double.parseDouble(gcMatcher.group(2))), SECONDS)); } Matcher jitMatcher = JIT_PATTERN.matcher(string); if (jitMatcher.matches()) { return new HotspotLogMessage(); } Matcher vmOptionMatcher = VM_OPTION_PATTERN.matcher(string); if (vmOptionMatcher.matches()) { return new VmOptionLogMessage(vmOptionMatcher.group(2), vmOptionMatcher.group(3)); } return null; } @Inject  LogMessageParser(); @Override LogMessage parse(CharSequence text);  }
@Test public void gcPatten_jdk7() throws Exception { List<String> lines = Resources.readLines( Resources.getResource(LogMessageParserTest.class, "jdk7-gc.txt"), UTF_8); for (String line : lines) { assertTrue(parser.parse(line) instanceof GcLogMessage); } }
@Test public void gcMessageData() { assertEquals( new GcLogMessage(INCREMENTAL, ShortDuration.of(1232, MICROSECONDS)), parser.parse("[GC 987K->384K(62848K), 0.0012320 secs]")); assertEquals( new GcLogMessage(FULL, ShortDuration.of(5455, MICROSECONDS)), parser.parse("[Full GC 384K->288K(62848K), 0.0054550 secs]")); assertEquals( new GcLogMessage(INCREMENTAL, ShortDuration.of(1424, MICROSECONDS)), parser.parse( "2013-02-11T20:15:26.706-0600: 0.098: [GC 1316K->576K(62848K), 0.0014240 secs]")); assertEquals( new GcLogMessage(FULL, ShortDuration.of(4486, MICROSECONDS)), parser.parse( "2013-02-11T20:15:26.708-0600: 0.099: [Full GC 576K->486K(62848K), 0.0044860 secs]")); }
@Test public void jitPattern_jdk6() throws Exception { List<String> lines = Resources.readLines( Resources.getResource(LogMessageParserTest.class, "jdk6-compilation.txt"), UTF_8); for (String line : lines) { assertTrue(parser.parse(line) instanceof HotspotLogMessage); } }
@Test public void jitPattern_jdk7() throws Exception { List<String> lines = Resources.readLines( Resources.getResource(LogMessageParserTest.class, "jdk7-compilation.txt"), UTF_8); for (String line : lines) { assertTrue(parser.parse(line) instanceof HotspotLogMessage); } }
@Test public void vmOptionPattern_jdk6() throws Exception { List<String> lines = Resources.readLines( Resources.getResource(LogMessageParserTest.class, "jdk6-flags.txt"), UTF_8); for (String line : lines) { assertTrue(parser.parse(line) instanceof VmOptionLogMessage); } }
@Test public void vmOptionPattern_jdk7() throws Exception { List<String> lines = Resources.readLines( Resources.getResource(LogMessageParserTest.class, "jdk7-flags.txt"), UTF_8); for (String line : lines) { assertTrue(parser.parse(line) instanceof VmOptionLogMessage); } }
@Test public void gcPatten_jdk6() throws Exception { List<String> lines = Resources.readLines( Resources.getResource(LogMessageParserTest.class, "jdk6-gc.txt"), UTF_8); for (String line : lines) { assertTrue(parser.parse(line) instanceof GcLogMessage); } }