1 /* 2 * Copyright (C) 2013 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.caliper.bridge; 18 19 import static com.google.caliper.bridge.GcLogMessage.Type.FULL; 20 import static com.google.caliper.bridge.GcLogMessage.Type.INCREMENTAL; 21 import static com.google.common.base.Charsets.UTF_8; 22 import static java.util.concurrent.TimeUnit.MICROSECONDS; 23 import static org.junit.Assert.assertEquals; 24 import static org.junit.Assert.assertTrue; 25 26 import com.google.caliper.util.ShortDuration; 27 import com.google.common.io.Resources; 28 29 import dagger.Component; 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.junit.runners.JUnit4; 34 35 import java.util.List; 36 37 import javax.inject.Inject; 38 39 /** 40 * Tests {@link LogMessageParser}. 41 */ 42 @RunWith(JUnit4.class) 43 44 public class LogMessageParserTest { 45 @Inject LogMessageParser parser; 46 47 @Component(modules = BridgeModule.class) 48 interface LogMessageParserComponent { 49 void inject(LogMessageParserTest test); 50 } 51 52 @Before public void setUp() { 53 DaggerLogMessageParserTest_LogMessageParserComponent.create().inject(this); 54 } 55 56 @Test public void gcPatten_jdk6() throws Exception { 57 List<String> lines = Resources.readLines( 58 Resources.getResource(LogMessageParserTest.class, "jdk6-gc.txt"), UTF_8); 59 for (String line : lines) { 60 assertTrue(parser.parse(line) instanceof GcLogMessage); 61 } 62 } 63 64 @Test public void gcPatten_jdk7() throws Exception { 65 List<String> lines = Resources.readLines( 66 Resources.getResource(LogMessageParserTest.class, "jdk7-gc.txt"), UTF_8); 67 for (String line : lines) { 68 assertTrue(parser.parse(line) instanceof GcLogMessage); 69 } 70 } 71 72 @Test public void gcMessageData() { 73 assertEquals(new GcLogMessage(INCREMENTAL, ShortDuration.of(1232, MICROSECONDS)), 74 parser.parse("[GC 987K->384K(62848K), 0.0012320 secs]")); 75 assertEquals(new GcLogMessage(FULL, ShortDuration.of(5455, MICROSECONDS)), 76 parser.parse("[Full GC 384K->288K(62848K), 0.0054550 secs]")); 77 assertEquals(new GcLogMessage(INCREMENTAL, ShortDuration.of(1424, MICROSECONDS)), 78 parser.parse( 79 "2013-02-11T20:15:26.706-0600: 0.098: [GC 1316K->576K(62848K), 0.0014240 secs]")); 80 assertEquals(new GcLogMessage(FULL, ShortDuration.of(4486, MICROSECONDS)), 81 parser.parse( 82 "2013-02-11T20:15:26.708-0600: 0.099: [Full GC 576K->486K(62848K), 0.0044860 secs]")); 83 } 84 85 @Test public void jitPattern_jdk6() throws Exception { 86 List<String> lines = Resources.readLines( 87 Resources.getResource(LogMessageParserTest.class, "jdk6-compilation.txt"), UTF_8); 88 for (String line : lines) { 89 assertTrue(parser.parse(line) instanceof HotspotLogMessage); 90 } 91 } 92 93 @Test public void jitPattern_jdk7() throws Exception { 94 List<String> lines = Resources.readLines( 95 Resources.getResource(LogMessageParserTest.class, "jdk7-compilation.txt"), UTF_8); 96 for (String line : lines) { 97 assertTrue(parser.parse(line) instanceof HotspotLogMessage); 98 } 99 } 100 101 @Test public void vmOptionPattern_jdk6() throws Exception { 102 List<String> lines = Resources.readLines( 103 Resources.getResource(LogMessageParserTest.class, "jdk6-flags.txt"), UTF_8); 104 for (String line : lines) { 105 assertTrue(parser.parse(line) instanceof VmOptionLogMessage); 106 } 107 } 108 109 @Test public void vmOptionPattern_jdk7() throws Exception { 110 List<String> lines = Resources.readLines( 111 Resources.getResource(LogMessageParserTest.class, "jdk7-flags.txt"), UTF_8); 112 for (String line : lines) { 113 assertTrue(parser.parse(line) instanceof VmOptionLogMessage); 114 } 115 } 116 } 117