Thursday, 12 September 2013

No suitable driver found when grails.project.fork is enabled in grails 2.3.0

No suitable driver found when grails.project.fork is enabled in grails 2.3.0

I have a brand new grails 2.3.0 app, completely unconfigured—just out of
the box settings with the exception of hibernate4 instead of hibernate 3.
There's just one empty domain class and its corresponding unit test. I
always get the following error if I try to do anything with sql in the
unit test:
java.sql.SQLException: No suitable driver found
forjdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000
I'm just using the default grails 2.3 grails.project.fork settings, if I
comment them out, everything works fine:
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the
Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm:
256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256,
daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256,
forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256,
forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
As well as the default h2 dataSource in the test environment:
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
...
environments {
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
}
And a rough spec that triggers the error:
@TestFor(Person)
class PersonSpec extends Specification {
def setup() {
}
def cleanup() {
}
void "test sql"() {
when:
def result
try {
def person = new Person(name: 'Name')
def sql = Sql.newInstance(config.dataSource.url,
config.dataSource.username, config.dataSource.password,
config.dataSource.driverClassName)
result = sql.execute("select * from person")
}
catch(java.sql.SQLException ex) {
result = ex
}
then:
result == true
}
}
Does the forked test environment block db connectivity? I can't seem to
figure out how to solve this.

No comments:

Post a Comment