use of org.openj9.test.management.util.ChildWatchdog in project openj9 by eclipse.
the class GuestOSMXBeanTest method runGuestOSMXBeanTest.
/**
* Starting point for the test program. Invokes the memory and processor test routines and
* indicates success or failure accordingly.
*
* @param args
*/
@Test
public static void runGuestOSMXBeanTest() {
int retryCounter = 0;
boolean localTest = true;
boolean isConnected = false;
boolean error = false;
JMXServiceURL urlForRemoteMachine = null;
JMXConnector connector = null;
MBeanServerConnection mbeanConnection = null;
MBeanServer mbeanServer = null;
ObjectName mxbeanName = null;
GuestOSMXBean mxbeanProxy = null;
logger.info(" ---------------------------------------");
logger.info(" Starting the GuestOSMXBean API tests....");
logger.info(" ---------------------------------------");
/* Check and set flag 'localTest'. If the user specified 'local' or nothing, select local testing,
* while under explicit specification of the option 'remote' do we platform remote testing.
*/
if (System.getProperty("RUNLOCAL").equalsIgnoreCase("false")) {
localTest = false;
} else if (!System.getProperty("RUNLOCAL").equalsIgnoreCase("true")) {
/* Failed parsing a sensible option specified by the user. */
logger.error("GuestOSMXBeanTest usage:");
logger.error(" -DRUNLOCAL=[false, true] $GuestOSMXBeanTest");
logger.error("Valid options are 'true' and 'false'.");
logger.error("In absence of a specified option, test defaults to local.");
Assert.fail("Invalid property");
}
/* We need the object name in any case - remote as well as local. */
try {
mxbeanName = new ObjectName("com.ibm.virtualization.management:type=GuestOS");
} catch (MalformedObjectNameException e) {
Assert.fail("MalformedObjectNameException!", e);
}
/* Perform the appropriate test as instructed through the command line. */
if (false == localTest) {
/* A remote test needs to be performed. Start the remote server if it is not running yet.
* Also, attach a watch dog to this, to bail out, in case it hangs.
*/
if (null == remoteServer) {
startRemoteServer();
watchdog = new ChildWatchdog(remoteServer, 30000);
}
/* Try connecting to the server; retry until limit reached. */
while (retryCounter < 10 && !isConnected) {
retryCounter++;
try {
urlForRemoteMachine = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
/* Connect to remote host and create a proxy to be used to get an GuestOSMXBean
* instance.
*/
connector = JMXConnectorFactory.connect(urlForRemoteMachine, null);
mbeanConnection = connector.getMBeanServerConnection();
/* Obtain an MBean handle using the connection and the
* object name for the class GuestOSMXBean.
*/
mxbeanProxy = JMX.newMXBeanProxy(mbeanConnection, mxbeanName, GuestOSMXBean.class);
if (true != mbeanConnection.isRegistered(mxbeanName)) {
Assert.fail("GuestOSMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
/* If we reached here, it means we are connected (no connection failure exception thrown). */
isConnected = true;
} catch (MalformedURLException e) {
Assert.fail("Please check the url supplied to JMXServiceURL!", e);
} catch (IOException e) {
/* Waiting 1000 ms before retrying to connect to remote server. */
logger.warn("Failed connecting. Retry " + retryCounter + " after 1000 ms.");
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
logger.warn("Exception occurred while sleeping thread: " + ie.getMessage(), e);
}
} catch (Exception e) {
Assert.fail("Exception occurred in setting up remote test environment.");
}
if (!isConnected) {
Assert.fail("Unable to connect to Remote Server. !!!Test Failed !!!");
}
}
} else {
/*
* A local test has been requested.
*/
try {
mbeanServer = ManagementFactory.getPlatformMBeanServer();
if (true != mbeanServer.isRegistered(mxbeanName)) {
Assert.fail("GuestOSMXBean is not registered. Cannot Proceed with the test.");
}
mxbeanProxy = JMX.newMXBeanProxy(mbeanServer, mxbeanName, GuestOSMXBean.class);
} catch (Exception e) {
Assert.fail("Exception occurred in setting up local test environment." + e.getMessage(), e);
}
}
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
HypervisorMXBean bean = ManagementFactory.getPlatformMXBean(mbs, HypervisorMXBean.class);
HypervisorName = bean.getVendor();
if (null == HypervisorName) {
HypervisorName = "none";
}
} catch (Exception e) {
Assert.fail("Unexpected exception occured" + e.getMessage(), e);
}
try {
error |= test_memoryInfo(mxbeanProxy);
error |= test_processorInfo(mxbeanProxy);
} finally {
/* Do all clean up here. */
if (false == localTest) {
/* Close the connection and Stop the remote Server */
try {
connector.close();
stopRemoteServer();
} catch (Exception e) {
Assert.fail("Unexpected exception occured when close connector" + e.getMessage(), e);
}
}
}
if (false != error) {
Assert.fail(" !!!Test Failed !!!");
}
}
use of org.openj9.test.management.util.ChildWatchdog in project openj9 by eclipse-openj9.
the class GuestOSMXBeanTest method runGuestOSMXBeanTest.
/**
* Starting point for the test program. Invokes the memory and processor test routines and
* indicates success or failure accordingly.
*
* @param args
*/
@Test
public static void runGuestOSMXBeanTest() {
int retryCounter = 0;
boolean localTest = true;
boolean isConnected = false;
boolean error = false;
JMXServiceURL urlForRemoteMachine = null;
JMXConnector connector = null;
MBeanServerConnection mbeanConnection = null;
MBeanServer mbeanServer = null;
ObjectName mxbeanName = null;
GuestOSMXBean mxbeanProxy = null;
logger.info(" ---------------------------------------");
logger.info(" Starting the GuestOSMXBean API tests....");
logger.info(" ---------------------------------------");
/* Check and set flag 'localTest'. If the user specified 'local' or nothing, select local testing,
* while under explicit specification of the option 'remote' do we platform remote testing.
*/
if (System.getProperty("RUNLOCAL").equalsIgnoreCase("false")) {
localTest = false;
} else if (!System.getProperty("RUNLOCAL").equalsIgnoreCase("true")) {
/* Failed parsing a sensible option specified by the user. */
logger.error("GuestOSMXBeanTest usage:");
logger.error(" -DRUNLOCAL=[false, true] $GuestOSMXBeanTest");
logger.error("Valid options are 'true' and 'false'.");
logger.error("In absence of a specified option, test defaults to local.");
Assert.fail("Invalid property");
}
/* We need the object name in any case - remote as well as local. */
try {
mxbeanName = new ObjectName("com.ibm.virtualization.management:type=GuestOS");
} catch (MalformedObjectNameException e) {
Assert.fail("MalformedObjectNameException!", e);
}
/* Perform the appropriate test as instructed through the command line. */
if (false == localTest) {
/* A remote test needs to be performed. Start the remote server if it is not running yet.
* Also, attach a watch dog to this, to bail out, in case it hangs.
*/
if (null == remoteServer) {
startRemoteServer();
watchdog = new ChildWatchdog(remoteServer, 30000);
}
/* Try connecting to the server; retry until limit reached. */
while (retryCounter < 10 && !isConnected) {
retryCounter++;
try {
urlForRemoteMachine = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
/* Connect to remote host and create a proxy to be used to get an GuestOSMXBean
* instance.
*/
connector = JMXConnectorFactory.connect(urlForRemoteMachine, null);
mbeanConnection = connector.getMBeanServerConnection();
/* Obtain an MBean handle using the connection and the
* object name for the class GuestOSMXBean.
*/
mxbeanProxy = JMX.newMXBeanProxy(mbeanConnection, mxbeanName, GuestOSMXBean.class);
if (true != mbeanConnection.isRegistered(mxbeanName)) {
Assert.fail("GuestOSMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
/* If we reached here, it means we are connected (no connection failure exception thrown). */
isConnected = true;
} catch (MalformedURLException e) {
Assert.fail("Please check the url supplied to JMXServiceURL!", e);
} catch (IOException e) {
/* Waiting 1000 ms before retrying to connect to remote server. */
logger.warn("Failed connecting. Retry " + retryCounter + " after 1000 ms.");
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
logger.warn("Exception occurred while sleeping thread: " + ie.getMessage(), e);
}
} catch (Exception e) {
Assert.fail("Exception occurred in setting up remote test environment.");
}
if (!isConnected) {
Assert.fail("Unable to connect to Remote Server. !!!Test Failed !!!");
}
}
} else {
/*
* A local test has been requested.
*/
try {
mbeanServer = ManagementFactory.getPlatformMBeanServer();
if (true != mbeanServer.isRegistered(mxbeanName)) {
Assert.fail("GuestOSMXBean is not registered. Cannot Proceed with the test.");
}
mxbeanProxy = JMX.newMXBeanProxy(mbeanServer, mxbeanName, GuestOSMXBean.class);
} catch (Exception e) {
Assert.fail("Exception occurred in setting up local test environment." + e.getMessage(), e);
}
}
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
HypervisorMXBean bean = ManagementFactory.getPlatformMXBean(mbs, HypervisorMXBean.class);
HypervisorName = bean.getVendor();
if (null == HypervisorName) {
HypervisorName = "none";
}
} catch (Exception e) {
Assert.fail("Unexpected exception occured" + e.getMessage(), e);
}
try {
error |= test_memoryInfo(mxbeanProxy);
error |= test_processorInfo(mxbeanProxy);
} finally {
/* Do all clean up here. */
if (false == localTest) {
/* Close the connection and Stop the remote Server */
try {
connector.close();
stopRemoteServer();
} catch (Exception e) {
Assert.fail("Unexpected exception occured when close connector" + e.getMessage(), e);
}
}
}
if (false != error) {
Assert.fail(" !!!Test Failed !!!");
}
}
use of org.openj9.test.management.util.ChildWatchdog in project openj9 by eclipse-openj9.
the class TestSetCategory method runJvmCpuMonitorMXBeanTest.
/**
* Starting point for the test program. Invokes the memory and processor test routines and
* indicates success or failure accordingly.
*
* @param args
*/
@Test
public void runJvmCpuMonitorMXBeanTest() throws IOException {
int retryCounter = 0;
boolean localTest = true;
boolean isConnected = false;
boolean error = false;
JMXServiceURL urlForRemoteMachine = null;
JMXConnector connector = null;
MBeanServerConnection mbeanConnection = null;
MBeanServer mbeanServer = null;
ObjectName jcmObjN = null;
ObjectName thdObjN = null;
ThreadMXBean thdmxbean = null;
JvmCpuMonitorMXBean jcmmxbean = null;
logger.info(" ------------------------------------------");
logger.info(" Starting JvmCpuMonitorMXBean API tests....");
logger.info(" ------------------------------------------");
/* Check and set flag 'localTest'. If the user specified 'local' or nothing, select local testing,
* while under explicit specification of the option 'remote' do we platform remote testing.
*/
if (System.getProperty("RUNLOCAL").equalsIgnoreCase("false")) {
localTest = false;
} else if (!System.getProperty("RUNLOCAL").equalsIgnoreCase("true")) {
/* Failed parsing a sensible option specified by the user. */
logger.error("JvmCpuMonitorMXBeanTest usage:");
logger.error(" -DRUNLOCAL=[false, true] $JvmCpuMonitorMXBeanTest");
logger.error("Valid options are 'true' and 'false'.");
logger.error("In absence of a specified option, test defaults to local.");
Assert.fail("Invalid property");
}
/* We need the object name in any case - remote as well as local. */
try {
thdObjN = new ObjectName("java.lang:type=Threading");
jcmObjN = new ObjectName("com.ibm.lang.management:type=JvmCpuMonitor");
} catch (MalformedObjectNameException e) {
Assert.fail("MalformedObjectNameException!", e);
}
/* Perform the appropriate test as instructed through the command line. */
if (!localTest) {
/* A remote test needs to be performed. Start the remote server if it is not running yet.
* Also, attach a watch dog to this, to bail out, in case it hangs.
*/
if (null == remoteMonitor) {
startRemoteMonitor();
watchdog = new ChildWatchdog(remoteMonitor, 30000);
}
/* Try connecting to the server; retry until limit reached. */
while (retryCounter < 10 && !isConnected) {
retryCounter++;
try {
urlForRemoteMachine = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
/* Connect to remote host and create a proxy to be used to get an JvmCpuMonitorMXBean
* instance.
*/
connector = JMXConnectorFactory.connect(urlForRemoteMachine, null);
mbeanConnection = connector.getMBeanServerConnection();
thdmxbean = JMX.newMXBeanProxy(mbeanConnection, thdObjN, ThreadMXBean.class);
if (true != mbeanConnection.isRegistered(jcmObjN)) {
Assert.fail("ThreadMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
/* Obtain an MBean handle using the connection and the
* object name for the class JvmCpuMonitorMXBean.
*/
jcmmxbean = JMX.newMXBeanProxy(mbeanConnection, jcmObjN, JvmCpuMonitorMXBean.class);
if (true != mbeanConnection.isRegistered(jcmObjN)) {
Assert.fail("JvmCpuMonitorMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
/* If we reached here, it means we are connected (no connection failure exception thrown). */
isConnected = true;
} catch (MalformedURLException e) {
Assert.fail("Please check the url supplied to JMXServiceURL!", e);
} catch (IOException e) {
/* Waiting 1000 ms before retrying to connect to remote server. */
logger.warn("Failed connecting. Retry " + retryCounter + " after 1000 ms.");
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
logger.warn("InterruptedException occurred while sleeping thread: " + ie.getMessage(), ie);
}
} catch (Exception e) {
Assert.fail("Exception occurred in setting up remote test environment.");
}
}
if (!isConnected) {
Assert.fail("Unable to connect to Remote Server. !!!Test Failed !!!");
}
} else {
/*
* A local test has been requested.
*/
try {
thdmxbean = ManagementFactory.getThreadMXBean();
mbeanServer = ManagementFactory.getPlatformMBeanServer();
if (true != mbeanServer.isRegistered(jcmObjN)) {
Assert.fail("JvmCpuMonitorMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
jcmmxbean = JMX.newMXBeanProxy(mbeanServer, jcmObjN, JvmCpuMonitorMXBean.class);
} catch (Exception e) {
Assert.fail("Exception occurred in setting up local test environment.", e);
}
}
try {
logger.info("Testing setCategory...");
error |= test_setThreadCategory(thdmxbean, jcmmxbean, localTest);
logger.info("Testing getThreadsCpuUsage...");
error |= test_getThreadsCpuUsage(thdmxbean, jcmmxbean, localTest);
} finally {
/* Do all clean up here. */
if (!localTest) {
/* Close the connection and Stop the remote Server */
try {
connector.close();
lock.notifyEvent("closed JMX connection");
} catch (Exception e) {
logger.error("Exception occurred while closing remote connection.", e);
}
/* Destroy the remote monitor process, if this hasn't exited already. */
stopRemoteMonitor();
}
}
if (error) {
Assert.fail(" !!!Test Failed !!!");
}
}
use of org.openj9.test.management.util.ChildWatchdog in project openj9 by eclipse.
the class TestSetCategory method runJvmCpuMonitorMXBeanTest.
/**
* Starting point for the test program. Invokes the memory and processor test routines and
* indicates success or failure accordingly.
*
* @param args
*/
@Test
public void runJvmCpuMonitorMXBeanTest() throws IOException {
int retryCounter = 0;
boolean localTest = true;
boolean isConnected = false;
boolean error = false;
JMXServiceURL urlForRemoteMachine = null;
JMXConnector connector = null;
MBeanServerConnection mbeanConnection = null;
MBeanServer mbeanServer = null;
ObjectName jcmObjN = null;
ObjectName thdObjN = null;
ThreadMXBean thdmxbean = null;
JvmCpuMonitorMXBean jcmmxbean = null;
logger.info(" ------------------------------------------");
logger.info(" Starting JvmCpuMonitorMXBean API tests....");
logger.info(" ------------------------------------------");
/* Check and set flag 'localTest'. If the user specified 'local' or nothing, select local testing,
* while under explicit specification of the option 'remote' do we platform remote testing.
*/
if (System.getProperty("RUNLOCAL").equalsIgnoreCase("false")) {
localTest = false;
} else if (!System.getProperty("RUNLOCAL").equalsIgnoreCase("true")) {
/* Failed parsing a sensible option specified by the user. */
logger.error("JvmCpuMonitorMXBeanTest usage:");
logger.error(" -DRUNLOCAL=[false, true] $JvmCpuMonitorMXBeanTest");
logger.error("Valid options are 'true' and 'false'.");
logger.error("In absence of a specified option, test defaults to local.");
Assert.fail("Invalid property");
}
/* We need the object name in any case - remote as well as local. */
try {
thdObjN = new ObjectName("java.lang:type=Threading");
jcmObjN = new ObjectName("com.ibm.lang.management:type=JvmCpuMonitor");
} catch (MalformedObjectNameException e) {
Assert.fail("MalformedObjectNameException!", e);
}
/* Perform the appropriate test as instructed through the command line. */
if (!localTest) {
/* A remote test needs to be performed. Start the remote server if it is not running yet.
* Also, attach a watch dog to this, to bail out, in case it hangs.
*/
if (null == remoteMonitor) {
startRemoteMonitor();
watchdog = new ChildWatchdog(remoteMonitor, 30000);
}
/* Try connecting to the server; retry until limit reached. */
while (retryCounter < 10 && !isConnected) {
retryCounter++;
try {
urlForRemoteMachine = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
/* Connect to remote host and create a proxy to be used to get an JvmCpuMonitorMXBean
* instance.
*/
connector = JMXConnectorFactory.connect(urlForRemoteMachine, null);
mbeanConnection = connector.getMBeanServerConnection();
thdmxbean = JMX.newMXBeanProxy(mbeanConnection, thdObjN, ThreadMXBean.class);
if (true != mbeanConnection.isRegistered(jcmObjN)) {
Assert.fail("ThreadMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
/* Obtain an MBean handle using the connection and the
* object name for the class JvmCpuMonitorMXBean.
*/
jcmmxbean = JMX.newMXBeanProxy(mbeanConnection, jcmObjN, JvmCpuMonitorMXBean.class);
if (true != mbeanConnection.isRegistered(jcmObjN)) {
Assert.fail("JvmCpuMonitorMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
/* If we reached here, it means we are connected (no connection failure exception thrown). */
isConnected = true;
} catch (MalformedURLException e) {
Assert.fail("Please check the url supplied to JMXServiceURL!", e);
} catch (IOException e) {
/* Waiting 1000 ms before retrying to connect to remote server. */
logger.warn("Failed connecting. Retry " + retryCounter + " after 1000 ms.");
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
logger.warn("InterruptedException occurred while sleeping thread: " + ie.getMessage(), ie);
}
} catch (Exception e) {
Assert.fail("Exception occurred in setting up remote test environment.");
}
}
if (!isConnected) {
Assert.fail("Unable to connect to Remote Server. !!!Test Failed !!!");
}
} else {
/*
* A local test has been requested.
*/
try {
thdmxbean = ManagementFactory.getThreadMXBean();
mbeanServer = ManagementFactory.getPlatformMBeanServer();
if (true != mbeanServer.isRegistered(jcmObjN)) {
Assert.fail("JvmCpuMonitorMXBean is not registered. Cannot Proceed with the test. !!!Test Failed !!!");
}
jcmmxbean = JMX.newMXBeanProxy(mbeanServer, jcmObjN, JvmCpuMonitorMXBean.class);
} catch (Exception e) {
Assert.fail("Exception occurred in setting up local test environment.", e);
}
}
try {
logger.info("Testing setCategory...");
error |= test_setThreadCategory(thdmxbean, jcmmxbean, localTest);
logger.info("Testing getThreadsCpuUsage...");
error |= test_getThreadsCpuUsage(thdmxbean, jcmmxbean, localTest);
} finally {
/* Do all clean up here. */
if (!localTest) {
/* Close the connection and Stop the remote Server */
try {
connector.close();
lock.notifyEvent("closed JMX connection");
} catch (Exception e) {
logger.error("Exception occurred while closing remote connection.", e);
}
/* Destroy the remote monitor process, if this hasn't exited already. */
stopRemoteMonitor();
}
}
if (error) {
Assert.fail(" !!!Test Failed !!!");
}
}
Aggregations