author | mseledtsov |
Mon, 23 Sep 2019 09:16:05 -0700 | |
branch | JEP-349-branch |
changeset 58271 | e47423f1318b |
parent 57361 | 53dccc90a5be |
child 58412 | 8a8fd35b6bc6 |
permissions | -rw-r--r-- |
57361 | 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.consumer.RecordingStream; |
|
32 |
||
33 |
/** |
|
34 |
* @test |
|
35 |
* @summary Tests that a stream can gracefully handle chunk being removed |
|
36 |
* @key jfr |
|
37 |
* @requires vm.hasJFR |
|
38 |
* @library /test/lib |
|
58271
e47423f1318b
Test fixes: more logging, typos, fixes to at-run targets
mseledtsov
parents:
57361
diff
changeset
|
39 |
* @run main/othervm jdk.jfr.api.consumer.streaming.TestRemovedChunks |
57361 | 40 |
*/ |
41 |
public class TestRemovedChunks { |
|
42 |
private final static CountDownLatch parkLatch = new CountDownLatch(1); |
|
43 |
private final static CountDownLatch removalLatch = new CountDownLatch(1); |
|
58271
e47423f1318b
Test fixes: more logging, typos, fixes to at-run targets
mseledtsov
parents:
57361
diff
changeset
|
44 |
private final static CountDownLatch IFeelFineLatch = new CountDownLatch(1); |
57361 | 45 |
|
46 |
static class DataEvent extends Event { |
|
47 |
double double1; |
|
48 |
double double2; |
|
49 |
double double3; |
|
50 |
double double4; |
|
51 |
double double5; |
|
52 |
} |
|
53 |
||
54 |
static class ParkStream extends Event { |
|
55 |
} |
|
56 |
||
57 |
static class IFeelFine extends Event { |
|
58 |
} |
|
59 |
||
60 |
public static void main(String... args) throws Exception { |
|
61 |
||
62 |
try (RecordingStream s = new RecordingStream()) { |
|
63 |
s.setMaxSize(20_000_000); |
|
64 |
s.onEvent(ParkStream.class.getName(), e -> { |
|
65 |
parkLatch.countDown(); |
|
66 |
await(removalLatch); |
|
67 |
||
68 |
}); |
|
69 |
s.onEvent(IFeelFine.class.getName(), e -> { |
|
58271
e47423f1318b
Test fixes: more logging, typos, fixes to at-run targets
mseledtsov
parents:
57361
diff
changeset
|
70 |
IFeelFineLatch.countDown(); |
57361 | 71 |
}); |
72 |
s.startAsync(); |
|
73 |
emitData(15_000_000); |
|
74 |
ParkStream ps = new ParkStream(); |
|
75 |
ps.commit(); |
|
76 |
await(parkLatch); |
|
77 |
// Try to force removal of chunk that is being streamed |
|
78 |
emitData(50_000_000); |
|
79 |
removalLatch.countDown(); |
|
80 |
IFeelFine i = new IFeelFine(); |
|
81 |
i.commit(); |
|
58271
e47423f1318b
Test fixes: more logging, typos, fixes to at-run targets
mseledtsov
parents:
57361
diff
changeset
|
82 |
await(IFeelFineLatch); |
57361 | 83 |
} |
84 |
||
85 |
} |
|
86 |
||
87 |
private static void await(CountDownLatch latch) throws Error { |
|
88 |
try { |
|
89 |
latch.await(); |
|
90 |
} catch (InterruptedException e1) { |
|
91 |
throw new Error("Latch interupted"); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
private static void emitData(int amount) throws InterruptedException { |
|
96 |
int count = 0; |
|
97 |
while (amount > 0) { |
|
98 |
DataEvent de = new DataEvent(); |
|
99 |
// 5 doubles are 40 bytes bytes |
|
100 |
// and event size, event type, thread, |
|
101 |
// start time, duration and stack trace about 15 bytes |
|
102 |
de.double1 = 0.0; |
|
103 |
de.double2 = 1.0; |
|
104 |
de.double3 = 2.0; |
|
105 |
de.double4 = 3.0; |
|
106 |
de.double5 = 4.0; |
|
107 |
de.commit(); |
|
108 |
amount -= 55; |
|
109 |
count++; |
|
110 |
// |
|
111 |
if (count % 100_000 == 0) { |
|
112 |
Thread.sleep(10); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
} |