8042205: javax/management/monitor/*: some tests didn't get all the notifications
authorsjiang
Tue, 16 Sep 2014 09:01:57 +0200
changeset 26623 11289cf5c8fc
parent 26622 e7763eeb5e4d
child 26624 e6383382c939
8042205: javax/management/monitor/*: some tests didn't get all the notifications Reviewed-by: dfuchs
jdk/test/ProblemList.txt
jdk/test/javax/management/monitor/AttributeArbitraryDataTypeTest.java
jdk/test/javax/management/monitor/CounterMonitorTest.java
jdk/test/javax/management/monitor/NonComparableAttributeValueTest.java
jdk/test/javax/management/monitor/ReflectionExceptionTest.java
jdk/test/javax/management/monitor/RuntimeExceptionTest.java
--- a/jdk/test/ProblemList.txt	Tue Sep 16 00:26:58 2014 +0200
+++ b/jdk/test/ProblemList.txt	Tue Sep 16 09:01:57 2014 +0200
@@ -142,13 +142,6 @@
 # 8050115
 javax/management/monitor/GaugeMonitorDeadlockTest.java          generic-all
 
-# 8042205 8057951                                               generic-all
-javax/management/monitor/CounterMonitorTest.java 
-javax/management/monitor/NonComparableAttributeValueTest.java 
-javax/management/monitor/ReflectionExceptionTest.java 
-javax/management/monitor/RuntimeExceptionTest.java
-javax/management/monitor/AttributeArbitraryDataTypeTest.java
-
 ############################################################################
 
 # jdk_math
--- a/jdk/test/javax/management/monitor/AttributeArbitraryDataTypeTest.java	Tue Sep 16 00:26:58 2014 +0200
+++ b/jdk/test/javax/management/monitor/AttributeArbitraryDataTypeTest.java	Tue Sep 16 09:01:57 2014 +0200
@@ -58,9 +58,9 @@
 public class AttributeArbitraryDataTypeTest implements NotificationListener {
 
     // Flag to notify that a message has been received
-    private boolean counterMessageReceived = false;
-    private boolean gaugeMessageReceived = false;
-    private boolean stringMessageReceived = false;
+    private volatile boolean counterMessageReceived = false;
+    private volatile boolean gaugeMessageReceived = false;
+    private volatile boolean stringMessageReceived = false;
 
     // Match enum
     public enum Match { do_not_match_0,
@@ -195,21 +195,33 @@
                      " has reached or exceeded the threshold");
                 echo("\t\tDerived Gauge = " + n.getDerivedGauge());
                 echo("\t\tTrigger = " + n.getTrigger());
-                counterMessageReceived = true;
+
+                synchronized (this) {
+                    counterMessageReceived = true;
+                    notifyAll();
+                }
             } else if (type.equals(MonitorNotification.
                                    THRESHOLD_HIGH_VALUE_EXCEEDED)) {
                 echo("\t\t" + n.getObservedAttribute() +
                      " has reached or exceeded the high threshold");
                 echo("\t\tDerived Gauge = " + n.getDerivedGauge());
                 echo("\t\tTrigger = " + n.getTrigger());
-                gaugeMessageReceived = true;
+
+                synchronized (this) {
+                    gaugeMessageReceived = true;
+                    notifyAll();
+                }
             } else if (type.equals(MonitorNotification.
                                    STRING_TO_COMPARE_VALUE_MATCHED)) {
                 echo("\t\t" + n.getObservedAttribute() +
                      " matches the string-to-compare value");
                 echo("\t\tDerived Gauge = " + n.getDerivedGauge());
                 echo("\t\tTrigger = " + n.getTrigger());
-                stringMessageReceived = true;
+
+                synchronized (this) {
+                    stringMessageReceived = true;
+                    notifyAll();
+                }
             } else {
                 echo("\t\tSkipping notification of type: " + type);
             }
@@ -358,6 +370,17 @@
 
             // Check if notification was received
             //
+            synchronized (this) {
+                while (!counterMessageReceived) {
+                    try {
+                        wait();
+                    } catch (InterruptedException e) {
+                        System.err.println("Got unexpected exception: " + e);
+                        e.printStackTrace();
+                        break;
+                    }
+                }
+            }
             if (counterMessageReceived) {
                 echo("\tOK: CounterMonitor notification received");
             } else {
@@ -525,6 +548,17 @@
 
             // Check if notification was received
             //
+            synchronized (this) {
+                while (!gaugeMessageReceived) {
+                    try {
+                        wait();
+                    } catch (InterruptedException e) {
+                        System.err.println("Got unexpected exception: " + e);
+                        e.printStackTrace();
+                        break;
+                    }
+                }
+            }
             if (gaugeMessageReceived) {
                 echo("\tOK: GaugeMonitor notification received");
             } else {
@@ -680,6 +714,17 @@
 
             // Check if notification was received
             //
+            synchronized (this) {
+                while (!stringMessageReceived) {
+                    try {
+                        wait();
+                    } catch (InterruptedException e) {
+                        System.err.println("Got unexpected exception: " + e);
+                        e.printStackTrace();
+                        break;
+                    }
+                }
+            }
             if (stringMessageReceived) {
                 echo("\tOK: StringMonitor notification received");
             } else {
--- a/jdk/test/javax/management/monitor/CounterMonitorTest.java	Tue Sep 16 00:26:58 2014 +0200
+++ b/jdk/test/javax/management/monitor/CounterMonitorTest.java	Tue Sep 16 09:01:57 2014 +0200
@@ -43,9 +43,6 @@
     // modulus number
     private Number modulus = new Integer(7);
 
-    // offset number
-    private int offset = 0;
-
     // difference mode flag
     private boolean differenceModeFlag = true;
 
@@ -58,9 +55,6 @@
     // counter values
     private int[] values = new int[] {4, 6, 9, 11};
 
-    // time to wait for notification (in seconds)
-    private int timeout = 5;
-
     // flag to notify that a message has been received
     private volatile boolean messageReceived = false;
 
@@ -92,8 +86,9 @@
                 echo("\t\t" + n.getObservedAttribute() +
                      " has reached or exceeded the threshold");
                 echo("\t\tDerived Gauge = " + n.getDerivedGauge());
-                messageReceived = true;
+
                 synchronized (this) {
+                    messageReceived = true;
                     notifyAll();
                 }
             } else {
@@ -205,22 +200,17 @@
     }
 
     /*
-     * Wait until timeout reached
+     * Wait messageReceived to be true
      */
