Debian Codegraph @

src/test/java/com/zaxxer/hikari/pool/RampUpDown.java

raw
1 /*
2 * Copyright (C) 2013, 2014 Brett Wooldridge
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.zaxxer.hikari.pool;
18
19 import static com.zaxxer.hikari.pool.TestElf.newHikariConfig;
20 import static com.zaxxer.hikari.pool.TestElf.getPool;
21 import static com.zaxxer.hikari.util.UtilityElf.quietlySleep;
22 import static org.junit.Assert.assertSame;
23
24 import java.sql.Connection;
25 import java.sql.SQLException;
26
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 import com.zaxxer.hikari.HikariConfig;
31 import com.zaxxer.hikari.HikariDataSource;
32
33 public class RampUpDown
34 {
35 @Test
36 public void rampUpDownTest() throws SQLException
37 {
38 HikariConfig config = newHikariConfig();
39 config.setMinimumIdle(5);
40 config.setMaximumPoolSize(60);
41 config.setInitializationFailTimeout(0);
42 config.setConnectionTestQuery("VALUES 1");
43 config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
44
45 System.setProperty("com.zaxxer.hikari.housekeeping.periodMs", "250");
46
47 try (HikariDataSource ds = new HikariDataSource(config)) {
48
49 ds.setIdleTimeout(1000);
50 HikariPool pool = getPool(ds);
51
52 // wait two housekeeping periods so we don't fail if this part of test runs too quickly
53 quietlySleep(500);
54
55 Assert.assertSame("Total connections not as expected", 5, pool.getTotalConnections());
56
57 Connection[] connections = new Connection[ds.getMaximumPoolSize()];
58 for (int i = 0; i < connections.length; i++)
59 {
60 connections[i] = ds.getConnection();
61 }
62
63 assertSame("Total connections not as expected", 60, pool.getTotalConnections());
64
65 for (Connection connection : connections)
66 {
67 connection.close();
68 }
69
70 quietlySleep(500);
71
72 assertSame("Total connections not as expected", 5, pool.getTotalConnections());
73 }
74 }
75 }