author | egahlin |
Fri, 09 Aug 2019 01:18:18 +0200 | |
branch | JEP-349-branch |
changeset 57690 | 9316d02dd4a5 |
parent 57628 | f5f590eaecf5 |
child 58076 | ca625d28c580 |
permissions | -rw-r--r-- |
57628 | 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.recordingstream; |
|
26 |
||
27 |
import java.time.Duration; |
|
28 |
import java.time.Instant; |
|
29 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
30 |
||
31 |
import jdk.jfr.Event; |
|
32 |
import jdk.jfr.Name; |
|
33 |
import jdk.jfr.Recording; |
|
34 |
import jdk.jfr.StackTrace; |
|
35 |
import jdk.jfr.consumer.EventStream; |
|
36 |
||
37 |
/** |
|
38 |
* @test |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
39 |
* @summary Tests EventStream::setStartTime |
57628 | 40 |
* @key jfr |
41 |
* @requires vm.hasJFR |
|
42 |
* @library /test/lib |
|
43 |
* @run main/othervm jdk.jfr.api.consumer.recordingstream.TestSetStartTime |
|
44 |
*/ |
|
45 |
public final class TestSetStartTime { |
|
46 |
||
47 |
@Name("Mark") |
|
48 |
@StackTrace(false) |
|
49 |
public final static class Mark extends Event { |
|
50 |
public boolean before; |
|
51 |
} |
|
52 |
||
53 |
public static void main(String... args) throws Exception { |
|
54 |
try (Recording r = new Recording()) { |
|
55 |
r.setFlushInterval(Duration.ofSeconds(1)); |
|
56 |
r.start(); |
|
57 |
Mark event1 = new Mark(); |
|
58 |
event1.before = true; |
|
59 |
event1.commit(); |
|
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
60 |
Thread.sleep(2000); |
57628 | 61 |
Instant now = Instant.now(); |
57690
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
62 |
System.out.println("Instant.now() = " + now); |
9316d02dd4a5
Add EventStream::setEndTime(...) and a first stab at priviliged access to local repository
egahlin
parents:
57628
diff
changeset
|
63 |
Thread.sleep(2000); |
57628 | 64 |
Mark event2 = new Mark(); |
65 |
event2.before = false; |
|
66 |
event2.commit(); |
|
67 |
AtomicBoolean error = new AtomicBoolean(); |
|
68 |
try (EventStream d = EventStream.openRepository()) { |
|
69 |
d.setStartTime(now); |
|
70 |
d.onEvent(e -> { |
|
71 |
System.out.println(e); |
|
72 |
boolean early = e.getBoolean("before"); |
|
73 |
if (early) { |
|
74 |
error.set(true); |
|
75 |
} else { |
|
76 |
// OK, as expected |
|
77 |
d.close(); |
|
78 |
} |
|
79 |
}); |
|
80 |
d.start(); |
|
81 |
if (error.get()) { |
|
82 |
throw new Exception("Found unexpected event!"); |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
} |
|
87 |
} |