1 /* 2 * Copyright (c) 2016, 2019, 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 package jdk.jfr.api.metadata.settingdescriptor; 26 27 import java.util.List; 28 29 import jdk.jfr.AnnotationElement; 30 import jdk.jfr.Description; 31 import jdk.jfr.EventType; 32 import jdk.jfr.Label; 33 import jdk.jfr.Name; 34 import jdk.jfr.SettingDescriptor; 35 import jdk.jfr.Timespan; 36 import jdk.testlibrary.Asserts; 37 import jdk.testlibrary.jfr.Events; 38 import jdk.testlibrary.jfr.BaseEvent; 39 import jdk.testlibrary.jfr.PlainSetting; 40 import jdk.testlibrary.jfr.AnnotatedSetting; 41 import jdk.testlibrary.jfr.CustomEvent; 42 43 /* 44 * @test 45 * @summary Test SettingDescriptor.getAnnotationElements() 46 * @key jfr 47 * @library /lib/testlibrary 48 * @run main/othervm jdk.jfr.api.metadata.settingdescriptor.TestGetAnnotationElement 49 */ 50 public class TestGetAnnotationElement { 51 52 public static void main(String[] args) throws Exception { 53 EventType type = EventType.getEventType(CustomEvent.class); 54 55 SettingDescriptor plain = Events.getSetting(type, "plain"); 56 Asserts.assertTrue(plain.getAnnotationElements().isEmpty()); 57 58 SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType"); 59 for (AnnotationElement ae : annotatedType.getAnnotationElements()) { 60 System.out.println(ae.getTypeName()); 61 } 62 Asserts.assertTrue(annotatedType.getAnnotationElements().isEmpty()); 63 64 SettingDescriptor newName = Events.getSetting(type, "newName"); 65 List<AnnotationElement> ae = newName.getAnnotationElements(); 66 Asserts.assertEquals(ae.size(), 4); 67 Asserts.assertEquals(ae.get(0).getTypeName(), Name.class.getName()); 68 Asserts.assertEquals(ae.get(1).getTypeName(), Label.class.getName()); 69 Asserts.assertEquals(ae.get(2).getTypeName(), Description.class.getName()); 70 Asserts.assertEquals(ae.get(3).getTypeName(), Timespan.class.getName()); 71 72 SettingDescriptor overridden = Events.getSetting(type, "overridden"); 73 Asserts.assertTrue(overridden.getAnnotationElements().isEmpty()); 74 75 CustomEvent.assertOnDisk((x, y) -> { 76 List<AnnotationElement> a1 = x.getAnnotationElements(); 77 List<AnnotationElement> a2 = y.getAnnotationElements(); 78 if (a1.size() != a2.size()) { 79 throw new RuntimeException("Not same number of annotation ekements on disk as in process"); 80 } 81 for (int i = 0; i < a1.size(); i++) { 82 if (!a1.get(i).getTypeName().equals(a2.get(i).getTypeName())) { 83 throw new RuntimeException("Type name of annotation elements in process doesn't match type name on disk"); 84 } 85 } 86 return 0; 87 }); 88 } 89 90 }