author | dbuck |
Tue, 18 Aug 2015 04:29:28 -0700 | |
changeset 32417 | 6859107fc6c3 |
parent 30376 | 2ccf2cf7ea48 |
child 44423 | 306c020eb154 |
permissions | -rw-r--r-- |
9690
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
9692
diff
changeset
|
2 |
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
9690
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
4 |
* |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
8 |
* |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
13 |
* accompanied this code). |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
14 |
* |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
18 |
* |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
21 |
* questions. |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
22 |
*/ |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
23 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
24 |
/* |
9692
161f3690d53c
7044203: Missing @test tag in test/javax/management/timer/StartTest.java
kamg
parents:
9690
diff
changeset
|
25 |
* @test |
9690
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
26 |
* @bug 6659215 |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
27 |
* @summary Test on timer start method with past notifications |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
28 |
* @author Shanliang JIANG |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
9692
diff
changeset
|
29 |
* @modules java.management |
9690
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
30 |
* @run clean StartTest |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
31 |
* @run build StartTest |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
32 |
* @run main StartTest |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
33 |
*/ |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
34 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
35 |
import java.util.Date; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
36 |
import javax.management.timer.Timer; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
37 |
import javax.management.Notification; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
38 |
import javax.management.NotificationListener; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
39 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
40 |
public class StartTest { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
42 |
System.out.println( |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
43 |
">>> Test on timer start method with past notifications."); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
44 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
45 |
System.out.println(">>> Create a Timer object."); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
46 |
Timer timer = new Timer(); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
47 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
48 |
System.out.println( |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
49 |
">>> Set the flag (setSendPastNotification) to true."); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
50 |
timer.setSendPastNotifications(true); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
51 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
52 |
timer.addNotificationListener(myListener, null, null); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
53 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
54 |
System.out.println(">>> Add notifications: " + SENT); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
55 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
56 |
Date date = new Date(); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
57 |
for (int i = 0; i < SENT; i++) { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
58 |
timer.addNotification( |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
59 |
"testType" + i, "testMsg" + i, "testData" + i, date); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
60 |
} |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
61 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
62 |
System.out.println(">>> The notifications should be sent at " + date); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
63 |
System.out.println(">>> Sleep 100 ms to have past notifications."); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
64 |
Thread.sleep(100); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
65 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
66 |
System.out.println(">>> Start the timer at " + new Date()); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
67 |
timer.start(); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
68 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
69 |
System.out.println(">>> Stop the timer."); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
70 |
Thread.sleep(100); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
71 |
stopping = true; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
72 |
timer.stop(); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
73 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
74 |
if (received != SENT) { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
75 |
throw new RuntimeException( |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
76 |
"Expected to receive " + SENT + " but got " + received); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
77 |
} |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
78 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
79 |
System.out.println(">>> Received all expected notifications."); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
80 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
81 |
System.out.println(">>> Bye bye!"); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
82 |
} |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
83 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
84 |
private static NotificationListener myListener = |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
85 |
new NotificationListener() { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
86 |
public void handleNotification(Notification n, Object hb) { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
87 |
if (!stopping) { |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
88 |
received++; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
89 |
System.out.println( |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
90 |
">>> myListener-handleNotification: received " + |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
91 |
n.getSequenceNumber()); |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
92 |
} |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
93 |
} |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
94 |
}; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
95 |
|
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
96 |
private static int SENT = 10; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
97 |
private static volatile int received = 0; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
98 |
private static volatile boolean stopping = false; |
5f9ce93ee91c
6659215: javax.management.timer.Timer frequently fails to start
kamg
parents:
diff
changeset
|
99 |
} |