changeset 975:928634dbc9ec

runners: clean up BenchmarkList and its tests.
author shade
date Fri, 22 Aug 2014 12:08:46 +0400
parents 1fe1a9936fa8
children a128b58999b1
files jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkList.java jmh-core/src/test/java/org/openjdk/jmh/runner/TestBenchmarkList.java
diffstat 2 files changed, 36 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkList.java	Fri Aug 22 11:44:38 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkList.java	Fri Aug 22 12:08:46 2014 +0400
@@ -30,7 +30,7 @@
 import java.io.IOException;
 import java.io.Reader;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import java.util.SortedSet;
@@ -69,32 +69,21 @@
      * @return A list of all benchmarks, excluding matched
      */
     public Set<BenchmarkListEntry> getAll(OutputFormat out, List<String> excludes) {
-        return find(out, ".*", excludes);
+        return find(out, Arrays.asList(".*"), excludes);
     }
 
     /**
      * Gets all the micro benchmarks that matches the given regexp, sorted.
      *
      * @param out Output the messages here
-     * @param regexp   Regexp to match against
-     * @param excludes List of regexps to match excludes against
-     * @return Names of all micro benchmarks in the list that matches the include and NOT matching excludes
-     */
-    public Set<BenchmarkListEntry> find(OutputFormat out, String regexp, List<String> excludes) {
-        return find(out, Collections.singletonList(regexp), excludes);
-    }
-
-    /**
-     * Gets all the micro benchmarks that matches the given regexp, sorted.
-     *
-     * @param out Output the messages here
-     * @param regexps  List of regexps to match against
+     * @param includes  List of regexps to match against
      * @param excludes List of regexps to match excludes against
      * @return Names of all micro benchmarks in the list that matches includes and NOT matching excludes
      */
