Debian Codegraph @

src/test/java/com/zaxxer/hikari/pool/IsolationTest.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.newHikariDataSource;
20 import static org.junit.Assert.assertNotSame;
21 import static org.junit.Assert.assertSame;
22
23 import java.sql.Connection;
24 import java.sql.SQLException;
25
26 import org.junit.Test;
27
28 import com.zaxxer.hikari.HikariDataSource;
29
30 public class IsolationTest
31 {
32 @Test
33 public void testIsolation() throws SQLException
34 {
35 try (HikariDataSource ds = newHikariDataSource()) {
36 ds.setMinimumIdle(1);
37 ds.setMaximumPoolSize(1);
38 ds.setIsolateInternalQueries(true);
39 ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
40
41 try (Connection connection = ds.getConnection()) {
42 connection.close();
43
44 try (Connection connection2 = ds.getConnection()) {
45 connection2.close();
46
47 assertNotSame(connection, connection2);
48 assertSame(connection.unwrap(Connection.class), connection2.unwrap(Connection.class));
49 }
50 }
51 }
52 }
53
54 @Test
55 public void testNonIsolation() throws SQLException
56 {
57 try (HikariDataSource ds = newHikariDataSource()) {
58 ds.setMinimumIdle(1);
59 ds.setMaximumPoolSize(1);
60 ds.setIsolateInternalQueries(false);
61 ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
62
63 try (Connection connection = ds.getConnection()) {
64 connection.close();
65
66 try (Connection connection2 = ds.getConnection()) {
67 connection2.close();
68
69 assertSame(connection.unwrap(Connection.class), connection2.unwrap(Connection.class));
70 }
71 }
72 }
73 }
74 }