test/jdk/jdk/jfr/api/metadata/annotations/TestFormatMissingValue.java
changeset 53013 c8b2a408628b
equal deleted inserted replaced
53012:c1eed9867bf0 53013:c8b2a408628b
       
     1 /*
       
     2  * Copyright (c) 2015, 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 
       
    26 package jdk.jfr.api.metadata.annotations;
       
    27 
       
    28 import jdk.jfr.DataAmount;
       
    29 import jdk.jfr.Event;
       
    30 import jdk.jfr.Frequency;
       
    31 import jdk.jfr.Recording;
       
    32 import jdk.jfr.StackTrace;
       
    33 import jdk.jfr.consumer.RecordedEvent;
       
    34 import jdk.test.lib.Asserts;
       
    35 import jdk.test.lib.jfr.Events;
       
    36 
       
    37 /**
       
    38  * @test
       
    39  * @key jfr
       
    40  * @summary Check that event values are properly formatted and sanity check
       
    41  *              that extreme values don't throws exceptions
       
    42  * @requires vm.hasJFR
       
    43  * @library /test/lib
       
    44  * @run main/othervm jdk.jfr.api.metadata.annotations.TestFormatMissingValue
       
    45  */
       
    46 public class TestFormatMissingValue {
       
    47 
       
    48     @StackTrace(false)
       
    49     static class MultiContentTypeEvent extends Event {
       
    50         @DataAmount(DataAmount.BYTES)
       
    51         @Frequency
       
    52         long a = Long.MIN_VALUE;
       
    53 
       
    54         @DataAmount(DataAmount.BYTES)
       
    55         @Frequency
       
    56         long b = Long.MAX_VALUE;
       
    57 
       
    58         @DataAmount(DataAmount.BYTES)
       
    59         @Frequency
       
    60         int c = Integer.MIN_VALUE;
       
    61 
       
    62         @DataAmount(DataAmount.BYTES)
       
    63         @Frequency
       
    64         int d = Integer.MAX_VALUE;
       
    65 
       
    66         @DataAmount(DataAmount.BYTES)
       
    67         @Frequency
       
    68         double e = Double.NEGATIVE_INFINITY;
       
    69 
       
    70         @DataAmount(DataAmount.BYTES)
       
    71         @Frequency
       
    72         double f = Double.POSITIVE_INFINITY;
       
    73 
       
    74         @DataAmount(DataAmount.BYTES)
       
    75         @Frequency
       
    76         double g = Double.NaN;
       
    77 
       
    78         @DataAmount(DataAmount.BYTES)
       
    79         @Frequency
       
    80         float h = Float.NEGATIVE_INFINITY;
       
    81 
       
    82         @DataAmount(DataAmount.BYTES)
       
    83         @Frequency
       
    84         float i = Float.POSITIVE_INFINITY;
       
    85 
       
    86         @DataAmount(DataAmount.BYTES)
       
    87         @Frequency
       
    88         float j = Float.NaN;
       
    89     }
       
    90 
       
    91     public static void main(String[] args) throws Exception {
       
    92         try (Recording r = new Recording()) {
       
    93             r.start();
       
    94             MultiContentTypeEvent m = new MultiContentTypeEvent();
       
    95             m.commit();
       
    96             r.stop();
       
    97             for (RecordedEvent e : Events.fromRecording(r)) {
       
    98                 String t = e.toString();
       
    99                 assertContains(t, "a = N/A");
       
   100                 assertContains(t, "c = N/A");
       
   101                 assertContains(t, "e = N/A");
       
   102                 assertContains(t, "g = N/A");
       
   103                 assertContains(t, "h = N/A");
       
   104                 assertContains(t, "j = N/A");
       
   105 
       
   106                 assertNotContains(t, "b = N/A");
       
   107                 assertNotContains(t, "d = N/A");
       
   108                 assertNotContains(t, "f = N/A");
       
   109                 assertNotContains(t, "i = N/A");
       
   110             }
       
   111         }
       
   112     }
       
   113 
       
   114     private static void assertContains(String t, String text) {
       
   115         if (!t.contains(text)) {
       
   116             Asserts.fail("Expected '" + t + "' to contain text '" + text + "'");
       
   117         }
       
   118     }
       
   119 
       
   120     private static void assertNotContains(String t, String text) {
       
   121         if (t.contains(text)) {
       
   122             Asserts.fail("Found unexpected value '" + text + "'  in text '" + t + "'");
       
   123         }
       
   124     }
       
   125 }