-    public SortedSet<BenchmarkListEntry> find(OutputFormat out, List<String> regexps, List<String> excludes) {
+    public SortedSet<BenchmarkListEntry> find(OutputFormat out, List<String> includes, List<String> excludes) {
 
         // assume we match all benchmarks when include is empty
+        List<String> regexps = new ArrayList<String>(includes);
         if (regexps.isEmpty()) {
             regexps.add(".*");
         }
--- a/jmh-core/src/test/java/org/openjdk/jmh/runner/TestBenchmarkList.java	Fri Aug 22 11:44:38 2014 +0400
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/TestBenchmarkList.java	Fri Aug 22 12:08:46 2014 +0400
@@ -30,8 +30,8 @@
 import org.openjdk.jmh.runner.format.OutputFormatFactory;
 import org.openjdk.jmh.runner.options.VerboseMode;
 
-import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
@@ -44,29 +44,26 @@
 public class TestBenchmarkList {
 
     private static BenchmarkList list;
-    private static List<String> excludes;
     private static OutputFormat out;
 
     @BeforeClass
     public static void setUpClass() throws Exception {
         list = BenchmarkList.fromResource("/org/openjdk/jmh/runner/MicroBenchmarks");
-        excludes = new ArrayList<String>();
         out = OutputFormatFactory.createFormatInstance(System.out, VerboseMode.NORMAL);
     }
 
     @Test
     public void testListGetNothing() throws Exception {
         // make sure we get nothing
-        excludes.clear();
-        excludes.add(".*");
+        List<String> excludes = Arrays.asList(".*");
         Set<BenchmarkListEntry> micros = list.getAll(out, excludes);
         assertEquals(0, micros.size());
     }
 
     @Test
     public void testListGetAll() throws Exception {
-        excludes.clear();
         // make sure we get em all
+        List<String> excludes = Collections.emptyList();
         Set<BenchmarkListEntry> micros = list.getAll(out, excludes);
         assertEquals(20, micros.size());
     }
@@ -74,87 +71,90 @@
     @Test
     public void testListFindSingleByPattern() throws Exception {
         // check find without excludes
-        excludes.clear();
-        Set<BenchmarkListEntry> micros = list.find(out, ".*Hash.*", excludes);
+        List<String> includes = Arrays.asList(".*Hash.*");
+        List<String> excludes = Collections.emptyList();
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(7, micros.size());
     }
 
     @Test
     public void testListFindSingleBySubstring() throws Exception {
         // check find without excludes
-        excludes.clear();
-        Set<BenchmarkListEntry> micros = list.find(out, "Hash", excludes);
+        List<String> includes = Arrays.asList("Hash");
+        List<String> excludes = Collections.emptyList();
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(7, micros.size());
     }
 
     @Test
     public void testListFindSingleByTypical() throws Exception {
         // check find without excludes
-        excludes.clear();
         // this would be a typical partial pattern with . abuse case
-        Set<BenchmarkListEntry> micros = list.find(out, "jbb05.GeneratedSPECjbb2005HashMap", excludes);
+        List<String> includes = Arrays.asList("jbb05.GeneratedSPECjbb2005HashMap");
+        List<String> excludes = Collections.emptyList();
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(5, micros.size());
     }
 
     @Test
     public void testListFindAnchored() throws Exception {
         // check find without excludes
-        excludes.clear();
         // matches only: org.openjdk.jmh.runner.TestMicro.dummy
-        Set<BenchmarkListEntry> micros = list.find(out, "^org\\.openjdk.*\\.dummy$", excludes);
+        List<String> includes = Arrays.asList("^org\\.openjdk.*\\.dummy$");
+        List<String> excludes = Collections.emptyList();
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(1, micros.size());
     }
 
     @Test
     public void testListFindSingleWithExcludes() throws Exception {
         // check find with excludes
-        excludes.clear();
-        excludes.add(".*Int.*");
-        Set<BenchmarkListEntry> micros = list.find(out, ".*Hash.*", excludes);
+        List<String> includes = Arrays.asList(".*Hash.*");
+        List<String> excludes = Arrays.asList(".*Int.*");
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(2, micros.size());
     }
 
     @Test
     public void testListFindAllWithSubstringExclude() throws Exception {
         // check find with excludes
-        excludes.clear();
-        excludes.add("oracle");
-        Set<BenchmarkListEntry> micros = list.find(out, "", excludes);
+        List<String> includes = Arrays.asList("");
+        List<String> excludes = Arrays.asList("oracle");
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(10, micros.size());
     }
 
     @Test
     public void testListFindAllWithEmpty() throws Exception {
-        // will get modified
-        List<String> emptyIncludes = new ArrayList<String>();
-        excludes.clear();
-        Set<BenchmarkListEntry> micros = list.find(out, emptyIncludes, excludes);
+        List<String> includes = Collections.emptyList();
+        List<String> excludes = Collections.emptyList();
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(20, micros.size());
     }
 
     @Test
     public void testListFindIncludeList() throws Exception {
         // check find with excludes
-        excludes.clear();
         List<String> includes = Arrays.asList("^oracle", ".*openjmh.*");
+        List<String> excludes = Collections.emptyList();
         Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(10, micros.size());
     }
 
     @Test
     public void testListFindWithIncludesAndExcludes() throws Exception {
-        excludes.clear();
-        excludes.add(".*Int.*");
-        Set<BenchmarkListEntry> micros = list.find(out, ".*Concurrent.*", excludes);
+        List<String> includes = Arrays.asList(".*Concurrent.*");
+        List<String> excludes = Arrays.asList(".*Int.*");
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         assertEquals(2, micros.size());
     }
 
     @Test
     public void testListIsSorted() throws Exception {
         // micros should be sorted
-        excludes.clear();
-        excludes.add(".*Int.*");
-        Set<BenchmarkListEntry> micros = list.find(out, ".*Hash.*", excludes);
+        List<String> includes = Arrays.asList(".*Hash.*");
+        List<String> excludes = Arrays.asList(".*Int.*");
+        Set<BenchmarkListEntry> micros = list.find(out, includes, excludes);
         BenchmarkListEntry first = micros.iterator().next();
         assertTrue("oracle.micro.benchmarks.api.java.util.concurrent.GeneratedMaps.testConcurrentHashMap".equals(first.getUsername()));
     }