|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertThat;
|
4 | 4 |
|
| 5 | +import java.io.ByteArrayInputStream; |
5 | 6 | import java.io.ByteArrayOutputStream;
|
6 | 7 | import java.io.IOException;
|
7 | 8 | import java.net.MalformedURLException;
|
8 | 9 | import java.net.URL;
|
| 10 | +import java.text.NumberFormat; |
9 | 11 |
|
10 | 12 | import com.tagtraum.perf.gcviewer.exp.impl.SummaryDataWriter;
|
| 13 | +import com.tagtraum.perf.gcviewer.imp.DataReader; |
| 14 | +import com.tagtraum.perf.gcviewer.imp.DataReaderSun1_6_0; |
| 15 | +import com.tagtraum.perf.gcviewer.imp.GcLogType; |
11 | 16 | import com.tagtraum.perf.gcviewer.model.AbstractGCEvent.Type;
|
12 | 17 | import com.tagtraum.perf.gcviewer.model.GCEvent;
|
13 | 18 | import com.tagtraum.perf.gcviewer.model.GCModel;
|
| 19 | +import com.tagtraum.perf.gcviewer.model.GcResourceFile; |
| 20 | +import com.tagtraum.perf.gcviewer.util.MemoryFormat; |
| 21 | + |
14 | 22 | import org.hamcrest.Matchers;
|
| 23 | +import org.junit.BeforeClass; |
15 | 24 | import org.junit.Test;
|
16 | 25 |
|
17 | 26 | /**
|
|
21 | 30 | */
|
22 | 31 | public class SummaryDataWriterTest {
|
23 | 32 |
|
| 33 | + private static NumberFormat percentFormatter; |
| 34 | + private static MemoryFormat memoryFormatter; |
| 35 | + |
| 36 | + @BeforeClass |
| 37 | + public static void setupClass() { |
| 38 | + percentFormatter = NumberFormat.getInstance(); |
| 39 | + percentFormatter.setMaximumFractionDigits(1); |
| 40 | + percentFormatter.setMinimumFractionDigits(1); |
| 41 | + memoryFormatter = new MemoryFormat(); |
| 42 | + } |
| 43 | + |
24 | 44 | private GCModel createGcModel() throws MalformedURLException {
|
25 | 45 | GCModel model = new GCModel();
|
26 | 46 | model.setURL(new URL("file", "localhost", "test-file"));
|
@@ -73,4 +93,27 @@ public void testWriteWithFullGc() throws IOException {
|
73 | 93 |
|
74 | 94 | assertThat("totalHeapAllocMax", csv, Matchers.containsString("avgfootprintAfterFullGC; 724; K"));
|
75 | 95 | }
|
| 96 | + |
| 97 | + @Test |
| 98 | + public void testWriteWithPromotion() throws IOException { |
| 99 | + ByteArrayInputStream in = new ByteArrayInputStream( |
| 100 | + ("2011-01-25T17:10:16.889+0100: 12076.859: [GC 12076.859: [ParNew2011-01-25T17:10:16.896+0100: 12076.866: [CMS-concurrent-abortable-preclean: 0.929/4.899 secs] [Times: user=2.13 sys=0.04, real=4.90 secs]" + |
| 101 | + "\n" + |
| 102 | + "\nDesired survivor size 720896 bytes, new threshold 1 (max 4)" + |
| 103 | + "\n- age 1: 1058016 bytes, 1058016 total" + |
| 104 | + "\n: 13056K->1408K(13056K), 0.0128277 secs] 131480K->122757K(141328K), 0.0131346 secs] [Times: user=0.15 sys=0.00, real=0.01 secs]") |
| 105 | + .getBytes()); |
| 106 | + DataReader reader = new DataReaderSun1_6_0(new GcResourceFile("byteArray"), in, GcLogType.SUN1_6); |
| 107 | + GCModel model = reader.read(); |
| 108 | + model.setURL(new URL("file", "localhost", "test-file")); |
| 109 | + |
| 110 | + ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 111 | + SummaryDataWriter objectUnderTest = new SummaryDataWriter(output); |
| 112 | + |
| 113 | + objectUnderTest.write(model); |
| 114 | + |
| 115 | + String csv = output.toString(); |
| 116 | + |
| 117 | + assertThat("avgPromotion", csv, Matchers.containsString("avgPromotion; " + memoryFormatter.formatToFormatted(2925).getValue() + "; K")); |
| 118 | + } |
76 | 119 | }
|
0 commit comments