2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.tomcat.jdbc.test;
20
import java.sql.Connection;
22
import org.apache.tomcat.jdbc.test.driver.Driver;
24
public class MultipleCloseTest extends DefaultTestCase {
26
public MultipleCloseTest(String name) {
31
public org.apache.tomcat.jdbc.pool.DataSource createDefaultDataSource() {
32
org.apache.tomcat.jdbc.pool.DataSource ds = super.createDefaultDataSource();
33
ds.getPoolProperties().setDriverClassName(Driver.class.getName());
34
ds.getPoolProperties().setUrl(Driver.url);
35
ds.getPoolProperties().setInitialSize(0);
36
ds.getPoolProperties().setMaxIdle(1);
37
ds.getPoolProperties().setMinIdle(1);
38
ds.getPoolProperties().setMaxActive(1);
39
ds.getPoolProperties().setUseDisposableConnectionFacade(true);
44
protected void tearDown() throws Exception {
49
public void testClosedConnectionsNotReused() throws Exception {
52
Connection con1 = datasource.getConnection();
54
// A new connection is open
55
assertFalse(con1.isClosed());
59
// Confirm that a closed connection is closed
60
assertTrue(con1.isClosed());
62
// Open a new connection (This will re-use the previous pooled connection)
63
datasource.getConnection();
65
// A connection, once closed, should stay closed
66
assertTrue(con1.isClosed());