Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/timer/StartTest.java
38839 views
1
/*
2
* Copyright (c) 2008, 2011, 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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6659215
27
* @summary Test on timer start method with past notifications
28
* @author Shanliang JIANG
29
* @run clean StartTest
30
* @run build StartTest
31
* @run main StartTest
32
*/
33
34
import java.util.Date;
35
import javax.management.timer.Timer;
36
import javax.management.Notification;
37
import javax.management.NotificationListener;
38
39
public class StartTest {
40
public static void main(String[] args) throws Exception {
41
System.out.println(
42
">>> Test on timer start method with past notifications.");
43
44
System.out.println(">>> Create a Timer object.");
45
Timer timer = new Timer();
46
47
System.out.println(
48
">>> Set the flag (setSendPastNotification) to true.");
49
timer.setSendPastNotifications(true);
50
51
timer.addNotificationListener(myListener, null, null);
52
53
System.out.println(">>> Add notifications: " + SENT);
54
55
Date date = new Date();
56
for (int i = 0; i < SENT; i++) {
57
timer.addNotification(
58
"testType" + i, "testMsg" + i, "testData" + i, date);
59
}
60
61
System.out.println(">>> The notifications should be sent at " + date);
62
System.out.println(">>> Sleep 100 ms to have past notifications.");
63
Thread.sleep(100);
64
65
System.out.println(">>> Start the timer at " + new Date());
66
timer.start();
67
68
System.out.println(">>> Stop the timer.");
69
Thread.sleep(100);
70
stopping = true;
71
timer.stop();
72
73
if (received != SENT) {
74
throw new RuntimeException(
75
"Expected to receive " + SENT + " but got " + received);
76
}
77
78
System.out.println(">>> Received all expected notifications.");
79
80
System.out.println(">>> Bye bye!");
81
}
82
83
private static NotificationListener myListener =
84
new NotificationListener() {
85
public void handleNotification(Notification n, Object hb) {
86
if (!stopping) {
87
received++;
88
System.out.println(
89
">>> myListener-handleNotification: received " +
90
n.getSequenceNumber());
91
}
92
}
93
};
94
95
private static int SENT = 10;
96
private static volatile int received = 0;
97
private static volatile boolean stopping = false;
98
}
99
100