50113
|
1 |
/*
|
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package jdk.jfr.api.recording.settings;
|
|
27 |
|
|
28 |
|
|
29 |
import java.io.File;
|
|
30 |
import java.io.FileReader;
|
|
31 |
import java.io.Reader;
|
|
32 |
import java.util.Map;
|
|
33 |
|
|
34 |
import jdk.jfr.Configuration;
|
|
35 |
import jdk.test.lib.Asserts;
|
|
36 |
import jdk.test.lib.jfr.EventNames;
|
|
37 |
|
|
38 |
/*
|
|
39 |
* @test
|
|
40 |
* @summary Test setName().
|
|
41 |
* @key jfr
|
|
42 |
* @library /test/lib
|
|
43 |
* @run main/othervm jdk.jfr.api.recording.settings.TestCreateConfigFromReader
|
|
44 |
*/
|
|
45 |
public class TestCreateConfigFromReader {
|
|
46 |
|
|
47 |
private static final String DIR = System.getProperty("test.src", ".");
|
|
48 |
|
|
49 |
public static void main(String[] args) throws Throwable {
|
|
50 |
testOkConfig();
|
|
51 |
testNullReader();
|
|
52 |
}
|
|
53 |
|
|
54 |
private static void testOkConfig() throws Exception {
|
|
55 |
File settingsFile = new File(DIR, "settings.jfc");
|
|
56 |
if(!settingsFile.exists()) throw new RuntimeException("File " + settingsFile.getAbsolutePath() + " not found ");
|
|
57 |
|
|
58 |
FileReader reader = new FileReader(settingsFile);
|
|
59 |
|
|
60 |
Configuration config = Configuration.create(reader);
|
|
61 |
Map<String, String> settings = config.getSettings();
|
|
62 |
|
|
63 |
Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
|
|
64 |
String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
|
|
65 |
String[] vals = {"true", "true", "1 ms", "5"};
|
|
66 |
for(int i=0; i<keys.length; ++i) {
|
|
67 |
String fullKey = EventNames.JavaMonitorWait + "#" + keys[i];
|
|
68 |
Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
|
|
69 |
}
|
|
70 |
Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");
|
|
71 |
|
|
72 |
Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
|
|
73 |
Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
|
|
74 |
Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
|
|
75 |
Asserts.assertNull(config.getName(), "Name should be null if created from reader");
|
|
76 |
}
|
|
77 |
|
|
78 |
private static void testNullReader() throws Exception {
|
|
79 |
try {
|
|
80 |
Configuration.create((Reader)null);
|
|
81 |
Asserts.fail("Exception was not thrown");
|
|
82 |
} catch(NullPointerException x) {
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
}
|