Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 7C4D8200B5C for ; Thu, 11 Aug 2016 18:02:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7AE7E160A93; Thu, 11 Aug 2016 16:02:42 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C9177160A90 for ; Thu, 11 Aug 2016 18:02:41 +0200 (CEST) Received: (qmail 86625 invoked by uid 500); 11 Aug 2016 16:02:40 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 86614 invoked by uid 99); 11 Aug 2016 16:02:40 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Aug 2016 16:02:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id F3CD2189CC1 for ; Thu, 11 Aug 2016 16:02:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.713 X-Spam-Level: X-Spam-Status: No, score=0.713 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, NO_RDNS_DOTCOM_HELO=0.433, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 3ZcMLr0EsnXI for ; Thu, 11 Aug 2016 16:02:36 +0000 (UTC) Received: from vms173015pub.verizon.net (vms173015pub.verizon.net [206.46.173.15]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id E68AF5F610 for ; Thu, 11 Aug 2016 16:02:35 +0000 (UTC) Received: from vz-proxy-l001.mx.aol.com ([64.236.82.153]) by vms173015.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0OBR00KW45VP3N40@vms173015.mailsrvcs.net> for users@tomcat.apache.org; Thu, 11 Aug 2016 11:02:14 -0500 (CDT) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=btqxfxui c=1 sm=1 tr=0 a=FJ1kTJ0/xm5uTekQe8vMdQ==:117 a=IkcTkHD0fZMA:10 a=7z1cN_iqozsA:10 a=j4nzMFrpAAAA:8 a=QfKxxUxMAAAA:8 a=gSqLQUQcB1qrLwfaqSoA:9 a=QEXdDO2ut3YA:10 Received: by 71.127.40.115 with SMTP id 112e43c8; Thu, 11 Aug 2016 16:02:14 GMT Subject: Re: BasicDataSource creation throws SQLException To: Tomcat Users List References: <7823b807-694b-478a-99ba-d45b5fa86c0a@apache.org> From: Christopher Schultz Message-id: <1ad5b72f-97ce-d0e7-0962-d2fa9f9bf723@christopherschultz.net> Date: Thu, 11 Aug 2016 12:02:13 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-version: 1.0 In-reply-to: Content-type: text/plain; charset=utf-8 Content-transfer-encoding: 7bit archived-at: Thu, 11 Aug 2016 16:02:42 -0000 -----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