/*
* 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 6273541
* jmx.monitor.error.type notification when the attribute
* being monitored returns a non comparable value.
* @author Luis-Miguel Alventosa
* @run clean NonComparableAttributeValueTest
* @run build NonComparableAttributeValueTest
* @run main NonComparableAttributeValueTest
*/
import javax.management.*;
// Flag to notify that a message has been received
private boolean messageReceived = false;
// MBean class
return new Object();
}
return new Object();
}
}
// MBean interface
public interface ObservedObjectMBean {
}
// Notification handler
echo("\tInside handleNotification...");
try {
messageReceived = true;
} else {
}
} catch (Exception e) {
echo("\tError in handleNotification!");
}
}
/**
* 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");
counterMonitor = new CounterMonitor();
echo(">>> ADD a listener to the CounterMonitor");
//
// MANAGEMENT OF A STANDARD MBEAN
//
echo(">>> CREATE a new ObservedObject MBean");
echo(">>> SET the attributes of the CounterMonitor:");
echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");
counterMonitor.setNotify(true);
echo("\tATTRIBUTE \"NotifyFlag\" = true");
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 notification received");
} else {
echo("\tKO: CounterMonitor notification missed or not emitted");
return 1;
}
} finally {
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");
gaugeMonitor = new GaugeMonitor();
echo(">>> ADD a listener to the GaugeMonitor");
//
// MANAGEMENT OF A STANDARD MBEAN
//
echo(">>> CREATE a new ObservedObject MBean");
echo(">>> SET the attributes of the GaugeMonitor:");
echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");
gaugeMonitor.setNotifyLow(false);
gaugeMonitor.setNotifyHigh(true);
echo("\tATTRIBUTE \"Notify Low Flag\" = false");
echo("\tATTRIBUTE \"Notify High Flag\" = true");
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 notification received");
} else {
echo("\tKO: GaugeMonitor notification missed or not emitted");
return 1;
}
} finally {
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");
stringMonitor = new StringMonitor();
echo(">>> ADD a listener to the StringMonitor");
//
// MANAGEMENT OF A STANDARD MBEAN
//
echo(">>> CREATE a new ObservedObject MBean");
echo(">>> SET the attributes of the StringMonitor:");
echo("\tATTRIBUTE \"ObservedAttribute\" = StringAttribute");
stringMonitor.setNotifyMatch(true);
echo("\tATTRIBUTE \"NotifyMatch\" = true");
stringMonitor.setNotifyDiffer(false);
echo("\tATTRIBUTE \"NotifyDiffer\" = false");
echo("\tATTRIBUTE \"StringToCompare\" = \"do_match_now\"");
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 notification received");
} else {
echo("\tKO: StringMonitor notification missed or not emitted");
return 1;
}
} finally {
if (stringMonitor != null)
}
return 0;
}
/**
* Test the monitor notifications.
*/
echo(">>> ----------------------------------------");
messageReceived = false;
int error = counterMonitorNotification();
echo(">>> ----------------------------------------");
messageReceived = false;
echo(">>> ----------------------------------------");
messageReceived = false;
echo(">>> ----------------------------------------");
return error;
}
/*
* Print message
*/
}
/*
* Standalone entry point.
*
* Run the test and report to stdout.
*/
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!");
}
}
}