-    void doWait() {
-        for (int i = 0; i < timeout; i++) {
-            echo("\tdoWait: Waiting for " + timeout + " seconds. " +
-                 "i = " + i + ", messageReceived = " + messageReceived);
-            if (messageReceived) {
+    synchronized void doWait() {
+        while (!messageReceived) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                System.err.println("Got unexpected exception: " + e);
+                e.printStackTrace();
                 break;
             }
-            try {
-                synchronized (this) {
-                    wait(1000);
-                }
-            } catch (InterruptedException e) {
-                // OK: Ignore...
-            }
         }
     }
 
--- a/jdk/test/javax/management/monitor/NonComparableAttributeValueTest.java	Tue Sep 16 00:26:58 2014 +0200
+++ b/jdk/test/javax/management/monitor/NonComparableAttributeValueTest.java	Tue Sep 16 09:01:57 2014 +0200
@@ -39,7 +39,7 @@
 public class NonComparableAttributeValueTest implements NotificationListener {
 
     // Flag to notify that a message has been received
-    private boolean messageReceived = false;
+    private volatile boolean messageReceived = false;
 
     // MBean class
     public class ObservedObject implements ObservedObjectMBean {
@@ -69,7 +69,11 @@
                 echo("\t\t" + n.getObservedAttribute() + " is null");
                 echo("\t\tDerived Gauge = " + n.getDerivedGauge());
                 echo("\t\tTrigger = " + n.getTrigger());
-                messageReceived = true;
+
+                synchronized (this) {
+                    messageReceived = true;
+                    notifyAll();
+                }
             } else {
                 echo("\t\tSkipping notification of type: " + type);
             }
@@ -134,12 +138,9 @@
             echo(">>> START the CounterMonitor");
             counterMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: CounterMonitor notification received");
             } else {
@@ -212,12 +213,9 @@
             echo(">>> START the GaugeMonitor");
             gaugeMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: GaugeMonitor notification received");
             } else {
@@ -289,12 +287,9 @@
             echo(">>> START the StringMonitor");
             stringMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: StringMonitor notification received");
             } else {
@@ -334,6 +329,21 @@
     }
 
     /*
+     * Wait messageReceived to be true
+     */
+    synchronized void doWait() {
+        while (!messageReceived) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                System.err.println("Got unexpected exception: " + e);
+                e.printStackTrace();
+                break;
+            }
+        }
+    }
+
+    /*
      * Standalone entry point.
      *
      * Run the test and report to stdout.
--- a/jdk/test/javax/management/monitor/ReflectionExceptionTest.java	Tue Sep 16 00:26:58 2014 +0200
+++ b/jdk/test/javax/management/monitor/ReflectionExceptionTest.java	Tue Sep 16 09:01:57 2014 +0200
@@ -87,7 +87,11 @@
                 echo("\tObservedAttribute: " + mn.getObservedAttribute());
                 echo("\tDerivedGauge: " + mn.getDerivedGauge());
                 echo("\tTrigger: " + mn.getTrigger());
-                messageReceived = true;
+
+                synchronized (this) {
+                    messageReceived = true;
+                    notifyAll();
+                }
             }
         }
     }
@@ -135,12 +139,9 @@
             echo(">>> START the CounterMonitor");
             counterMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
             } else {
@@ -203,12 +204,9 @@
             echo(">>> START the GaugeMonitor");
             gaugeMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
             } else {
@@ -270,12 +268,9 @@
             echo(">>> START the StringMonitor");
             stringMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
             } else {
@@ -349,8 +344,23 @@
         }
     }
 
+    /*
+     * Wait messageReceived to be true
+     */
+    synchronized void doWait() {
+        while (!messageReceived) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                System.err.println("Got unexpected exception: " + e);
+                e.printStackTrace();
+                break;
+            }
+        }
+    }
+
     // Flag to notify that a message has been received
