/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6200391
* @summary Test that the jmx.monitor.error.runtime monitor notification
* is emitted when getAttribute throws RuntimeException.
* @author Luis-Miguel Alventosa
* @run clean RuntimeExceptionTest MBeanServerBuilderImpl
* MBeanServerForwarderInvocationHandler
* @run build RuntimeExceptionTest MBeanServerBuilderImpl
* MBeanServerForwarderInvocationHandler
* @run main RuntimeExceptionTest
*/
// MBean class
return i;
}
this.i = i;
}
return s;
}
this.s = s;
}
private Integer i = 1;
private String s = "dummy";
}
// MBean interface
public interface ObservedObjectMBean {
}
// Notification handler
if (notification instanceof MonitorNotification) {
messageReceived = true;
}
}
}
/**
* Update the counter and check for notifications
*/
try {
// Create a new CounterMonitor MBean and add it to the MBeanServer.
//
echo(">>> CREATE a new CounterMonitor MBean");
echo(">>> ADD a listener to the CounterMonitor");
//
// MANAGEMENT OF A STANDARD MBEAN
//
echo(">>> SET the attributes of the CounterMonitor:");
echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");
counterMonitor.setNotify(false);
echo("\tATTRIBUTE \"NotifyFlag\" = false");
int granularityperiod = 500;
echo(">>> START the CounterMonitor");
// Wait for granularity period (multiplied by 2 for sure)
//
// Check if notification was received
//
if (messageReceived) {
echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: CounterMonitor did not get " +
"RUNTIME_ERROR notification!");
return 1;
}
} finally {
messageReceived = false;
if (counterMonitor != null)
}
return 0;
}
/**
* Update the gauge and check for notifications
*/
try {
// Create a new GaugeMonitor MBean and add it to the MBeanServer.
//
echo(">>> CREATE a new GaugeMonitor MBean");
echo(">>> ADD a listener to the GaugeMonitor");
//
// MANAGEMENT OF A STANDARD MBEAN
//
echo(">>> SET the attributes of the GaugeMonitor:");
echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");
gaugeMonitor.setNotifyLow(false);
gaugeMonitor.setNotifyHigh(false);
echo("\tATTRIBUTE \"Notify Low Flag\" = false");
echo("\tATTRIBUTE \"Notify High Flag\" = false");
int granularityperiod = 500;
echo(">>> START the GaugeMonitor");
// Wait for granularity period (multiplied by 2 for sure)
//
// Check if notification was received
//
if (messageReceived) {
echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: GaugeMonitor did not get " +
"RUNTIME_ERROR notification!");
return 1;
}
} finally {
messageReceived = false;
if (gaugeMonitor != null)
gaugeMonitor.stop();
}
return 0;
}
/**
* Update the string and check for notifications
*/
try {
// Create a new StringMonitor MBean and add it to the MBeanServer.
//
echo(">>> CREATE a new StringMonitor MBean");
echo(">>> ADD a listener to the StringMonitor");
//
// MANAGEMENT OF A STANDARD MBEAN
//
echo(">>> SET the attributes of the StringMonitor:");
echo("\tATTRIBUTE \"ObservedAttribute\" = StringAttribute");
stringMonitor.setNotifyMatch(false);
echo("\tATTRIBUTE \"NotifyMatch\" = false");
stringMonitor.setNotifyDiffer(false);
echo("\tATTRIBUTE \"NotifyDiffer\" = false");
echo("\tATTRIBUTE \"StringToCompare\" = \"dummy\"");
int granularityperiod = 500;
echo(">>> START the StringMonitor");
// Wait for granularity period (multiplied by 2 for sure)
//
// Check if notification was received
//
if (messageReceived) {
echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: StringMonitor did not get " +
"RUNTIME_ERROR notification!");
return 1;
}
} finally {
messageReceived = false;
if (stringMonitor != null)
}
return 0;
}
/**
* Test the monitor notifications.
*/
new RuntimeException("Test RuntimeException"));
echo(">>> ----------------------------------------");
int error = counterMonitorNotification();
echo(">>> ----------------------------------------");
echo(">>> ----------------------------------------");
echo(">>> ----------------------------------------");
return error;
}
/*
* Print message
*/
}
/*
* Standalone entry point.
*
* Run the test and report to stdout.
*/
MBeanServerBuilderImpl.class.getName());
if (error > 0) {
echo(">>> Unhappy Bye, Bye!");
throw new IllegalStateException("Test FAILED: Didn't get all " +
"the notifications that were " +
"expected by the test!");
} else {
echo(">>> Happy Bye, Bye!");
}
}
// Flag to notify that a message has been received
private boolean messageReceived = false;
}