|
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 |
|
26 package jdk.jfr.api.consumer.streaming; |
|
27 |
|
28 import java.util.concurrent.CountDownLatch; |
|
29 |
|
30 import jdk.jfr.Event; |
|
31 import jdk.jfr.FlightRecorder; |
|
32 import jdk.jfr.Name; |
|
33 import jdk.jfr.Period; |
|
34 import jdk.jfr.Recording; |
|
35 import jdk.jfr.consumer.RecordingStream; |
|
36 |
|
37 /** |
|
38 * @test |
|
39 * @summary Verifies that it is possible to stream contents of ongoing |
|
40 * recordings |
|
41 * @key jfr |
|
42 * @requires vm.hasJFR |
|
43 * @library /test/lib |
|
44 * @run main/othervm -Xlog:jfr+system+streaming=trace |
|
45 * jdk.jfr.api.consumer.streaming.TestStartMultiChunk |
|
46 */ |
|
47 public class TestStartMultiChunk { |
|
48 |
|
49 @Period("10 s") |
|
50 @Name("Zebra") |
|
51 static class ZebraEvent extends Event { |
|
52 } |
|
53 |
|
54 @Name("Cat") |
|
55 static class CatEvent extends Event { |
|
56 } |
|
57 |
|
58 @Name("Dog") |
|
59 static class DogEvent extends Event { |
|
60 } |
|
61 |
|
62 @Name("Mouse") |
|
63 static class MouseEvent extends Event { |
|
64 } |
|
65 |
|
66 public static void main(String... args) throws Exception { |
|
67 CountDownLatch dogLatch = new CountDownLatch(1); |
|
68 CountDownLatch catLatch = new CountDownLatch(1); |
|
69 CountDownLatch mouseLatch = new CountDownLatch(1); |
|
70 CountDownLatch zebraLatch = new CountDownLatch(3); |
|
71 |
|
72 FlightRecorder.addPeriodicEvent(ZebraEvent.class, () -> { |
|
73 ZebraEvent ze = new ZebraEvent(); |
|
74 ze.commit(); |
|
75 System.out.println("Zebra emitted"); |
|
76 }); |
|
77 |
|
78 try (RecordingStream s = new RecordingStream()) { |
|
79 s.onEvent("Cat", e -> { |
|
80 System.out.println("Found cat!"); |
|
81 catLatch.countDown(); |
|
82 }); |
|
83 s.onEvent("Dog", e -> { |
|
84 System.out.println("Found dog!"); |
|
85 dogLatch.countDown(); |
|
86 }); |
|
87 s.onEvent("Zebra", e -> { |
|
88 System.out.println("Found zebra!"); |
|
89 zebraLatch.countDown(); |
|
90 }); |
|
91 s.onEvent("Mouse", e -> { |
|
92 System.out.println("Found mouse!"); |
|
93 mouseLatch.countDown(); |
|
94 }); |
|
95 s.startAsync(); |
|
96 System.out.println("Stream recoding started"); |
|
97 |
|
98 try (Recording r1 = new Recording()) { |
|
99 r1.start(); |
|
100 System.out.println("r1.start()"); |
|
101 MouseEvent me = new MouseEvent(); |
|
102 me.commit(); |
|
103 System.out.println("Mouse emitted"); |
|
104 mouseLatch.await(); |
|
105 try (Recording r2 = new Recording()) { // force chunk rotation |
|
106 // in stream |
|
107 r2.start(); |
|
108 System.out.println("r2.start()"); |
|
109 DogEvent de = new DogEvent(); |
|
110 de.commit(); |
|
111 System.out.println("Dog emitted"); |
|
112 dogLatch.await(); |
|
113 CatEvent ce = new CatEvent(); |
|
114 ce.commit(); |
|
115 System.out.println("Cat emitted"); |
|
116 catLatch.await(); |
|
117 zebraLatch.await(); |
|
118 } |
|
119 } |
|
120 } |
|
121 } |
|
122 } |