-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"merged" #2126 Added Support For beginRequest and endRequest (new ver…
…sion)
- Loading branch information
1 parent
8053e39
commit d544180
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/java/com/zaxxer/hikari/pool/RequestBoundariesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.zaxxer.hikari.pool; | ||
|
||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import com.zaxxer.hikari.mocks.StubConnection; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.sql.Connection; | ||
|
||
import static com.zaxxer.hikari.pool.TestElf.getPool; | ||
import static com.zaxxer.hikari.pool.TestElf.newHikariConfig; | ||
|
||
public class RequestBoundariesTest { | ||
|
||
private static final HikariConfig config; | ||
static { | ||
config = newHikariConfig(); | ||
config.setMinimumIdle(0); | ||
config.setMaximumPoolSize(10); | ||
config.setInitializationFailTimeout(Long.MAX_VALUE); | ||
config.setConnectionTestQuery("VALUES 1"); | ||
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource"); | ||
} | ||
|
||
private HikariPool getHikariPool(boolean enableRequestBoundaries) { | ||
System.setProperty("com.zaxxer.hikari.enableRequestBoundaries", String.valueOf(enableRequestBoundaries)); | ||
HikariDataSource ds = new HikariDataSource(config); | ||
HikariPool pool = getPool(ds); | ||
return pool; | ||
} | ||
|
||
@Test | ||
public void requestBoundaryEnabledTest() throws Exception { | ||
HikariPool pool = getHikariPool(true); | ||
Connection conn = pool.getConnection(); | ||
StubConnection stubConnection = conn.unwrap(StubConnection.class); | ||
Assert.assertTrue("Begin request called", stubConnection.beginRequestCalled); | ||
Assert.assertFalse("End request called", stubConnection.endRequestCalled); | ||
conn.close(); | ||
Assert.assertTrue("Begin request called", stubConnection.beginRequestCalled); | ||
Assert.assertTrue("End request called", stubConnection.endRequestCalled); | ||
} | ||
|
||
@Test | ||
public void requestBoundaryDisabledTest() throws Exception { | ||
HikariPool pool = getHikariPool(false); | ||
Connection conn = pool.getConnection(); | ||
StubConnection stubConnection = conn.unwrap(StubConnection.class); | ||
Assert.assertFalse("Begin request called", stubConnection.beginRequestCalled); | ||
Assert.assertFalse("End request called", stubConnection.endRequestCalled); | ||
conn.close(); | ||
Assert.assertFalse("Begin request called", stubConnection.beginRequestCalled); | ||
Assert.assertFalse("End request called", stubConnection.endRequestCalled); | ||
} | ||
} |