test/jdk/jdk/jfr/api/consumer/streaming/TestJVMExit.java
changeset 59226 a0f39cc47387
child 59246 fcad92f425c5
equal deleted inserted replaced
59225:80e1201f6c9a 59226:a0f39cc47387
       
     1 /*
       
     2  * Copyright (c) 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.consumer.streaming;
       
    26 
       
    27 import java.time.Instant;
       
    28 import java.util.concurrent.atomic.AtomicInteger;
       
    29 
       
    30 import jdk.jfr.consumer.EventStream;
       
    31 
       
    32 /**
       
    33  * @test
       
    34  * @summary Test that a stream ends/closes when an application exists.
       
    35  * @key jfr
       
    36  * @requires vm.hasJFR
       
    37  * @library /test/lib /test/jdk
       
    38  * @modules jdk.jfr jdk.attach java.base/jdk.internal.misc
       
    39  *
       
    40  * @run main/othervm jdk.jfr.api.consumer.streaming.TestJVMExit
       
    41  */
       
    42 public class TestJVMExit {
       
    43 
       
    44     public static void main(String... args) throws Exception {
       
    45         TestProcess process = new TestProcess("exit-application");
       
    46         AtomicInteger eventCounter = new AtomicInteger();
       
    47         try (EventStream es = EventStream.openRepository(process.getRepository())) {
       
    48             // Start from first event in repository
       
    49             es.setStartTime(Instant.EPOCH);
       
    50             es.onEvent(e -> {
       
    51                 if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) {
       
    52                     process.exit();
       
    53                 }
       
    54             });
       
    55             es.start();
       
    56         }
       
    57     }
       
    58 }