Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test containers #6

Merged
merged 5 commits into from Mar 19, 2021
Merged

Conversation

pablogrisafi1975
Copy link
Contributor

My original idea was to make another totally unrelated change.
But I saw I could not run most test without installing every engine manually, and I
didn't like the idea.

I found this wonderful project TestContainers, used for other persistence libraries.
Basically it automatically starts and stops an instance of a docker virtual machine
with whatever database you need. I'm not docker-savvy, but it worked with docker for windows,
instructions were pretty clear and so I give it a try. And it worked.

You still need to install docker (for windows if that's your OS), but it's waaaay less work than
installing 5 database engines.

The first time a test for a specific database runs it need to download the full image
and that make take some time, but after that it reuses the same image and they are pretty fast.

161 tests run in 300 seconds on my laptop

What I did:

I migrated all tests to junit4, since is the minimal version supported by testContainers
I separated the tests in 3 categories

  • The quick tests that run in memory databases plus sqlite. I didn't touch them, they don't need to be installed.
  • The TestContainerDB category that run using test containers and cover almost every other database.
  • The ExternalDB category that runs with a working external DB. The only class left in that category is TestOracle,
    because I couldn't make it work.

You can choose what category to run from command line, I wrote the instructions in the readme.md file.

I refactored the tests one by one, using TestContainers docker based databased and most test worked after a few changes

The changes

  • MySql tables and columns are case sensitive or not depending on the file system. In Windows they are case insensitive, in
    linux (like docker images) are case sensitive. I edited your script for creating tables for MySql, basically making
    all tables names PascalCase.
  • There was a bug in the method UtilsForTests.isProcedureInDatabase, fixed.
  • I needed to separate the two MSSQL tests in two classes, on for the MS driver, one for the jtds driver.
  • jtds returned a null clob when there was null data! A simple if solved the problem.
  • In some cases the insert call to executeUpdate throw an exception! Something like "there is a record and should not be". I solved it by changing from executeUpdate to execute.
  • executeCommand methods in BaseTest are now static because I needed them.
  • TestContainers database are empty, in order to run tests that included Pubs or Northwind databases I needed to create them first, and then reverse engineer your extra columns.
  • In some cases I was able to create the tables just once (and make them faster), in other cases I needed to recreate
    them on every test method.

Finally I don't know If I broke oracle, I find no way to test it.

I think there is still room for improvement:

  • Every TestContainer DB starts form zero, so there is no need to clean up anything. That may speed things up.
  • If all tests inside a class can run without restarting the database, it will be faster.
  • Probably the logging of every creation statement is slowing down the whole thing.
  • Maybe create a basic battery of tests for every engine using Pubs and Northwind, and then add
    specific tests for the non-standard dataypes?
  • there is a lot of copy/paste between Test clases, could be removed.
  • Every once in a while a got an OOM, or a "The forked VM terminated without properly saying goodbye. VM crash or System.exit called?"
    message. I think I'm killing my machine by starting/stopping multiple database engines, but maybe there is something else.

Anyway, let me know what you think, and please try in you machine!

PS:
Persism.iml files, and the whole folders .idea and target should be included in .gitignore. There are not needed because
idea regenerated them on demand, and are filesystem dependent. I didn't change them because I didn't want to
make more changes in the PR.

Again, let me know what you think!

@sproket
Copy link
Owner

sproket commented Mar 19, 2021

Thanks! This is awesome. I'll have a look this weekend and coordinate.

@sproket
Copy link
Owner

sproket commented Mar 19, 2021

Line 79 in my todo.txt file. Great minds think alike.

@sproket
Copy link
Owner

sproket commented Mar 19, 2021

Oof. Docker and VBox don't play nice together. I'll need to figure this out.

Copy link
Owner

@sproket sproket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I'll approve and test here. I managed to get VBOX and Docker to play nice.

@sproket sproket merged commit 613780f into sproket:master Mar 19, 2021
@sproket
Copy link
Owner

sproket commented Mar 20, 2021

I have trouble with Docker since it now requires HyperV to be enabled or it doesn't play nice with Virtual Box. I tried running the older Docker Toolbox version but it doesn't work.

I integrated your tests. We can tidy this up over time.

POM
changed oracle back to ojdbc8 which should be fine running under java8 or +
fixed jaybird warning
added profile for running without test containers
Added back suites to AllTests (Left @ignore for Maven) - I still need AllTests from IDE to generate code-coverage
Added subclasses for Container versions - please test these
Marked JTDS for deprecation - I should remove it because it's no longer maintained
Added .idea to .gitignore and removed from git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants