author | egahlin |
Fri, 29 Nov 2019 17:31:01 +0100 | |
changeset 59327 | 2c3578aa0bdf |
parent 59310 | 72f3dd43dd28 |
permissions | -rw-r--r-- |
58863 | 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.recordingstream; |
|
27 |
||
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
28 |
import java.time.Instant; |
58863 | 29 |
import java.util.concurrent.CountDownLatch; |
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
30 |
import java.util.concurrent.atomic.AtomicReference; |
58863 | 31 |
|
32 |
import jdk.jfr.Event; |
|
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
33 |
import jdk.jfr.Recording; |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
34 |
import jdk.jfr.consumer.EventStream; |
58863 | 35 |
import jdk.jfr.consumer.RecordingStream; |
36 |
||
37 |
/** |
|
38 |
* @test |
|
39 |
* @summary Tests RecordingStream::close() |
|
40 |
* @key jfr |
|
41 |
* @requires vm.hasJFR |
|
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
42 |
* @library /test/lib /test/jdk |
58863 | 43 |
* @run main/othervm jdk.jfr.api.consumer.recordingstream.TestClose |
44 |
*/ |
|
45 |
public class TestClose { |
|
46 |
||
47 |
private static class CloseEvent extends Event { |
|
48 |
} |
|
49 |
||
50 |
public static void main(String... args) throws Exception { |
|
51 |
testCloseUnstarted(); |
|
52 |
testCloseStarted(); |
|
53 |
testCloseTwice(); |
|
54 |
testCloseStreaming(); |
|
55 |
testCloseMySelf(); |
|
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
56 |
testCloseNoEvents(); |
58863 | 57 |
} |
58 |
||
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
59 |
private static void testCloseUnstarted() { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
60 |
System.out.println("testCloseUnstarted()"); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
61 |
|
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
62 |
try (RecordingStream r = new RecordingStream()) { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
63 |
r.close(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
64 |
} |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
65 |
} |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
66 |
|
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
67 |
private static void testCloseStarted() { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
68 |
System.out.println("testCloseStarted()"); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
69 |
|
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
70 |
try (RecordingStream r = new RecordingStream()) { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
71 |
r.startAsync(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
72 |
} // <- Close |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
73 |
} |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
74 |
|
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
75 |
private static void testCloseTwice() { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
76 |
System.out.println("Entering testCloseTwice()"); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
77 |
|
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
78 |
try (RecordingStream r = new RecordingStream()) { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
79 |
r.startAsync(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
80 |
r.close(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
81 |
} // <- Second close |
58863 | 82 |
} |
83 |
||
84 |
private static void testCloseStreaming() throws Exception { |
|
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
85 |
System.out.println("Entering testCloseStreaming()"); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
86 |
|
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
87 |
EventProducer p = new EventProducer(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
88 |
p.start(); |
58863 | 89 |
CountDownLatch streaming = new CountDownLatch(1); |
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
90 |
try (RecordingStream r = new RecordingStream()) { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
91 |
r.onEvent(e -> { |
58863 | 92 |
streaming.countDown(); |
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
93 |
}); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
94 |
r.startAsync(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
95 |
streaming.await(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
96 |
} // <- Close |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
97 |
p.kill(); |
58863 | 98 |
} |
99 |
||
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
100 |
private static void testCloseMySelf() throws Exception { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
101 |
System.out.println("testCloseMySelf()"); |
58863 | 102 |
|
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
103 |
CountDownLatch closed = new CountDownLatch(1); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
104 |
try (RecordingStream r = new RecordingStream()) { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
105 |
r.onEvent(e -> { |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
106 |
r.close(); // <- Close |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
107 |
closed.countDown(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
108 |
}); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
109 |
r.startAsync(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
110 |
CloseEvent c = new CloseEvent(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
111 |
c.commit(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
112 |
closed.await(); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
113 |
} |
58863 | 114 |
} |
115 |
||
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
116 |
private static void testCloseNoEvents() throws Exception { |
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
117 |
System.out.println("testCloseNoEvents()"); |
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
118 |
|
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
119 |
try (Recording r = new Recording()) { |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
120 |
r.start(); |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
121 |
CountDownLatch finished = new CountDownLatch(2); |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
122 |
AtomicReference<Thread> streamingThread = new AtomicReference<>(); |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
123 |
try (EventStream es = EventStream.openRepository()) { |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
124 |
es.setStartTime(Instant.EPOCH); |
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
125 |
es.onFlush(() -> { |
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
126 |
streamingThread.set(Thread.currentThread()); |
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
127 |
finished.countDown(); |
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
128 |
}); |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
129 |
es.startAsync(); |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
130 |
finished.await(); |
59327
2c3578aa0bdf
8234671: JFR api/consumer/recordingstream/TestStart.java failed due to timeout at testStartTwice()
egahlin
parents:
59310
diff
changeset
|
131 |
} // <- Close should terminate thread |
59310
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
132 |
while (streamingThread.get().isAlive()) { |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
133 |
Thread.sleep(10); |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
134 |
} |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
135 |
} |
72f3dd43dd28
8234888: EventStream::close doesn't abort streaming thread
egahlin
parents:
58863
diff
changeset
|
136 |
} |
58863 | 137 |
} |