author | egahlin |
Wed, 02 Oct 2019 19:26:33 +0200 | |
branch | JEP-349-branch |
changeset 58445 | 1893a674db04 |
child 58472 | d345ae0fddc4 |
permissions | -rw-r--r-- |
58445
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
1 |
/* |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
4 |
* |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
10 |
* |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
15 |
* accompanied this code). |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
16 |
* |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
20 |
* |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
23 |
* questions. |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
24 |
*/ |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
25 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
26 |
package jdk.jfr.api.consumer.recordingstream; |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
27 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
28 |
import java.util.concurrent.CountDownLatch; |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
29 |
import java.util.concurrent.atomic.AtomicBoolean; |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
30 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
31 |
import jdk.jfr.Event; |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
32 |
import jdk.jfr.consumer.RecordingStream; |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
33 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
34 |
/** |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
35 |
* @test |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
36 |
* @summary Tests that events are not emitted in handlers |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
37 |
* @key jfr |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
38 |
* @requires vm.hasJFR |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
39 |
* @library /test/lib |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
40 |
* @run main/othervm jdk.jfr.api.consumer.recordingstream.TestRecursive |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
41 |
*/ |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
42 |
public class TestRecursive { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
43 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
44 |
static class NotRecorded extends Event { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
45 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
46 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
47 |
static class Recorded extends Event { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
48 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
49 |
|
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
50 |
public static void main(String... args) throws Exception { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
51 |
CountDownLatch latchOne = new CountDownLatch(1); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
52 |
CountDownLatch latchTwo = new CountDownLatch(2); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
53 |
AtomicBoolean fail = new AtomicBoolean(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
54 |
try (RecordingStream r = new RecordingStream()) { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
55 |
r.onEvent(e -> { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
56 |
System.out.println(e); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
57 |
NotRecorded event = new NotRecorded(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
58 |
event.commit(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
59 |
if (e.getEventType().getName().equals(Recorded.class.getName())) { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
60 |
latchOne.countDown(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
61 |
latchTwo.countDown(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
62 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
63 |
if (e.getEventType().getName().equals(NotRecorded.class.getName())) { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
64 |
fail.set(true); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
65 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
66 |
}); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
67 |
r.startAsync(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
68 |
Recorded e1 = new Recorded(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
69 |
e1.commit(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
70 |
latchOne.await(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
71 |
Recorded e2 = new Recorded(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
72 |
e2.commit(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
73 |
latchTwo.await(); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
74 |
if (fail.get()) { |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
75 |
throw new Exception("Unexpected event found"); |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
76 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
77 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
78 |
} |
1893a674db04
Add TestRecusrive and only skip events for DirectoryStream
egahlin
parents:
diff
changeset
|
79 |
} |