26
26
package jdk .jfr .jcmd ;
27
27
28
28
import java .nio .file .Files ;
29
+ import java .nio .file .Paths ;
29
30
import java .util .ArrayList ;
30
31
import java .util .List ;
31
32
33
+ import jdk .jfr .internal .Repository ;
34
+ import jdk .jfr .internal .SecuritySupport .SafePath ;
32
35
import jdk .jfr .internal .Options ;
33
36
import jdk .test .lib .Asserts ;
34
37
import jdk .test .lib .Utils ;
40
43
* @requires vm.hasJFR
41
44
* @library /test/lib /test/jdk
42
45
* @modules jdk.jfr/jdk.jfr.internal
43
- * @run main/othervm jdk.jfr.jcmd.TestJcmdConfigure
46
+ * @run main/othervm -Xlog:jfr=info:file=jfr_info.txt jdk.jfr.jcmd.TestJcmdConfigure
44
47
*/
45
48
public class TestJcmdConfigure {
46
49
@@ -53,6 +56,13 @@ public class TestJcmdConfigure {
53
56
private static final String SAMPLE_THREADS = "samplethreads" ;
54
57
private static final String UNSUPPORTED_OPTION = "unsupportedoption" ;
55
58
59
+ private static final String REPOSITORYPATH_1 = "./repo1" ;
60
+ private static final String REPOSITORYPATH_2 = "./repo2" ;
61
+
62
+ private static final String REPOSITORYPATH_SETTING_1 = "repositorypath=" +REPOSITORYPATH_1 ;
63
+ private static final String REPOSITORYPATH_SETTING_2 = "repositorypath=" +REPOSITORYPATH_2 ;
64
+ private static final String JFR_UNIFIED_LOG_FILE = "jfr_info.txt" ;
65
+
56
66
public static void main (String [] args ) throws Exception {
57
67
//
58
68
// Simple sanity tests against what is available in Java,
@@ -76,6 +86,8 @@ public static void main(String[] args) throws Exception {
76
86
testNegative (UNSUPPORTED_OPTION , 100000 );
77
87
testNegative (MAX_CHUNK_SIZE , -500 );
78
88
89
+ testRepository ();
90
+
79
91
if (!testExceptions .isEmpty ()) {
80
92
for (Exception e : testExceptions ) {
81
93
System .out .println ("Error: " + e .getMessage ());
@@ -118,4 +130,28 @@ private static Object getOption(String name) {
118
130
default : throw new RuntimeException ("Unknown option " + name );
119
131
}
120
132
}
133
+
134
+ private static void testRepository (){
135
+ final String findWhat = "[info][jfr] Same base repository path " + REPOSITORYPATH_1 + " is set" ;
136
+
137
+ try {
138
+ JcmdHelper .jcmd ("JFR.configure" , REPOSITORYPATH_SETTING_1 );
139
+ SafePath initialPath = Repository .getRepository ().getRepositoryPath ();
140
+
141
+ JcmdHelper .jcmd ("JFR.configure" , REPOSITORYPATH_SETTING_1 );
142
+ SafePath samePath = Repository .getRepository ().getRepositoryPath ();
143
+ Asserts .assertTrue (samePath .equals (initialPath ));
144
+
145
+ List <String > lines = Files .readAllLines (Paths .get (JFR_UNIFIED_LOG_FILE ));
146
+ Asserts .assertTrue (lines .stream ().anyMatch (l ->l .contains (findWhat )));
147
+
148
+ JcmdHelper .jcmd ("JFR.configure" , REPOSITORYPATH_SETTING_2 );
149
+ SafePath changedPath = Repository .getRepository ().getRepositoryPath ();
150
+
151
+ Asserts .assertFalse (changedPath .equals (initialPath ));
152
+
153
+ } catch (Exception e ) {
154
+ testExceptions .add (e );
155
+ }
156
+ }
121
157
}
0 commit comments