Permalink
Browse files

Add hybrid test case

  • Loading branch information...
Norbert Hu
Norbert Hu committed Mar 23, 2012
1 parent c82c161 commit 7a9824506ad70f1f39eddee315abf5bf65eedb3c
Showing with 38 additions and 1 deletion.
  1. +1 −1 pom.xml
  2. +37 −0 src/test/java/com/foursquare/heapaudit/test/TestHybrid.java
View
@@ -147,7 +147,7 @@
<goal>verify</goal>
</goals>
<configuration>
- <argLine>-javaagent:${project.build.directory}/${project.artifactId}-${project.version}.jar="-Xconditional -Aorg/apache/maven/.+ -Ajunit/.+ -Aorg/junit/.+"</argLine>
+ <argLine>-javaagent:${project.build.directory}/${project.artifactId}-${project.version}.jar="-Xconditional -Aorg/apache/maven/.+ -Ajunit/.+ -Aorg/junit/.+" -Djavaagent=${project.build.directory}/${project.artifactId}-${project.version}.jar</argLine>
<workingDirectory>${project.build.directory}</workingDirectory>
<includes>
<include>**/Test*.java</include>
@@ -0,0 +1,37 @@
+package com.foursquare.heapaudit.test;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class TestHybrid {
+
+ // Test hybrid scenario.
+
+ @Test public void Hybrid() throws InterruptedException, IOException {
+
+ Process process = Runtime.getRuntime().exec("java -javaagent:" + System.getProperty("javaagent") + "=-Icom.foursquare.heapaudit.tutorials.Example@allocateBar.+ -classpath test-classes com/foursquare/heapaudit/tutorials/example4/Hybrid");
+
+ process.waitFor();
+
+ BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
+
+ String result = "";
+
+ for (String s = input.readLine(); s != null; s = input.readLine()) {
+
+ result += s + "\n";
+
+ }
+
+ assertTrue(result.matches("(?m)^HEAP: com/foursquare/heapaudit/tutorials/Example@allocateBar\\(\\)V x1$[\\s\\S]*^ - com.foursquare.heapaudit.tutorials.Example[$]Bar \\(\\d+ bytes\\) x1$[\\s\\S]*"));
+
+ assertFalse(result.matches("(?m)[\\s\\S]*^ - com.foursquare.heapaudit.tutorials.Example[$]Foo \\(\\d+ bytes\\) x\\d+$[\\s\\S]*"));
+
+ }
+
+}

0 comments on commit 7a98245

Please sign in to comment.