|
6 | 6 | import java.io.IOException; |
7 | 7 | import java.net.MalformedURLException; |
8 | 8 | import java.net.URL; |
| 9 | +import java.text.NumberFormat; |
9 | 10 |
|
10 | 11 | import com.tagtraum.perf.gcviewer.exp.impl.SummaryDataWriter; |
11 | 12 | import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type; |
12 | 13 | import com.tagtraum.perf.gcviewer.model.GCEvent; |
13 | 14 | import com.tagtraum.perf.gcviewer.model.GCModel; |
| 15 | +import com.tagtraum.perf.gcviewer.util.MemoryFormat; |
| 16 | + |
14 | 17 | import org.hamcrest.Matchers; |
| 18 | +import org.junit.BeforeClass; |
15 | 19 | import org.junit.Test; |
16 | 20 |
|
17 | 21 | /** |
|
21 | 25 | */ |
22 | 26 | public class SummaryDataWriterTest { |
23 | 27 |
|
| 28 | + private static NumberFormat percentFormatter; |
| 29 | + private static MemoryFormat memoryFormatter; |
| 30 | + |
| 31 | + @BeforeClass |
| 32 | + public static void setupClass() { |
| 33 | + percentFormatter = NumberFormat.getInstance(); |
| 34 | + percentFormatter.setMaximumFractionDigits(1); |
| 35 | + percentFormatter.setMinimumFractionDigits(1); |
| 36 | + memoryFormatter = new MemoryFormat(); |
| 37 | + } |
| 38 | + |
24 | 39 | private GCModel createGcModel() throws MalformedURLException { |
25 | 40 | GCModel model = new GCModel(); |
26 | 41 | model.setURL(new URL("file", "localhost", "test-file")); |
@@ -73,4 +88,28 @@ public void testWriteWithFullGc() throws IOException { |
73 | 88 |
|
74 | 89 | assertThat("totalHeapAllocMax", csv, Matchers.containsString("avgfootprintAfterFullGC; 724; K")); |
75 | 90 | } |
| 91 | + |
| 92 | + @Test |
| 93 | + public void testWriteWithPerm() throws IOException { |
| 94 | + ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 95 | + SummaryDataWriter objectUnderTest = new SummaryDataWriter(output); |
| 96 | + |
| 97 | + // 83.403: [Full GC 83.403: [Tenured: 38156K->54636K(349568K), 0.6013150 secs] 141564K->54636K(506944K), [Perm : 73727K->73727K(73728K)], 0.6014256 secs] [Times: user=0.58 sys=0.00, real=0.59 secs] |
| 98 | + GCEvent fullGcEvent = new GCEvent(83.403, 141564, 54636, 506944, 0.6014256, Type.FULL_GC); |
| 99 | + GCEvent tenured = new GCEvent(83.403, 38156, 54636, 349568, 0.6013150, Type.TENURED); |
| 100 | + GCEvent perm = new GCEvent(83.403, 73727, 73727, 73728, 0.6014256, Type.PERM); |
| 101 | + fullGcEvent.add(tenured); |
| 102 | + fullGcEvent.add(perm); |
| 103 | + |
| 104 | + GCModel model = createGcModel(); |
| 105 | + model.add(fullGcEvent); |
| 106 | + |
| 107 | + objectUnderTest.write(model); |
| 108 | + |
| 109 | + String csv = output.toString(); |
| 110 | + |
| 111 | + assertThat("totalPermAllocMax", csv, Matchers.containsString("totalPermAllocMax; 72; M")); |
| 112 | + assertThat("totalPermUsedMax", csv, Matchers.containsString("totalPermUsedMax; " + memoryFormatter.formatToFormatted(73727).getValue() + "; M")); |
| 113 | + assertThat("totalPermUsedMaxpc", csv, Matchers.containsString("totalPermUsedMaxpc; " + percentFormatter.format(100.0) + "; %")); |
| 114 | + } |
76 | 115 | } |
0 commit comments