Author: fjuma
Date: 2009-02-02 10:14:56 -0500 (Mon, 02 Feb 2009)
New Revision: 127
Modified:
trunk/core/src/main/webapp/secure/operationParameters.xhtml
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Added tests for the "Flush" operation and for the "List Formatted Sub Pool
Statistics" operation.
Modified: trunk/core/src/main/webapp/secure/operationParameters.xhtml
===================================================================
--- trunk/core/src/main/webapp/secure/operationParameters.xhtml 2009-01-28 21:50:27 UTC
(rev 126)
+++ trunk/core/src/main/webapp/secure/operationParameters.xhtml 2009-02-02 15:14:56 UTC
(rev 127)
@@ -60,7 +60,8 @@
<ui:remove><!--Don't use s:button, as it will not submit the
form!--></ui:remove>
<h:panelGrid columns="2" styleClass="buttons-table"
columnClasses="button-cell">
- <h:commandButton value="#{messages['button.ok']}"
+ <h:commandButton id="okButton"
+ value="#{messages['button.ok']}"
action="#{operationAction.invokeOperation()}"
styleClass="buttonmed"/>
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-01-28
21:50:27 UTC (rev 126)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-02-02
15:14:56 UTC (rev 127)
@@ -283,6 +283,28 @@
}
/**
+ * Create the specified number of connections to the given
+ * database.
+ *
+ * @return the ArrayList of Connections.
+ */
+ public ArrayList<Connection> createConnections(int numConnections,
+ String jndiName,
+ String username,
+ String password) throws Exception {
+ // Establish multiple connections
+ ArrayList<Connection> connections = new ArrayList<Connection>();
+
+ for(int i = 0; i < numConnections; i++) {
+ Connection con = connectDB(jndiName, username, password);
+ assertNotNull("Null connection", con);
+ connections.add(con);
+ }
+
+ return connections;
+ }
+
+ /**
* Disconnect from the database.
*/
public void disconnectDB(Connection con) throws SQLException {
@@ -292,6 +314,15 @@
}
/**
+ * Close each Connection in the given ArrayList of Connections.
+ */
+ public void closeConnections(ArrayList<Connection> connections) throws
SQLException {
+ for(int i = 0; i < connections.size(); i++) {
+ disconnectDB(connections.get(i));
+ }
+ }
+
+ /**
* @return the suite of tests being tested
* @throws UnsupportedOperationException - you have to override this.
* Can't be abstract, must be static.
@@ -930,6 +961,5 @@
*/
protected abstract boolean isMBeanStateDeployedImpl( ObjectName deploymentMBean )
throws JMException, IOException;
-
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-01-28
21:50:27 UTC (rev 126)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-02-02
15:14:56 UTC (rev 127)
@@ -31,6 +31,7 @@
import javax.management.ObjectName;
import java.util.Map;
import javax.management.JMException;
+import java.sql.Connection;
/**
* When complete, this class will contain tests for creating,
@@ -331,6 +332,184 @@
// Clean up
deleteDatasource(propertiesMap.get("jndi-name"));
+ }
+
+ /**
+ * Test the "Flush" operation.
+ */
+ public void testFlushOperation() throws IOException {
+
+ // Min pool size will be 6, max pool size will be 15
+ Map<String, String> propertiesMap =
createXADatasource("FlushDS");
+
+ performDatasourceOperation(propertiesMap.get("jndi-name"),
DatasourceType.XA_DATASOURCE, "Flush");
+
+ // Make sure the metrics are updated appropriately
+ Map<String, String> expectedMetrics = new HashMap<String, String>();
+ expectedMetrics.put("Available Connection Count", "15.0");
+ expectedMetrics.put("Connection Count", "0.0");
+ expectedMetrics.put("Connection Created Count", "0.0");
+ expectedMetrics.put("Connection Destroyed Count", "0.0");
+ expectedMetrics.put("In Use Connection Count", "0.0");
+ expectedMetrics.put("Max Connections In Use Count", "0.0");
+ expectedMetrics.put("Max Size", "15.0");
+ expectedMetrics.put("Min Size", "6.0");
+
+ checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.XA_DATASOURCE, expectedMetrics);
+
+ // Clean up
+ deleteDatasource(propertiesMap.get("jndi-name"));
}
+
+ /**
+ * Test the "List Formatted Sub Pool Statistics" after creating a new
+ * datasource.
+ */
+ public void testListFormattedSubPoolStatisticsAfterDatasourceCreation() throws
Exception {
+
+ // Min pool size will be 5, max pool size will be 20
+ Map<String, String> propertiesMap =
createNoTXDatasource("ListFormattedSubPoolStatisticsAfterDatasourceCreationDS");
+
+ performDatasourceOperation(propertiesMap.get("jndi-name"),
+ DatasourceType.NO_TX_DATASOURCE,
+ "List Formatted Sub Pool Statistics");
+
+ // Use the default formatter
+ client.click("parametersForm:okButton");
+
+ HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
+ "(Show/Hide Details)");
+ detailsLink.click();
+
+ // Get the result of the operation
+ HtmlForm form = (HtmlForm)client.getElement("operationHistoryForm");
+ HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
+ String actualResult = resultTextBox.getText();
+
+ String expectedResult = "Sub Pool Statistics: \nSub Pool Count: 1\n"
+ +
"------------------------------------------------------\n\n"
+ + "Track By Transaction: false\n"
+ + "Available Connections Count: 20\n"
+ + "Max Connections In Use Count:0\n"
+ + "Connections Destroyed Count:0\n"
+ + "Connections In Use Count:0\n"
+ + "Total Block Time:0\n"
+ + "Average Block Time For Sub Pool:0\n"
+ + "Maximum Wait Time For Sub Pool:0\n"
+ + "Total Timed Out:0";
+
+
+ assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
+ + "\n\nbut was:\n\n" + actualResult,
+ actualResult.contains(expectedResult));
+
+ // Clean up
+ deleteDatasource(propertiesMap.get("jndi-name"));
+ }
+
+ /**
+ * Test the "List Formatted Sub Pool Statistics" operation after multiple
+ * connections to a database have been established.
+ */
+ public void testListFormattedSubPoolStatisticsAfterMultipleConnections() throws
Exception {
+
+ // Min pool size will be 5, max pool size will be 20
+ Map<String, String> propertiesMap =
createLocalTXDatasource("ListFormattedSubPoolStatisticsAfterMultipleConnectionsDS");
+
+ // Create some connections
+ ArrayList<Connection> connections = createConnections(4,
propertiesMap.get("jndi-name"),
+
propertiesMap.get("user-name"),
+
propertiesMap.get("password"));
+
+ performDatasourceOperation(propertiesMap.get("jndi-name"),
+ DatasourceType.LOCAL_TX_DATASOURCE,
+ "List Formatted Sub Pool Statistics");
+
+ // Use the default formatter
+ client.click("parametersForm:okButton");
+
+ HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
+ "(Show/Hide Details)");
+ detailsLink.click();
+
+ // Get the result of the operation
+ HtmlForm form = (HtmlForm)client.getElement("operationHistoryForm");
+ HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
+ String actualResult = resultTextBox.getText();
+
+ String expectedResult = "Sub Pool Statistics: \nSub Pool Count: 1\n"
+ +
"------------------------------------------------------\n\n"
+ + "Track By Transaction: true\n"
+ + "Available Connections Count: 16\n"
+ + "Max Connections In Use Count:4\n"
+ + "Connections Destroyed Count:0\n"
+ + "Connections In Use Count:4\n"
+ + "Total Block Time:0\n"
+ + "Average Block Time For Sub Pool:0\n"
+ + "Maximum Wait Time For Sub Pool:0\n"
+ + "Total Timed Out:0";
+
+ assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
+ + "\n\nbut was:\n\n" + actualResult,
+ actualResult.contains(expectedResult));
+
+ // Clean up
+ closeConnections(connections);
+ deleteDatasource(propertiesMap.get("jndi-name"));
+ }
+
+ /**
+ * Test the "List Formatted Sub Pool Statistics" operation after
+ * closing some connections.
+ */
+ public void testListFormattedSubPoolStatisticsAfterClosingConnections() throws
Exception {
+
+ // Min pool size will be 5, max pool size will be 20
+ Map<String, String> propertiesMap =
createLocalTXDatasource("ListFormattedSubPoolStatisticsAfterClosingConnectionsDS");
+
+ // Create some connections
+ ArrayList<Connection> connections = createConnections(10,
propertiesMap.get("jndi-name"),
+
propertiesMap.get("user-name"),
+
propertiesMap.get("password"));
+
+ // Close some connections
+ disconnectDB(connections.get(0));
+ disconnectDB(connections.get(1));
+
+ performDatasourceOperation(propertiesMap.get("jndi-name"),
+ DatasourceType.LOCAL_TX_DATASOURCE,
+ "List Formatted Sub Pool Statistics");
+
+ // Use the default formatter
+ client.click("parametersForm:okButton");
+
+ HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
+ "(Show/Hide Details)");
+ detailsLink.click();
+
+ // Get the result of the operation
+ HtmlForm form = (HtmlForm)client.getElement("operationHistoryForm");
+ HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
+ String actualResult = resultTextBox.getText();
+
+ String expectedResult = "Sub Pool Statistics: \nSub Pool Count: 1\n"
+ +
"------------------------------------------------------\n\n"
+ + "Track By Transaction: true\n"
+ + "Available Connections Count: 12\n"
+ + "Max Connections In Use Count:10\n"
+ + "Connections Destroyed Count:0\n"
+ + "Connections In Use Count:8";
+
+ assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
+ + "\n\nbut was:\n\n" + actualResult.substring(0,
actualResult.lastIndexOf("Total Block Time")),
+ actualResult.contains(expectedResult));
+
+ // Clean up
+ for(int i = 2; i <=9; i++) {
+ disconnectDB(connections.get(i));
+ }
+
+ deleteDatasource(propertiesMap.get("jndi-name"));
+ }
}