|
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.streaming; |
|
26 |
|
27 import java.time.Duration; |
|
28 import java.time.Instant; |
|
29 import java.util.concurrent.atomic.AtomicInteger; |
|
30 |
|
31 import jdk.jfr.consumer.EventStream; |
|
32 |
|
33 /** |
|
34 * @test |
|
35 * @summary Test that a stream ends/closes when an application crashes. |
|
36 * @key jfr |
|
37 * @requires vm.hasJFR |
|
38 * @library /test/lib /test/jdk |
|
39 * @modules jdk.jfr jdk.attach java.base/jdk.internal.misc |
|
40 * |
|
41 * @run main/othervm jdk.jfr.api.consumer.streaming.TestJVMCrash |
|
42 */ |
|
43 public class TestJVMCrash { |
|
44 |
|
45 public static void main(String... args) throws Exception { |
|
46 int id = 1; |
|
47 while (true) { |
|
48 TestProcess process = new TestProcess("crash-application-" + id++); |
|
49 AtomicInteger eventCounter = new AtomicInteger(); |
|
50 try (EventStream es = EventStream.openRepository(process.getRepository())) { |
|
51 // Start from first event in repository |
|
52 es.setStartTime(Instant.EPOCH); |
|
53 es.onEvent(e -> { |
|
54 if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) { |
|
55 process.crash(); |
|
56 } |
|
57 }); |
|
58 es.startAsync(); |
|
59 // If crash corrupts chunk in repository, retry in 30 seconds |
|
60 es.awaitTermination(Duration.ofSeconds(30)); |
|
61 if (eventCounter.get() == TestProcess.NUMBER_OF_EVENTS) { |
|
62 return; |
|
63 } |
|
64 System.out.println("Incorrect event count. Retrying..."); |
|
65 } |
|
66 } |
|
67 } |
|
68 } |