String pageHeaderText = String.format(AS_NODE_NAME_FORMAT, jbossConfig);
//assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
assertTrue("Content doesn't contain the header: "+pageHeaderText,
client.getElement("content").getTextContent().contains(pageHeaderText));
ContentTable table;
ContentInfoTable infoTable;
String headerText;
Properties properties;
JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
/*
* General Properties
Name:JBoss AS 5 (default)
Version:5.1.0.CR1
Description:JBoss Application Server
*/
headerText = "General Properties";
assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
infoTable = ejtt.getContentInfoTable(table.getElement());
properties = infoTable.getProperties();
assertEquals("General Properties / Name", pageHeaderText, properties.getProperty("Name") );
String versionPrefix = "5.1";
String jmxMBeanName = "jboss.system:type=Server";
versionPrefix = (String) jmxUtils.getMBeanAttribute(jmxMBeanName, "VersionNumber");
assertTrue("General Properties / Version startsWith('"+versionPrefix+"')",
properties.getProperty("Version","~not found~").startsWith(versionPrefix) );
assertEquals("General Properties / Description", AS_NODE_DESCRIPTION, properties.get("Description") );
/*
* Resource Traits
Server Name: default
Server Home Dir: /home/brq/ozizka/.../jboss-as-5.x/build/output/jboss-5.1.0.CR1/server/default
Version Name: The Oracle
Build Date: April 22 2009
Start Date: Wed Apr 22 18:26:43 CEST 2009
*/
headerText = AppConstants.LABEL_TRAITS;
assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
infoTable = ejtt.getContentInfoTable(table.getElement());
properties = infoTable.getProperties();
assertEquals(AppConstants.LABEL_TRAITS+" / Server Name", ejtt.getJBossConfig(),
properties.getProperty("Server Name"));
assertEquals(AppConstants.LABEL_TRAITS+" / Server Home Dir",
//String.format("%s/server/%s", ejtt.getJBossHomeDir(), ejtt.getJBossConfig()),
ejtt.getJBossHomeDir(),
properties.getProperty("Server Home Dir"));
/*
* Metrics Summary
Name Value Description
Active Thread Count 7.0 The current number of active threads for this app server instance
JVM Free Memory 183.6MB The amount of free memory for the JVM this app server instance is running on
JVM Total Memory 218.7MB The amount of total memory for the JVM this app server instance is running on
TODO: Split - grab some resources and do a page refresh for every part?
*/
headerText = AppConstants.LABEL_NUMERIC_METRICS;
assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
// Get values as properties.
table.analyzeColumns();
Properties metricsProps = table.getProperties("Name", "Value");
log.info( headerText +" 1st: "+ metricsProps.toString() );
// Parse the values.
int threads1 = (int)NumberUtils.toDouble(metricsProps.getProperty("Active Thread Count").replace(',', '.'));
double memFree1 = NumberUtils.toDouble(metricsProps.getProperty("JVM Free Memory").replace(',', '.').replace("MB", ""));
double memTotal1 = NumberUtils.toDouble(metricsProps.getProperty("JVM Total Memory").replace(',', '.').replace("MB", ""));
// Do some requests to add threads.
// Bad way - thread pool can cause thread number not to change.
/*
// Create HTMLUnit WebClient.
WebClient wc = new WebClient(BrowserVersion.FIREFOX_3);
wc.setCssEnabled(false);
wc.setJavaScriptEnabled(false);
// Get some page.
wc.getPage("http://localhost:8080/");
*/
// Launch as much threads as the current number to get higher number.
log.info("Starting "+threads1+" threads.");
ThreadGroup threadGroup = new ThreadGroup("Dummy threads");
for( int i = 0; i < threads1; i++ ) {
log.debug("Starting thread 'Dummy thread "+i+"'");
Thread thread = new Thread(threadGroup, new MyRunnable(), "Dummy thread "+i);
thread.start();
}
// Allocate some memory to decrease free mem.
log.info("Allocating 500 MB of ram.");
byte tmp[] = new byte[500 * 1024 * 1024]; // Few MB.
tmp[0] = 1;
tmp[tmp.length-1] = 1;
// Refresh the page
((HtmlPage)client.getContentPage()).refresh();
// Stop the threads.
threadGroup.interrupt();
// Read new values.
headerText = "Metrics Summary";
assertTrue("Page doesn't contain the header: "+headerText, pageText.contains(headerText));
table = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader(headerText);
// Get values as properties.
table.analyzeColumns();
metricsProps = table.getProperties("Name", "Value");
log.info( headerText +" 2nd: "+ metricsProps.toString() );
// Parse the values.
int threads2 = (int)NumberUtils.toDouble( metricsProps.getProperty("Active Thread Count").replace(',', '.') );
double memFree2 = NumberUtils.toDouble(metricsProps.getProperty("JVM Free Memory").replace(',', '.').replace("MB", "") );