changeset 1344:c46c864dfc7c

7901784: org.openjdk.jmh.it.annsteal.CustomTest fails with -P asm,reflection
author shade
date Wed, 07 Sep 2016 18:54:20 +0300
parents 183e50c96c54
children b9ea316668ae
files jmh-core-it/pom.xml jmh-core-it/src/test/java/org/openjdk/jmh/it/annsteal/CustomTest.java jmh-core/src/main/java/org/openjdk/jmh/util/FileUtils.java
diffstat 3 files changed, 37 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core-it/pom.xml	Wed Sep 07 11:22:31 2016 +0300
+++ b/jmh-core-it/pom.xml	Wed Sep 07 18:54:20 2016 +0300
@@ -73,7 +73,7 @@
                 <version>2.14.1</version>
                 <configuration>
                     <!-- Integration tests are not measuring performance, OK to run them concurrently -->
-                    <argLine>-Djmh.ignoreLock=true -Xms256m -Xmx256m</argLine>
+                    <argLine>-Djmh.ignoreLock=true -Xms256m -Xmx256m -Djmh.core.it.profile=${jmh.core.it.profile}</argLine>
                     <forkCount>1C</forkCount>
                     <reuseForks>true</reuseForks>
                     <redirectTestOutputToFile>true</redirectTestOutputToFile>
@@ -107,6 +107,9 @@
     <profiles>
         <profile>
             <id>default</id>
+            <properties>
+                <jmh.core.it.profile>default</jmh.core.it.profile>
+            </properties>
             <dependencies>
                 <dependency>
                     <groupId>org.openjdk.jmh</groupId>
@@ -136,6 +139,9 @@
 
         <profile>
             <id>asm</id>
+            <properties>
+                <jmh.core.it.profile>asm</jmh.core.it.profile>
+            </properties>
             <dependencies>
                 <dependency>
                     <groupId>org.openjdk.jmh</groupId>
@@ -223,6 +229,9 @@
 
         <profile>
             <id>reflection</id>
+            <properties>
+                <jmh.core.it.profile>reflection</jmh.core.it.profile>
+            </properties>
             <dependencies>
                 <dependency>
                     <groupId>org.openjdk.jmh</groupId>
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/annsteal/CustomTest.java	Wed Sep 07 11:22:31 2016 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/annsteal/CustomTest.java	Wed Sep 07 18:54:20 2016 +0300
@@ -45,8 +45,16 @@
 
     @Test
     public void test() throws IOException {
-        File file = FileUtils.extractFromResource('/' + CustomBenchmarkProcessor.CBP_LIST);
-        Collection<String> strings = FileUtils.readAllLines(file);
+        if (!"default".equals(System.getProperty("jmh.core.it.profile"))) {
+            return;
+        }
+
+        InputStream list = CustomTest.class.getResourceAsStream('/' + CustomBenchmarkProcessor.CBP_LIST);
+        if (list == null) {
+            throw new IllegalStateException(CustomBenchmarkProcessor.class.getSimpleName() + " list is not found");
+        }
+
+        Collection<String> strings = FileUtils.readAllLines(list);
         Assert.assertTrue(strings.contains(CustomTest.class.getSimpleName()));
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/FileUtils.java	Wed Sep 07 11:22:31 2016 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/FileUtils.java	Wed Sep 07 18:54:20 2016 +0300
@@ -115,13 +115,13 @@
     }
 
     public static Collection<String> readAllLines(Reader src) throws IOException {
-            BufferedReader reader = new BufferedReader(src);
-            List<String> lines = new ArrayList<String>();
-            String line;
-            while ((line = reader.readLine()) != null) {
-                lines.add(line);
-            }
-            return lines;
+        BufferedReader reader = new BufferedReader(src);
+        List<String> lines = new ArrayList<String>();
+        String line;
+        while ((line = reader.readLine()) != null) {
+            lines.add(line);
+        }
+        return lines;
     }
 
     public static Collection<String> readAllLines(File file) throws IOException {
@@ -134,6 +134,16 @@
         }
     }
 
+    public static Collection<String> readAllLines(InputStream stream) throws IOException {
+        InputStreamReader reader = new InputStreamReader(stream);
+        try {
+            return readAllLines(reader);
+        } finally {
+            FileUtils.safelyClose(reader);
+            FileUtils.safelyClose(stream);
+        }
+    }
+
     public static void writeLines(File file, Collection<String> lines) throws IOException {
         PrintWriter pw = null;
         try {