From 35af7c95ff1e710a053371c3f2088b8028d5a8de Mon Sep 17 00:00:00 2001 From: fhanik Date: Mon, 17 Nov 2008 04:42:29 +0000 Subject: [PATCH] Add timeout test git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@718170 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tomcat/jdbc/test/BorrowWaitTest.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java new file mode 100644 index 000000000..d9b355285 --- /dev/null +++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/BorrowWaitTest.java @@ -0,0 +1,55 @@ +package org.apache.tomcat.jdbc.test; + +import java.sql.Connection; +import java.sql.SQLException; + +public class BorrowWaitTest extends DefaultTestCase { + + public BorrowWaitTest(String name) { + super(name); + } + + public void testWaitTime() throws Exception { + int wait = 10000; + this.init(); + this.datasource.setMaxActive(1); + this.datasource.setMaxWait(wait); + Connection con = datasource.getConnection(); + long start = System.currentTimeMillis(); + try { + Connection con2 = datasource.getConnection(); + assertFalse("This should not happen, connection should be unavailable.",true); + }catch (SQLException x) { + long delta = System.currentTimeMillis(); + boolean inrange = Math.abs(wait-delta) < 1000; + assertTrue("Connection should have been acquired within +/- 1 second.",true); + } + con.close(); + } + + public void testWaitTimeInfinite() throws Exception { + if(true){ + System.err.println("testWaitTimeInfinite() test is disabled."); + return;//this would lock up the test suite + } + int wait = -1; + this.init(); + this.datasource.setMaxActive(1); + this.datasource.setMaxWait(wait); + Connection con = datasource.getConnection(); + long start = System.currentTimeMillis(); + try { + Connection con2 = datasource.getConnection(); + assertFalse("This should not happen, connection should be unavailable.",true); + }catch (SQLException x) { + long delta = System.currentTimeMillis(); + boolean inrange = Math.abs(wait-delta) < 1000; + assertTrue("Connection should have been acquired within +/- 1 second.",true); + } + con.close(); + } + + + + +} -- 2.11.0