|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
21 | 21 | * questions.
|
22 | 22 | */
|
23 | 23 |
|
| 24 | +import org.testng.annotations.DataProvider; |
24 | 25 | import org.testng.annotations.Test;
|
25 | 26 |
|
26 | 27 | import java.util.regex.Pattern;
|
|
42 | 43 | public class ClassHistogramTest {
|
43 | 44 | public static class TestClass {}
|
44 | 45 | public static TestClass[] instances = new TestClass[1024];
|
45 |
| - protected String classHistogramArgs = ""; |
46 | 46 |
|
47 | 47 | static {
|
48 | 48 | for (int i = 0; i < instances.length; ++i) {
|
49 | 49 | instances[i] = new TestClass();
|
50 | 50 | }
|
51 | 51 | }
|
52 | 52 |
|
53 |
| - public void run(CommandExecutor executor) { |
| 53 | + public void run(CommandExecutor executor, String classHistogramArgs, String expactedErrMsg) { |
54 | 54 | OutputAnalyzer output = executor.execute("GC.class_histogram " + classHistogramArgs);
|
| 55 | + if (!expactedErrMsg.isEmpty()) { |
| 56 | + output.shouldMatch(expactedErrMsg); |
| 57 | + return; |
| 58 | + } |
55 | 59 |
|
56 | 60 | /*
|
57 | 61 | * example output:
|
@@ -87,8 +91,34 @@ public void run(CommandExecutor executor) {
|
87 | 91 | Pattern.quote(TestClass.class.getName()) + "\\s*$");
|
88 | 92 | }
|
89 | 93 |
|
90 |
| - @Test |
91 |
| - public void jmx() { |
92 |
| - run(new JMXExecutor()); |
| 94 | + @DataProvider(name="ArgsProvider") |
| 95 | + private Object[][] getArgs() { |
| 96 | + String parallelErr = "Parallel thread number out of range"; |
| 97 | + return new Object[][] { |
| 98 | + // valid args |
| 99 | + {"", ""}, |
| 100 | + {"-parallel=0", ""}, |
| 101 | + {"-parallel=1", ""}, |
| 102 | + {"-parallel=2", ""}, |
| 103 | + {"-parallel="+Long.MAX_VALUE, ""}, |
| 104 | + {"-all=false -parallel=0", ""}, |
| 105 | + {"-all=false -parallel=1", ""}, |
| 106 | + {"-all=false -parallel=2", ""}, |
| 107 | + {"-all=true", ""}, |
| 108 | + {"-all=true -parallel=0", ""}, |
| 109 | + {"-all=true -parallel=1", ""}, |
| 110 | + {"-all=true -parallel=2", ""}, |
| 111 | + {"-parallel=2 -all=true", ""}, |
| 112 | + // invalid args |
| 113 | + {"-parallel=-1", parallelErr}, |
| 114 | + {"-parallel="+Long.MIN_VALUE, parallelErr}, |
| 115 | + {"-all=false -parallel=-10", parallelErr}, |
| 116 | + {"-all=true -parallel=-100", parallelErr}, |
| 117 | + }; |
| 118 | + } |
| 119 | + |
| 120 | + @Test(dataProvider="ArgsProvider") |
| 121 | + public void jmx(String args, String expactedErrMsg) { |
| 122 | + run(new JMXExecutor(), args, expactedErrMsg); |
93 | 123 | }
|
94 | 124 | }
|
0 commit comments