< prev index next >

test/jdk/jdk/jfr/event/metadata/TestDefaultConfigurations.java

Print this page


   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


 160     }
 161 
 162     private static Document createDocument(String content) throws ParserConfigurationException, SAXException, IOException {
 163         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 164         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
 165         Document doc = dBuilder.parse(new InputSource(new StringReader(content)));
 166         doc.getDocumentElement().normalize();
 167         // Don't want to add these settings to the jfc-files we ship since they
 168         // are not useful to configure. They are however needed to make the test
 169         // pass.
 170         insertSetting(doc, EventNames.ActiveSetting, "stackTrace", "false");
 171         insertSetting(doc, EventNames.ActiveSetting, "threshold", "0 ns");
 172         insertSetting(doc, EventNames.ActiveRecording, "stackTrace", "false");
 173         insertSetting(doc, EventNames.ActiveRecording, "threshold", "0 ns");
 174         insertSetting(doc, EventNames.JavaExceptionThrow, "threshold", "0 ns");
 175         insertSetting(doc, EventNames.JavaErrorThrow, "threshold", "0 ns");
 176         insertSetting(doc, EventNames.SecurityProperty, "threshold", "0 ns");
 177         insertSetting(doc, EventNames.TLSHandshake, "threshold", "0 ns");
 178         insertSetting(doc, EventNames.X509Certificate, "threshold", "0 ns");
 179         insertSetting(doc, EventNames.X509Validation, "threshold", "0 ns");


 180         return doc;
 181     }
 182 
 183     private static void insertSetting(Document doc, String eventName, String settingName, String settingValue) {
 184         for (Element event : getChildElements(doc.getDocumentElement(), "event")) {
 185             Attr attribute = event.getAttributeNode("name");
 186             if (attribute != null) {
 187                 if (eventName.equals(attribute.getValue())) {
 188                     Element setting = doc.createElement("setting");
 189                     setting.setAttribute("name", settingName);
 190                     setting.setTextContent(settingValue);
 191                     event.appendChild(setting);
 192                 }
 193             }
 194         }
 195     }
 196 
 197     private static Collection<Element> getChildElements(Element parent, String name) {
 198         NodeList elementsByTagName = parent.getElementsByTagName(name);
 199         List<Element> elements = new ArrayList<>();
   1 /*
   2  * Copyright (c) 2018, 2020, 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


 160     }
 161 
 162     private static Document createDocument(String content) throws ParserConfigurationException, SAXException, IOException {
 163         DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
 164         DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
 165         Document doc = dBuilder.parse(new InputSource(new StringReader(content)));
 166         doc.getDocumentElement().normalize();
 167         // Don't want to add these settings to the jfc-files we ship since they
 168         // are not useful to configure. They are however needed to make the test
 169         // pass.
 170         insertSetting(doc, EventNames.ActiveSetting, "stackTrace", "false");
 171         insertSetting(doc, EventNames.ActiveSetting, "threshold", "0 ns");
 172         insertSetting(doc, EventNames.ActiveRecording, "stackTrace", "false");
 173         insertSetting(doc, EventNames.ActiveRecording, "threshold", "0 ns");
 174         insertSetting(doc, EventNames.JavaExceptionThrow, "threshold", "0 ns");
 175         insertSetting(doc, EventNames.JavaErrorThrow, "threshold", "0 ns");
 176         insertSetting(doc, EventNames.SecurityProperty, "threshold", "0 ns");
 177         insertSetting(doc, EventNames.TLSHandshake, "threshold", "0 ns");
 178         insertSetting(doc, EventNames.X509Certificate, "threshold", "0 ns");
 179         insertSetting(doc, EventNames.X509Validation, "threshold", "0 ns");
 180         insertSetting(doc, EventNames.ProcessStart, "threshold", "0 ns");
 181 
 182         return doc;
 183     }
 184 
 185     private static void insertSetting(Document doc, String eventName, String settingName, String settingValue) {
 186         for (Element event : getChildElements(doc.getDocumentElement(), "event")) {
 187             Attr attribute = event.getAttributeNode("name");
 188             if (attribute != null) {
 189                 if (eventName.equals(attribute.getValue())) {
 190                     Element setting = doc.createElement("setting");
 191                     setting.setAttribute("name", settingName);
 192                     setting.setTextContent(settingValue);
 193                     event.appendChild(setting);
 194                 }
 195             }
 196         }
 197     }
 198 
 199     private static Collection<Element> getChildElements(Element parent, String name) {
 200         NodeList elementsByTagName = parent.getElementsByTagName(name);
 201         List<Element> elements = new ArrayList<>();
< prev index next >