/* * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/ package jdk.jfr.tool;
privatestaticvoid testVerbose() throws Throwable { var input = newInputFile("flag.jfc");
var output = newOutputFile("verbose-1.jfc"); var result = jfrConfigure("--input", input, "--verbose", "mammal=true", "--output", output);
result.shouldContain("com.example.Lion#enabled=true");
result.shouldContain("com.example.Tiger#enabled=true");
var input1Setting = readSettings(input1); var input2Setting = readSettings(input2); var outputSetting = readSettings(output);
Map<String, String> expected = new HashMap<>();
expected.putAll(input1Setting);
expected.putAll(input2Setting);
aseertEqual(outputSetting, expected);
}
privatestaticvoid testAdding() throws Throwable { var input = newInputFile("plain.jfc");
var output = newOutputFile("test-adding-succeed-1.jfc"); var result = jfrConfigure("--input", input, "+com.example.Tiger#legs=4", "--output", output);
result.shouldNotContain("Could not find"); var outputSetting = readSettings(output); var expected = readSettings(input);
expected.put("com.example.Tiger#legs", "4");
aseertEqual(outputSetting, expected);
output = newOutputFile("test-adding-succeed-2.jfc");
result = jfrConfigure("--input", input, "+com.example.Foo#bar=baz", "--output", output);
result.shouldNotContain("Could not find");
privatestaticvoid testModify() throws Throwable { var input = newInputFile("plain.jfc");
var output = newOutputFile("test-modify-fail-1.jfc"); var result = jfrConfigure("--input", input, "com.example.Zebra#stackTrace=true", "--output", output);
result.shouldContain("Could not find event 'com.example.Zebra'");
output = newOutputFile("test-modify-fail-2.jfc");
result = jfrConfigure("--input", input, "com.example.Tiger#foo=true", "--output", output);
result.shouldContain("Could not find setting 'foo' for event 'com.example.Tiger'");
output = newOutputFile("test-modify-succeed.jfc");
result = jfrConfigure("--input", input, "com.example.Tiger#enabled=true", "--output", output);
result.shouldNotContain("Could not find");
var outputSetting = readSettings(output); var expected = readSettings(input);
expected.put("com.example.Tiger#enabled", "true");
aseertEqual(outputSetting, expected);
}
// JMC may add attributes or elements, make sure some random elements/attributes survive privatestaticvoid testSuperflouos() throws Throwable { var output = newOutputFile("test-superfluous.jfc"); var input = newInputFile("superfluous.jfc");
jfrConfigure("--input", input, "--output", output);
String content = Files.readString(Path.of(output)); for (String t : List.of("legs=\"4\"", "radio", "red", "", "option")) { if (!content.contains(t)) { thrownew Exception("Expected superfluous element '" + t + "' or attribute to survive");
}
}
}
privatestaticvoid testMissingControl() throws Throwable { var output = newOutputFile("missed.jfc"); var input = newInputFile("missing.jfc"); var result = jfrConfigure("--input", input, "--output", output);
result.shouldContain("Warning! Setting 'com.example.Tiger#enabled' refers to missing control 'tigre'");
}
privatestaticvoid testDefault() throws Throwable { var output = newOutputFile("fresh.jfc"); var result = jfrConfigure("--output", output);
result.shouldNotContain("Warning"); // checks dangling control reference in default.jfc var outputSetting = readSettings(output);
aseertEqual(outputSetting, Configuration.getConfiguration("default").getSettings());
}
privatestaticvoid testCopyPredefined() throws Throwable { var output = newOutputFile("new.jfc"); var result = jfrConfigure("--input", "profile", "--output", output);
result.shouldNotContain("Warning"); // checks missing control reference in profile.jfc
var outputSetting = readSettings(output);
aseertEqual(outputSetting, Configuration.getConfiguration("profile").getSettings());
}
privatestaticvoid testNone() throws Throwable { var output = newOutputFile("new.jfc");
jfrConfigure("--input", "none", "--output", output); var outputSetting = readSettings(output);
aseertEqual(outputSetting, Map.of());
}
privatestaticvoid testOr() throws Throwable { var output = newOutputFile("test-or-true.jfc"); var input = newInputFile("or.jfc");
jfrConfigure("--input", input, "month=May", "--output", output); var outputSetting = readSettings(output); var expected = readSettings(input);
expected.put("season.Spring#enabled", "true");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.