cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject cayenne git commit: CAY-2009 Non-blocking connection pool
Date Sun, 10 May 2015 18:25:50 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master beb07ceb5 -> 55ea394a6


CAY-2009 Non-blocking connection pool

* unit tests to check the queue timeout behavior


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/55ea394a
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/55ea394a
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/55ea394a

Branch: refs/heads/master
Commit: 55ea394a6ad8dad5b236a0f7b4b2d2d52144395f
Parents: beb07ce
Author: aadamchik <aadamchik@apache.org>
Authored: Sun May 10 14:25:44 2015 -0400
Committer: aadamchik <aadamchik@apache.org>
Committed: Sun May 10 14:25:44 2015 -0400

----------------------------------------------------------------------
 .../datasource/BasePoolingDataSourceIT.java     |  6 ++--
 .../cayenne/datasource/PoolingDataSourceIT.java | 37 +++++++++++++++++++-
 2 files changed, 39 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/55ea394a/cayenne-server/src/test/java/org/apache/cayenne/datasource/BasePoolingDataSourceIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/datasource/BasePoolingDataSourceIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/datasource/BasePoolingDataSourceIT.java
index 0c9ea45..22d8421 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/datasource/BasePoolingDataSourceIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/datasource/BasePoolingDataSourceIT.java
@@ -22,8 +22,6 @@ import java.sql.Driver;
 import java.sql.SQLException;
 
 import org.apache.cayenne.conn.DataSourceInfo;
-import org.apache.cayenne.datasource.PoolingDataSource;
-import org.apache.cayenne.datasource.PoolingDataSourceParameters;
 import org.apache.cayenne.di.AdhocObjectFactory;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.log.JdbcEventLogger;
@@ -36,6 +34,8 @@ import org.junit.Before;
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class BasePoolingDataSourceIT extends ServerCase {
 
+	protected static final long QUEUE_WAIT_TIME = 1000l;
+
 	@Inject
 	private DataSourceInfo dataSourceInfo;
 
@@ -70,7 +70,7 @@ public class BasePoolingDataSourceIT extends ServerCase {
 		PoolingDataSourceParameters poolParameters = new PoolingDataSourceParameters();
 		poolParameters.setMinConnections(2);
 		poolParameters.setMaxConnections(3);
-		poolParameters.setMaxQueueWaitTime(1000);
+		poolParameters.setMaxQueueWaitTime(QUEUE_WAIT_TIME);
 		return poolParameters;
 	}
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/55ea394a/cayenne-server/src/test/java/org/apache/cayenne/datasource/PoolingDataSourceIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/datasource/PoolingDataSourceIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/datasource/PoolingDataSourceIT.java
index 342300c..894a50a 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/datasource/PoolingDataSourceIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/datasource/PoolingDataSourceIT.java
@@ -47,7 +47,7 @@ public class PoolingDataSourceIT extends BasePoolingDataSourceIT {
 	}
 
 	@Test
-	public void testGetConnectionAutoCommit() throws Exception {
+	public void testGetConnection_AutoCommit() throws Exception {
 
 		assertTrue(dataSource.getMaxConnections() > 0);
 
@@ -86,6 +86,41 @@ public class PoolingDataSourceIT extends BasePoolingDataSourceIT {
 	}
 
 	@Test
+	public void testGetConnection_FailOnFull() throws Exception {
+
+		assertTrue(dataSource.getMaxConnections() > 0);
+
+		List<Connection> connections = new ArrayList<Connection>();
+		try {
+
+			for (int i = 0; i < dataSource.getMaxConnections(); i++) {
+				connections.add(dataSource.getConnection());
+			}
+
+			long t0 = System.currentTimeMillis();
+			try {
+
+				dataSource.getConnection();
+				fail("Opening more connections than the pool allows succeeeded");
+			} catch (SQLException e) {
+				// expected, but check if we waited sufficiently
+
+				long t1 = System.currentTimeMillis();
+				assertTrue(t1 - t0 >= QUEUE_WAIT_TIME);
+			}
+
+		} finally {
+			for (Connection c : connections) {
+				try {
+					c.close();
+				} catch (SQLException e) {
+
+				}
+			}
+		}
+	}
+
+	@Test
 	public void testGetConnection() throws Exception {
 
 		assertEquals(2, dataSource.poolSize());


Mime
View raw message