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