No SQL error reporting
Closed this issue · 9 comments
When the SQL used to seed the database has problems, the errors are swallowed and it is impossible to debug what is wrong.
Hi @Gaibhne ! Thanks for reporting. I will look into it. Should not be to hard to implement.
The reason this happens to me a lot is because I am adjusting legacy unit tests to not use the production (!) database and my typical work flow is to export the production DB with a tool like mysqldump or phpMyAdmin and then use that to seed the unit test database, but since MySQL and Postgre are not quite compatible with H2, oftentimes the SQL needs some cleanup before it is accepted by H2 and thus embedded-db-junit.
Added logging for exception that is catched during initialization. As this library relies on SLF4J, remember to have a SLF4J runtime available in "test" scope to be able to read the actual log output
@Gaibhne : just released the changes to Maven central as v. 0.9,. It should be widely available pretty soon. Thank you for reporting back!
Even after adding the SLF dependencies to my project, the following does not produce any helpful output:
@Rule
public EmbeddedDatabaseRule rule = EmbeddedDatabaseRule.builder().withMode("MySQL")
.withInitialSqlFromResource("classpath:mock-data.sql").build();
@Test
public void bla() {
rule.getConnectionJdbcUrl();
assertTrue(true);
}
Am I not using it correctly ? All I get are variations of "Malformed database URL, failed to parse the main URL sections", which is obviously not the correct error.
Yours:
[INFO] +- org.zapodot:embedded-db-junit:jar:1.0-RC1:compile
[INFO] | +- com.h2database:h2:jar:1.4.194:compile
Here is my complete dependency tree:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ InternalProject ---
[INFO] some.internal.project:InternalProject:jar:0.2.2
[INFO] +- junit:junit:jar:4.12:compile
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- com.github.stefanbirkner:system-rules:jar:1.16.1:test
[INFO] | \- (junit:junit:jar:4.11:test - omitted for conflict with 4.12)
[INFO] +- some.other.internal.project:MiscProject:jar:0.2:compile
[INFO] +- some.internal.project:InternalLogger:jar:0.1.2:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.4.1:compile
[INFO] | +- org.apache.logging.log4j:log4j-core:jar:2.4.1:compile
[INFO] | | \- (org.apache.logging.log4j:log4j-api:jar:2.4.1:compile - omitted for duplicate)
[INFO] | \- (some.other.internal.project:MiscProject:jar:0.1:compile - omitted for conflict with 0.2)
[INFO] +- org.apache.commons:commons-configuration2:jar:2.1:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- commons-io:commons-io:jar:2.5:compile
[INFO] +- com.squareup.retrofit2:retrofit:jar:2.1.0:compile
[INFO] | \- com.squareup.okhttp3:okhttp:jar:3.3.0:compile
[INFO] | \- com.squareup.okio:okio:jar:1.8.0:compile
[INFO] +- com.squareup.retrofit2:converter-gson:jar:2.1.0:compile
[INFO] | +- (com.squareup.retrofit2:retrofit:jar:2.1.0:compile - omitted for duplicate)
[INFO] | \- com.google.code.gson:gson:jar:2.7:compile
[INFO] +- com.squareup.okhttp3:logging-interceptor:jar:3.3.0:compile
[INFO] | \- (com.squareup.okhttp3:okhttp:jar:3.3.0:compile - omitted for duplicate)
[INFO] +- org.projectlombok:lombok:jar:1.16.12:provided
[INFO] +- com.beust:jcommander:jar:1.64:compile
[INFO] +- some.internal.project.commons:internal-java-commons:jar:1.6.8:compile
[INFO] | +- some.internal.project:InternalDBCore:jar:1.1.1:compile
[INFO] | | +- org.apache.commons:commons-dbcp2:jar:2.1.1:compile
[INFO] | | | +- (org.apache.commons:commons-pool2:jar:2.4.2:compile - omitted for duplicate)
[INFO] | | | \- (commons-logging:commons-logging:jar:1.2:compile - omitted for duplicate)
[INFO] | | +- (org.apache.commons:commons-lang3:jar:3.5:compile - omitted for conflict with 3.3.2)
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] | | | +- (commons-logging:commons-logging:jar:1.2:compile - omitted for duplicate)
[INFO] | | | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | | +- mysql:mysql-connector-java:jar:6.0.5:compile
[INFO] | | +- (some.internal.project:InternalLogger:jar:0.1:compile - omitted for conflict with 0.1.2)
[INFO] | | +- (some.other.internal.project:MiscProject:jar:0.2:compile - omitted for duplicate)
[INFO] | | +- (org.apache.commons:commons-configuration2:jar:2.1:compile - omitted for duplicate)
[INFO] | | \- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] | +- (some.other.internal.project:MiscProject:jar:0.2:compile - omitted for duplicate)
[INFO] | +- (some.internal.project:InternalLogger:jar:0.1:compile - omitted for conflict with 0.1.2)
[INFO] | +- javax.mail:mail:jar:1.5.0-b01:compile
[INFO] | | \- javax.activation:activation:jar:1.1:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.1:compile
[INFO] | +- (org.slf4j:slf4j-simple:jar:1.7.21:compile - omitted for duplicate)
[INFO] | +- com.squareup:javapoet:jar:1.8.0:compile
[INFO] | +- (com.google.code.gson:gson:jar:2.7:compile - omitted for duplicate)
[INFO] | +- (com.squareup.okhttp3:okhttp:jar:3.3.0:compile - omitted for duplicate)
[INFO] | +- (com.squareup.retrofit2:retrofit:jar:2.1.0:compile - omitted for duplicate)
[INFO] | +- (com.squareup.retrofit2:converter-gson:jar:2.1.0:compile - omitted for duplicate)
[INFO] | \- (com.squareup.okhttp3:logging-interceptor:jar:3.3.0:compile - omitted for duplicate)
[INFO] +- com.google.guava:guava:jar:21.0:compile
[INFO] +- io.rest-assured:json-schema-validator:jar:3.0.2:compile
[INFO] | +- com.github.fge:json-schema-validator:jar:2.2.6:compile
[INFO] | | +- (com.google.code.findbugs:jsr305:jar:3.0.0:compile - omitted for conflict with 3.0.1)
[INFO] | | +- joda-time:joda-time:jar:2.3:compile
[INFO] | | +- com.googlecode.libphonenumber:libphonenumber:jar:6.2:compile
[INFO] | | +- com.github.fge:json-schema-core:jar:1.2.5:compile
[INFO] | | | +- com.github.fge:uri-template:jar:0.9:compile
[INFO] | | | | +- com.github.fge:msg-simple:jar:1.1:compile
[INFO] | | | | | +- com.github.fge:btf:jar:1.2:compile
[INFO] | | | | | | \- (com.google.code.findbugs:jsr305:jar:2.0.1:compile - omitted for conflict with 3.0.1)
[INFO] | | | | | \- (com.google.code.findbugs:jsr305:jar:2.0.1:compile - omitted for conflict with 3.0.1)
[INFO] | | | | +- (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 21.0)
[INFO] | | | | \- (com.google.code.findbugs:jsr305:jar:2.0.1:compile - omitted for conflict with 3.0.1)
[INFO] | | | +- com.github.fge:jackson-coreutils:jar:1.8:compile
[INFO] | | | | +- (com.github.fge:msg-simple:jar:1.1:compile - omitted for duplicate)
[INFO] | | | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
[INFO] | | | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.3:compile
[INFO] | | | | | \- com.fasterxml.jackson.core:jackson-core:jar:2.2.3:compile
[INFO] | | | | +- (com.google.guava:guava:jar:16.0.1:compile - omitted for conflict with 21.0)
[INFO] | | | | \- (com.google.code.findbugs:jsr305:jar:2.0.1:compile - omitted for conflict with 3.0.1)
[INFO] | | | +- org.mozilla:rhino:jar:1.7R4:compile
[INFO] | | | \- (com.google.code.findbugs:jsr305:jar:2.0.1:compile - omitted for conflict with 3.0.1)
[INFO] | | \- net.sf.jopt-simple:jopt-simple:jar:4.6:compile
[INFO] | \- (org.hamcrest:hamcrest-core:jar:1.3:compile - omitted for duplicate)
[INFO] +- org.zapodot:embedded-db-junit:jar:1.0-RC1:compile
[INFO] | +- (junit:junit:jar:4.12:compile - omitted for duplicate)
[INFO] | +- com.h2database:h2:jar:1.4.194:compile
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.5.6:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.24:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.21:compile
[INFO] | \- (org.slf4j:slf4j-api:jar:1.7.21:compile - omitted for conflict with 1.7.24)
[INFO] +- org.jdbi:jdbi3:jar:3.0.0-beta1:compile
[INFO] | +- org.antlr:antlr-runtime:jar:3.4:compile
[INFO] | | +- org.antlr:stringtemplate:jar:3.2.1:compile
[INFO] | | | \- (antlr:antlr:jar:2.7.7:compile - omitted for duplicate)
[INFO] | | \- antlr:antlr:jar:2.7.7:compile
[INFO] | +- (org.slf4j:slf4j-api:jar:1.7.21:compile - omitted for conflict with 1.7.24)
[INFO] | +- com.google.code.findbugs:annotations:jar:3.0.1:compile
[INFO] | | +- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] | | \- (com.google.code.findbugs:jsr305:jar:3.0.1:compile - omitted for duplicate)
[INFO] | +- (com.google.guava:guava:jar:21.0:compile - omitted for duplicate)
[INFO] | \- net.jodah:expiringmap:jar:0.5.6:compile
[INFO] \- org.jdbi:jdbi3-sqlobject:jar:3.0.0-beta1:compile
[INFO] +- (org.jdbi:jdbi3:jar:3.0.0-beta1:compile - omitted for duplicate)
[INFO] +- (com.google.code.findbugs:annotations:jar:3.0.1:compile - omitted for duplicate)
[INFO] \- org.assertj:assertj-core:jar:3.5.2:compile
@Gaibhne thank you for posting your dependency graph. I still haven't got the time to write a test to find out what is happening in your case.
However: the library is using the H2 database driver's ability to add init scripts in the JDBC URL (see http://h2database.com/html/features.html#execute_sql_on_connection) and I guess that is why you are seeing the MalformedUrlException. Have you checked that you are using the correct path to the SQL file?
Having said that I will try to create a test of some sort to try to reproduce the error.
Yes, my configuration in general is fine, as I am already using db-unit in my unit tests, and sometimes when I add something to the SQL files, they stop working. As soon as I remove the offending pieces (like "Engine=InnoDB") it works again. But since I get no feedback on what is wrong exactly, I sometimes have to try around a lot until I figure out what is causing the issue.