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