tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: BasicDataSource creation throws SQLException
Date Thu, 11 Aug 2016 16:02:13 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Roy,

On 8/11/16 3:43 AM, Roy Leonardus wrote:
> Hello Christopher,
> 
> maybe i'm a little bit slow here, but from what i see, we should
> mock the connection method
> 
> Connection connection= ds.getConnection();
> 
> something like
> 
> Connection connection =(Connection) EasyMock.expect(ds. 
> isvalid()).andReturn(true).anyTimes();
> 
> Problem is, the error happened during the validation of the 
> PoolableConnection, below is the build error from the surefire
> 
> Caused by: java.sql.SQLException: isValid() returned false at 
> org.apache.tomcat.dbcp.dbcp2.PoolableConnection.validate(PoolableConne
ction.java:283)
>
> 
at
> org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.validateConnect
ion(PoolableConnectionFactory.java:357)
>
> 
at
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory
(BasicDataSource.java:2307)
>
> 
at
> org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionF
actory(BasicDataSource.java:2290)


It's
> 
been a while since I've bothered to mock the JDBC interfaces
because they are such a PITA to do. But it's possible that your mock
Connection isn't being used by the BasicDataSource. Perhaps you need
to mock the BasicDataSource (or maybe just DataSource) too.

> so i think we should either override the validate() so the
> validation is always returning true( which i am reluctant to do, as
> the point is to test the whole thing)
> 
> or enhancing the fake driver connection, so it always responding
> with a result set.

If you have set a validation query, that query should be executed. If
you don't specify a query, I'd expect Connection.isValid to be used
instead. I see from the exception that the isValid is failing, but you
also mentioned that you tried to set a validation query and got a
different error.

I think you should keep going without a validation query because it
should simplify things a little bit. Can you post more of your code?
It's hard to tell how you are setting-up your test-case. If you have
mock objects, what are you mocking and how are you injecting those
mock objects into the code you are testing?

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJXrKGFAAoJEBzwKT+lPKRYhfwP/AvTbY+aDWduuHChdoRAoPR2
bjcA6u6QjCOxmpFT2qzMnp9PYNnUbqx6GpGyY0poSN6eX9lG5jc27r0SN1Hvrbwk
Rp/+dFySnwMupnLccvhfZnqMZvoyVhPegdEwsbZ4Ep9zzE+wVK0hxAc/8V5nAZpY
5SLTYACt63i5pWyYTwxCHpVVYYyeSm+S9OH2nogD4QugDoV93g6K+YSLpM35SVHp
ul55OBUrWazDQIay6FcFmIf1aQmeNlGejHIPjwdwCsF4QXEwY179s3VFMlKeKkUa
ur/fnZpJ2ZTGFe9q7UzZW+X0HaZHNDHlu/FJAzjquNIxzHxZBh1vsOHncn0D44F5
0yWLRJkuDDT/2e9gwZPQ2civfrAC5c6bKudB03KIZfx5tmCrJMRuneUTt5viIHet
yCF5F30jeOEbBeag1u6A5MH1f96kwJ6h995ohitSzwH4K9vUqaDhL+UFnkVdjusR
vjanlOQcLUYu99fce7QtCMJTThlZy00REmrB0kgnM/VKPOU7ovBFQC95vYknsYyx
8zt2vwKdcz5DYYBhwEJ5D1/SdLNXTeIMJnH9rsIEbXP3DSQVEjeyLTMusVKUP6ER
fN23NOTIyiiceVZdNdXeDh1nhuhsadkGdzFdzK7zdlygcQ+e3yUfhl/T5dfNZyJ+
jnfF+jGQ+CODibpRYFqh
=QV9g
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message