-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reject singleton ConnectionProvider when given to NonBlockingConnecti…
…onPool builder #34
- Loading branch information
1 parent
1d2aedf
commit e0fd757
Showing
4 changed files
with
49 additions
and
13 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
24 changes: 24 additions & 0 deletions
24
rxjava2-jdbc/src/main/java/org/davidmoten/rx/jdbc/internal/SingletonConnectionProvider.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,24 @@ | ||
package org.davidmoten.rx.jdbc.internal; | ||
|
||
import java.sql.Connection; | ||
|
||
import org.davidmoten.rx.jdbc.ConnectionProvider; | ||
|
||
public final class SingletonConnectionProvider implements ConnectionProvider { | ||
|
||
private final Connection connection; | ||
|
||
public SingletonConnectionProvider(Connection connection) { | ||
this.connection = connection; | ||
} | ||
|
||
@Override | ||
public Connection get() { | ||
return connection; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// do nothing as con was not created by this provider | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
rxjava2-jdbc/src/test/java/org/davidmoten/rx/jdbc/pool/NonBlockingConnectionPoolTest.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,17 @@ | ||
package org.davidmoten.rx.jdbc.pool; | ||
|
||
import java.sql.Connection; | ||
|
||
import org.davidmoten.rx.jdbc.ConnectionProvider; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
public class NonBlockingConnectionPoolTest { | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testRejectSingletonConnectionProvider() { | ||
Connection con = Mockito.mock(Connection.class); | ||
NonBlockingConnectionPool.builder().connectionProvider(ConnectionProvider.from(con)); | ||
} | ||
|
||
} |