test/jdk/jdk/jfr/api/consumer/streaming/TestEmptyChunks.java
author egahlin
Thu, 24 Oct 2019 07:02:36 +0200
branchJEP-349-branch
changeset 58774 141412e96b12
parent 57361 53dccc90a5be
permissions -rw-r--r--
Stabilize tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     1
/*
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     4
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    10
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    15
 * accompanied this code).
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    16
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    20
 *
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    23
 * questions.
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    24
 */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    25
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    26
package jdk.jfr.api.consumer.streaming;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    27
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    28
import java.util.concurrent.CountDownLatch;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    29
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    30
import jdk.jfr.Event;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    31
import jdk.jfr.Recording;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    32
import jdk.jfr.consumer.RecordingStream;
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    33
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    34
/**
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    35
 * @test
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    36
 * @summary Test that it is possible to iterate over chunk without normal events
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    37
 * @key jfr
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    38
 * @requires vm.hasJFR
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    39
 * @library /test/lib
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    40
 * @run main/othervm jdk.jfr.api.consumer.streaming.TestEmptyChunks
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    41
 */
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    42
public class TestEmptyChunks {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    43
    static class EndEvent extends Event {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    44
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    45
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    46
    public static void main(String... args) throws Exception {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    47
        CountDownLatch end = new CountDownLatch(1);
58774
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    48
        CountDownLatch firstFlush = new CountDownLatch(1);
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    49
        try (RecordingStream es = new RecordingStream()) {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    50
            es.onEvent(EndEvent.class.getName(), e -> {
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    51
                end.countDown();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    52
            });
58774
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    53
            es.onFlush(() -> {
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    54
                firstFlush.countDown();
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    55
            });
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    56
            es.startAsync();
58774
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    57
            System.out.println("Invoked startAsync()");
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    58
            // Wait for stream thread to start
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    59
            firstFlush.await();
141412e96b12 Stabilize tests
egahlin
parents: 57361
diff changeset
    60
            System.out.println("Stream thread active");
57361
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    61
            Recording r1 = new Recording();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    62
            r1.start();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    63
            System.out.println("Chunk 1 started");
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    64
            Recording r2 = new Recording();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    65
            r2.start();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    66
            System.out.println("Chunk 2 started");
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    67
            Recording r3 = new Recording();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    68
            r3.start();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    69
            System.out.println("Chunk 3 started");
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    70
            r2.stop();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    71
            System.out.println("Chunk 4 started");
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    72
            r3.stop();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    73
            System.out.println("Chunk 5 started");
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    74
            EndEvent e = new EndEvent();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    75
            e.commit();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    76
            end.await();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    77
            r1.stop();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    78
            System.out.println("Chunk 5 ended");
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    79
            r1.close();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    80
            r2.close();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    81
            r3.close();
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    82
        }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    83
    }
53dccc90a5be Preview-addendum
mgronlun
parents:
diff changeset
    84
}