Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Merge branch 'no_future'
Browse files Browse the repository at this point in the history
  • Loading branch information
freels committed Dec 16, 2010
2 parents 63f4f87 + b4e44e6 commit b407a33
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions project/build.properties
@@ -1,8 +1,8 @@
#Project properties #Project properties
#Fri Nov 12 13:59:13 PST 2010 #Mon Nov 15 13:56:50 PST 2010
project.organization=com.twitter project.organization=com.twitter
project.name=querulous project.name=querulous
sbt.version=0.7.4 sbt.version=0.7.4
project.version=1.4.3-SNAPSHOT project.version=1.4.4-SNAPSHOT
build.scala.versions=2.7.7 2.8.0 build.scala.versions=2.7.7 2.8.0
project.initialize=false project.initialize=false
2 changes: 1 addition & 1 deletion src/main/scala/com/twitter/querulous/FutureTimeout.scala
Expand Up @@ -20,7 +20,7 @@ class FutureTimeout(poolSize: Int, queueSize: Int) {
thread thread
} }
} }
private val executor = new ThreadPoolExecutor(poolSize, poolSize, 0, TimeUnit.SECONDS, private val executor = new ThreadPoolExecutor(1, poolSize, 60, TimeUnit.SECONDS,
new LinkedBlockingQueue[Runnable](queueSize), new LinkedBlockingQueue[Runnable](queueSize),
DaemonThreadFactory) DaemonThreadFactory)


Expand Down
Expand Up @@ -34,7 +34,6 @@ object DatabaseFactory {
timeoutConfig("pool_size").toInt, timeoutConfig("pool_size").toInt,
timeoutConfig("queue_size").toInt, timeoutConfig("queue_size").toInt,
timeoutConfig("open").toLong.millis, timeoutConfig("open").toLong.millis,
timeoutConfig("initialize").toLong.millis,
config("size_max").toInt) config("size_max").toInt)
} }


Expand Down
Expand Up @@ -9,16 +9,25 @@ import net.lag.logging.Logger


class SqlDatabaseTimeoutException(msg: String, val timeout: Duration) extends SQLException(msg) class SqlDatabaseTimeoutException(msg: String, val timeout: Duration) extends SQLException(msg)


class TimingOutDatabaseFactory(val databaseFactory: DatabaseFactory, val poolSize: Int, queueSize: Int, openTimeout: Duration, initialTimeout: Duration, maxConnections: Int) extends DatabaseFactory { class TimingOutDatabaseFactory(val databaseFactory: DatabaseFactory,
def apply(dbhosts: List[String], dbname: String, username: String, password: String, urlOptions: Map[String, String]) = { val poolSize: Int,
val queueSize: Int,
val openTimeout: Duration,
val maxConnections: Int) extends DatabaseFactory {
private val timeout = new FutureTimeout(poolSize, queueSize)

def apply(dbhosts: List[String], dbname: String, username: String, password: String,
urlOptions: Map[String, String]) = {
val dbLabel = if (dbname != null) dbname else "(null)" val dbLabel = if (dbname != null) dbname else "(null)"


new TimingOutDatabase(databaseFactory(dbhosts, dbname, username, password, urlOptions), dbhosts, dbLabel, poolSize, queueSize, openTimeout, initialTimeout, maxConnections) new TimingOutDatabase(databaseFactory(dbhosts, dbname, username, password, urlOptions),
dbhosts, dbLabel, timeout, openTimeout, maxConnections)
} }
} }


class TimingOutDatabase(database: Database, dbhosts: List[String], dbname: String, poolSize: Int, queueSize: Int, openTimeout: Duration, initialTimeout: Duration, maxConnections: Int) extends Database { class TimingOutDatabase(database: Database, dbhosts: List[String], dbname: String,
private val timeout = new FutureTimeout(poolSize, queueSize) timeout: FutureTimeout, openTimeout: Duration,
maxConnections: Int) extends Database {
private val log = Logger.get(getClass.getName) private val log = Logger.get(getClass.getName)


private def getConnection(wait: Duration) = { private def getConnection(wait: Duration) = {
Expand Down
Expand Up @@ -17,6 +17,7 @@ class TimingOutDatabaseSpec extends Specification with JMocker with ClassMocker
val timeout = 1.second val timeout = 1.second
var shouldWait = false var shouldWait = false
val connection = mock[Connection] val connection = mock[Connection]
val future = new FutureTimeout(1, 1)
val database = new Database { val database = new Database {
def open() = { def open() = {
if (shouldWait) latch.await(100.seconds.inMillis, TimeUnit.MILLISECONDS) if (shouldWait) latch.await(100.seconds.inMillis, TimeUnit.MILLISECONDS)
Expand All @@ -29,7 +30,7 @@ class TimingOutDatabaseSpec extends Specification with JMocker with ClassMocker
// one(connection).close() // one(connection).close()
} }


val timingOutDatabase = new TimingOutDatabase(database, List("dbhost"), "dbname", 1, 1, timeout, timeout, 1) val timingOutDatabase = new TimingOutDatabase(database, List("dbhost"), "dbname", future, timeout, 1)
shouldWait = true shouldWait = true


"timeout" in { "timeout" in {
Expand Down

0 comments on commit b407a33

Please sign in to comment.