[CONJ-112] Better structure of database URL for connect in JUnit test cases Created: 2014-09-10 Updated: 2014-09-23 Resolved: 2014-09-23 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | None |
| Affects Version/s: | 1.1.7 |
| Fix Version/s: | 1.1.8 |
| Type: | Task | Priority: | Trivial |
| Reporter: | Lennart Schedin | Assignee: | Massimo Siani (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
I like JUnit tests and I frequently “messes” with them to try different things. I have MariaDB server 5.5 installed on my Windows computer as my normal database server. I have Mysql 5.1 installed on a different port. I also have a virtual Ubuntu machine with some other version. I frequently edit the database URL in BaseTest.java to change my IP, port and sometimes also to add connection properties. I searched the source code and found 49 matches of the string “DriverManager.getConnection”. One is found in BaseTest.java and the others are found in other test files. It would be easier for me if there only was one place to change the database host and port in the test cases. I understand that some of the test cases need to create more than 1 Connection and also use other properties in the connection url. I suggest that the connect mechanism in BaseTest.java is refactored so that the following things can be edited easily:
For test cases that needs a new Connection a getConnection()-method could be created in BaseTest.java. For test cases that need optional URL parameters it can be supplied as parameters to a getConnection()-method. |
| Comments |
| Comment by Massimo Siani (Inactive) [ 2014-09-15 ] | |
|
Does https://code.launchpad.net/~massimo-siani/mariadb-java-client/cleanup-tests represent something close to what you mean? (not complete yet) | |
| Comment by Lennart Schedin [ 2014-09-16 ] | |
|
Yes it is something like that that I had in mind! Even though it is not finished I’m making two small suggestions: | |
| Comment by Lennart Schedin [ 2014-09-17 ] | |
|
One more enhancement request: would it be possible to set the database URL/host/IP/port/username/password externally? Typically you might have a Jenkins Continuous integration system that automatically runs the test. It would be good to be able to configure the URL like this:
The BaseTest.java could then use System.getProperty("dbUrl") and use that (if it exists). | |
| Comment by Vladislav Vaintroub [ 2014-09-17 ] | |
|
Massimo, in your patch you are leaking connections. the setConnection always opens a new connection, but does not close the existing one, and you have a bunch of setConnection inside the tests, in addition to "beforeTest" one. to me, looks like it would be better not to create a new connection, but instead use connection.setClientInfo(String name, String value), and make sure it works | |
| Comment by Massimo Siani (Inactive) [ 2014-09-18 ] | |
|
Vlad, you're right, thanks. It should be better now. | |
| Comment by Massimo Siani (Inactive) [ 2014-09-19 ] | |
|
I think that this one should be the first to be merged, or it will be too difficult to maintain. |