|
| 1 | +package com.tagtraum.perf.gcviewer.imp; |
| 2 | + |
| 3 | +import static org.hamcrest.Matchers.closeTo; |
| 4 | +import static org.hamcrest.Matchers.is; |
| 5 | +import static org.junit.Assert.assertThat; |
| 6 | + |
| 7 | +import java.io.ByteArrayInputStream; |
| 8 | +import java.io.InputStream; |
| 9 | +import java.util.logging.Level; |
| 10 | + |
| 11 | +import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type; |
| 12 | +import com.tagtraum.perf.gcviewer.model.GCModel; |
| 13 | +import com.tagtraum.perf.gcviewer.model.GCResource; |
| 14 | +import com.tagtraum.perf.gcviewer.model.GcResourceFile; |
| 15 | +import org.junit.Test; |
| 16 | + |
| 17 | +/** |
| 18 | + * Tests unified jvm logging parser for serial gc events. |
| 19 | + */ |
| 20 | +public class TestDataReaderUJLSerialJdk17 { |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testStandardEvent() throws Exception { |
| 24 | + TestLogHandler handler = new TestLogHandler(); |
| 25 | + handler.setLevel(Level.WARNING); |
| 26 | + GCResource gcResource = new GcResourceFile("byteArray"); |
| 27 | + gcResource.getLogger().addHandler(handler); |
| 28 | + InputStream in = new ByteArrayInputStream( |
| 29 | + ("[2023-03-05T15:03:14.411+0000][0.276s][info][gc,start ] GC(0) Pause Young (Allocation Failure)\n" + |
| 30 | + "[2023-03-05T15:03:14.415+0000][0.280s][info][gc,heap ] GC(0) DefNew: 8703K(9792K)->1088K(9792K) Eden: 8703K(8704K)->0K(8704K) From: 0K(1088K)->1088K(1088K)\n" + |
| 31 | + "[2023-03-05T15:03:14.415+0000][0.281s][info][gc,heap ] GC(0) Tenured: 0K(21888K)->6627K(21888K)\n" + |
| 32 | + "[2023-03-05T15:03:14.416+0000][0.281s][info][gc,metaspace] GC(0) Metaspace: 309K(512K)->309K(512K) NonClass: 293K(384K)->293K(384K) Class: 16K(128K)->16K(128K)\n" + |
| 33 | + "[2023-03-05T15:03:14.416+0000][0.282s][info][gc ] GC(0) Pause Young (Allocation Failure) 8M->7M(30M) 5.480ms\n" + |
| 34 | + "[2023-03-05T15:03:14.416+0000][0.282s][info][gc,cpu ] GC(0) User=0.00s Sys=0.00s Real=0.01s\n" + |
| 35 | + "[2023-03-05T15:03:14.417+0000][0.282s][info][safepoint ] Safepoint \"GenCollectForAllocation\", Time since last: 209726300 ns, Reaching safepoint: 51400 ns, At safepoint: 6279300 ns, Total: 6330700 ns\n" |
| 36 | + ).getBytes()); |
| 37 | + |
| 38 | + DataReader reader = new DataReaderUnifiedJvmLogging(gcResource, in); |
| 39 | + GCModel model = reader.read(); |
| 40 | + |
| 41 | + assertThat("number of warnings", handler.getCount(), is(0)); |
| 42 | + assertThat("number of events", model.size(), is(1)); |
| 43 | + assertThat("event type", model.get(0).getExtendedType().getType(), is(Type.UJL_PAUSE_YOUNG)); |
| 44 | + assertThat("event pause", model.get(0).getPause(), closeTo(0.00548, 0.0000001)); |
| 45 | + |
| 46 | + assertThat("phases", model.getGcEventPhases().size(), is(0)); |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments