|
| 1 | +/* |
| 2 | + * Copyright and related rights waived via CC0 |
| 3 | + * |
| 4 | + * You should have received a copy of the CC0 legalcode along with this |
| 5 | + * work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.zaxxer.hikaricp.test; |
| 9 | + |
| 10 | +import com.zaxxer.hikari.HikariConfig; |
| 11 | +import com.zaxxer.hikari.HikariDataSource; |
| 12 | +import com.zaxxer.hikaricp.test.driver.CustomDriver; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | + |
| 15 | +import java.sql.Connection; |
| 16 | +import java.sql.SQLException; |
| 17 | + |
| 18 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 19 | + |
| 20 | +public class HikariCPTest { |
| 21 | + @Test |
| 22 | + void test() throws SQLException { |
| 23 | + HikariConfig config = new HikariConfig(); |
| 24 | + |
| 25 | + config.setAutoCommit(false); |
| 26 | + config.setConnectionTimeout(1000); |
| 27 | + config.setMaximumPoolSize(10); |
| 28 | + config.setDriverClassName(CustomDriver.class.getName()); |
| 29 | + config.setJdbcUrl("jdbc:custom:foo"); |
| 30 | + config.setUsername("bart"); |
| 31 | + config.setPassword("51mp50n"); |
| 32 | + config.addDataSourceProperty("cachePrepStmts", "true"); |
| 33 | + config.addDataSourceProperty("prepStmtCacheSize", "250"); |
| 34 | + config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); |
| 35 | + |
| 36 | + try (HikariDataSource ds = new HikariDataSource(config)) { |
| 37 | + for (int i = 0; i < 10; i++) { |
| 38 | + try (Connection connection = ds.getConnection()) { |
| 39 | + assertNotNull(connection); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + } |
| 45 | +} |
0 commit comments