Skip to content

Commit

Permalink
improve unittests #196
Browse files Browse the repository at this point in the history
  • Loading branch information
chewiebug committed Mar 26, 2018
1 parent 23d0551 commit 34726f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/test/java/com/tagtraum/perf/gcviewer/imp/TestDataReaderGo.java
@@ -1,39 +1,63 @@
package com.tagtraum.perf.gcviewer.imp;

import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.closeTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

import com.tagtraum.perf.gcviewer.UnittestHelper;
import com.tagtraum.perf.gcviewer.model.GCModel;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;

import com.tagtraum.perf.gcviewer.UnittestHelper;
import com.tagtraum.perf.gcviewer.model.AbstractGCEvent;
import com.tagtraum.perf.gcviewer.model.GCModel;
import com.tagtraum.perf.gcviewer.model.GCResource;
import com.tagtraum.perf.gcviewer.model.GcResourceFile;
import org.junit.Test;

public class TestDataReaderGo {

@Test
public void test() throws IOException {
TestLogHandler handler = new TestLogHandler();
handler.setLevel(Level.WARNING);
GCResource gcResource = new GcResourceFile("byteArray");
gcResource.getLogger().addHandler(handler);

String gcLog = ""
+ "gc starting...\n" // Such a line is not produced by the Go GC; it is just for testing
+ "gc 1 @997.597s 3%: 68+0.36+0.51 ms clock, 205+0/16/89+1.5 ms cpu, 84->84->42 MB, 86 MB goal, 3 P\n"
+ "gc 1 @0.058s 0%: 0+1.9+0 ms clock, 0+0.94/1.9/2.9+0 ms cpu, 4->5->1 MB, 5 MB goal, 4 P\n"
+ "a line unrelated to GC logging\n"
+ "gc 2 @997.597s 3%: 68+0.36+0.51 ms clock, 205+0/16/89+1.5 ms cpu, 11111111111111111111111111111111111->84->42 MB, 86 MB goal, 3 P\n"
+ "gc 3 @997.597s 3%: 68+0.36+0.51 ms clock, 205+0/16/89+1.5 ms cpu, 84->84->42 MB, 86 MB goal, 3 P\n";
+ "gc 2 @0.073s 3%: 68+0.36+0.51 ms clock, 205+0/16/89+1.5 ms cpu, 11111111111111111111111111111111111->84->42 MB, 86 MB goal, 3 P\n"
+ "gc 58 @17.837s 0%: 0.48+17+0 ms clock, 1.9+9.3/7.9/15+0 ms cpu, 30->30->15 MB, 31 MB goal, 4 P\n";
ByteArrayInputStream in = new ByteArrayInputStream(gcLog.getBytes("US-ASCII"));
DataReader reader = new DataReaderGo(new GcResourceFile("byteArray"), in);
DataReader reader = new DataReaderGo(gcResource, in);
GCModel model = reader.read();

assertEquals(2, model.size());
assertThat("gc 2 -> warning", handler.getCount(), is(1));
assertThat("size", model.size(), is(2));

AbstractGCEvent<?> event1 = model.get(0);
assertThat("timestamp", event1.getTimestamp(), closeTo(0.058, 0.0001));
assertThat("pause", event1.getPause(), closeTo(0 + 0, 0.1));
assertThat("preused", event1.getPreUsed(), is(4096));
assertThat("postused", event1.getPostUsed(), is(1024));
assertThat("heap", event1.getTotal(), is(5120));
}

@Test
public void exampleLog() throws IOException {
String fileName = "go1.9.txt";
InputStream in = UnittestHelper.getResourceAsStream(UnittestHelper.FOLDER.GO, fileName);
DataReader reader = new DataReaderGo(new GcResourceFile(fileName), in);
TestLogHandler handler = new TestLogHandler();
handler.setLevel(Level.WARNING);
GCResource gcResource = new GcResourceFile("go1.9.txt");
gcResource.getLogger().addHandler(handler);

InputStream in = UnittestHelper.getResourceAsStream(UnittestHelper.FOLDER.GO, gcResource.getResourceName());
DataReader reader = new DataReaderGo(gcResource, in);
GCModel model = reader.read();

assertEquals(635, model.size());
assertThat("warnings", handler.getCount(), is(0));
assertThat("size", model.size(), is(635));
}
}
Expand Up @@ -64,6 +64,7 @@ public void fullGcWithDetailedSizes() throws Exception {
TestLogHandler handler = new TestLogHandler();
handler.setLevel(Level.WARNING);
GCResource gcResource = new GcResourceFile("byteArray");
gcResource.getLogger().addHandler(handler);

ByteArrayInputStream in = new ByteArrayInputStream(
("2014-07-24T13:49:45.090+0400: 92457.841: [Full GC (Allocation Failure) 5811M->3097M(12G), 8.9862292 secs]"
Expand Down

0 comments on commit 34726f6

Please sign in to comment.