-    private boolean messageReceived = false;
+    private volatile boolean messageReceived = false;
 
     private MBeanServer server;
     private ObjectName obsObjName;
--- a/jdk/test/javax/management/monitor/RuntimeExceptionTest.java	Tue Sep 16 00:26:58 2014 +0200
+++ b/jdk/test/javax/management/monitor/RuntimeExceptionTest.java	Tue Sep 16 09:01:57 2014 +0200
@@ -86,7 +86,11 @@
                 echo("\tObservedAttribute: " + mn.getObservedAttribute());
                 echo("\tDerivedGauge: " + mn.getDerivedGauge());
                 echo("\tTrigger: " + mn.getTrigger());
-                messageReceived = true;
+
+                synchronized (this) {
+                    messageReceived = true;
+                    notifyAll();
+                }
             }
         }
     }
@@ -134,12 +138,9 @@
             echo(">>> START the CounterMonitor");
             counterMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
             } else {
@@ -202,12 +203,9 @@
             echo(">>> START the GaugeMonitor");
             gaugeMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
             } else {
@@ -269,12 +267,9 @@
             echo(">>> START the StringMonitor");
             stringMonitor.start();
 
-            // Wait for granularity period (multiplied by 2 for sure)
-            //
-            Thread.sleep(granularityperiod * 2);
-
             // Check if notification was received
             //
+            doWait();
             if (messageReceived) {
                 echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
             } else {
@@ -347,8 +342,23 @@
         }
     }
 
+    /*
+     * Wait messageReceived to be true
+     */
+    synchronized void doWait() {
+        while (!messageReceived) {
+            try {
+                wait();
+            } catch (InterruptedException e) {
+                System.err.println("Got unexpected exception: " + e);
+                e.printStackTrace();
+                break;
+            }
+        }
+    }
+
     // Flag to notify that a message has been received
-    private boolean messageReceived = false;
+    private volatile boolean messageReceived = false;
 
     private MBeanServer server;
     private ObjectName obsObjName;