How to Test Datasource Connection Pool in Wildfly Java Application Server via Command Line

Posted on

Related to the article titled ‘How to Add Datasource in Wildfly Java Application Server via Command Line’ in this link which is written before, this article is specifically written with the relation of testing the datasource which has already been added and defined before. After successfully adding the datasource and also reloading the Wildfly Java Application Server, there is no way to know that the datasource configuration added is totally working successfully.

First of all, it must be tested. The mechanism for testing it can be done by directly used in the application deployed. In other words, the datasource added is directly connected through the application deployed. But there is actually a simple mechanisme for testing the already added datasource before it can be actually tested with the application deployed. It can be done by executing the following command as shown in the following pattern below :

[standalone@localhost:9990 /] /subsystem=datasources/data-source=my-datasource:test-connection-in-pool
{
"outcome" => "failed",
"failure-description" => "WFLYJCA0040: failed to invoke operation: WFLYJCA0047: Connection is not valid",
"rolled-back" => true,
"response-headers" => {"process-state" => "reload-required"}
}
[standalone@localhost:9990 /]

The above output command generated can be seen that the output is actually generating a failure outcome since there is an error message stating “Connection is not valid”. So, the datasource configuration added needs to be corrected, and if the output is success, in other words, the datasource is being configured correctly, the output produced or given is somehow will look like the following output :

[standalone@localhost:9990 /] /subsystem=datasources/data-source=my-datasource:test-connection-in-pool
{
"outcome" => "success",
"result" => [true]
}
[standalone@localhost:9990 /]

To be able to find out the name of the datasource specified in the above command execution, just check and list the available datasource added in the Wildlfy Java Management Console. For further reference on how to get the list of the existing datasource available in the Wildlfy Java Application Server, just check the article titled ‘How to Display Database Driver List in Wildfly Java Application Server’ in this link. Another reference to be checked out is the Wildfly Cheat Sheet Command in this link or googling it out to get the best answer.

Leave a Reply