Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix cross-compilation

  • Loading branch information...
commit e0e3a383da6f55c0d77c67f43ddf3ad72f31ed70 1 parent 7ff55f3
@freels freels authored
View
2  project/build/QuerulousProject.scala
@@ -15,7 +15,7 @@ class QuerulousProject(info: ProjectInfo) extends StandardProject(info) with Sub
}
val util = buildScalaVersion match {
- case "2.7.7" => "com.twitter" % "util" % "1.1.1"
+ case "2.7.7" => "com.twitter" % "util" % "1.1.2"
case _ => "com.twitter" % "util" % "1.2.8"
}
View
1  src/main/scala/com/twitter/querulous/database/Database.scala
@@ -1,5 +1,6 @@
package com.twitter.querulous.database
+import com.twitter.querulous._
import java.sql.Connection
import com.twitter.querulous.StatsCollector
import com.twitter.util.TimeConversions._
View
67 src/main/scala/com/twitter/querulous/query/TimingOutStatsCollectingQuery.scala
@@ -1,67 +0,0 @@
-package com.twitter.querulous.query
-
-import java.sql.{Connection, ResultSet}
-import scala.collection.Map
-import scala.util.matching.Regex
-import scala.collection.Map
-import com.twitter.util.Duration
-import com.twitter.util.TimeConversions._
-import com.twitter.querulous.StatsCollector
-import net.lag.extensions._
-
-
-object TimingOutStatsCollectingQueryFactory {
- val TABLE_NAME = """(FROM|UPDATE|INSERT INTO|LIMIT)\s+[\w-]+""".r
- val DDL_QUERY = """^\s*((CREATE|DROP|ALTER)\s+(TABLE|DATABASE)|DESCRIBE)\s+""".r
-
- def simplifiedQuery(query: String) = {
- if (DDL_QUERY.findFirstMatchIn(query).isDefined) {
- "default"
- } else {
- query.regexSub(TABLE_NAME) { m => m.group(1) + " ?" }
- }
- }
-}
-
-class TimingOutStatsCollectingQueryFactory(
- queryFactory: QueryFactory,
- queryInfo: Map[String, (String, Duration, Boolean)],
- defaultTimeout: Duration,
- stats: StatsCollector)
- extends QueryFactory {
-
- def apply(connection: Connection, queryClass: QueryClass, query: String, params: Any*) = {
- val simplifiedQueryString = TimingOutStatsCollectingQueryFactory.simplifiedQuery(query)
- val (name, timeout, cancelOnTimeout) = queryInfo.getOrElse(simplifiedQueryString, ("default", defaultTimeout, false))
-
- new TimingOutStatsCollectingQuery(
- new TimingOutQuery(
- queryFactory(connection, queryClass, query, params: _*),
- connection,
- timeout,
- cancelOnTimeout),
- name,
- stats)
- }
-}
-
-class TimingOutStatsCollectingQuery(query: Query, queryName: String, stats: StatsCollector) extends QueryProxy(query) {
- override def select[A](f: ResultSet => A) = {
- stats.incr("db-select-count", 1)
- stats.time("db-select-timing")(delegate(query.select(f)))
- }
-
- override def execute() = {
- stats.incr("db-execute-count", 1)
- stats.time("db-execute-timing")(delegate(query.execute()))
- }
-
- override def delegate[A](f: => A) = {
- stats.incr("db-query-count-" + queryName, 1)
- stats.time("db-timing") {
- stats.time("x-db-query-timing-" + queryName) {
- f
- }
- }
- }
-}
View
9 src/main/scala/com/twitter/querulous/test/FakeDatabase.scala
@@ -5,13 +5,16 @@ import com.twitter.util.{Duration, Time}
import com.twitter.util.TimeConversions._
import com.twitter.querulous.database.Database
-class FakeDatabase(connection: Connection, latency: Duration) extends Database {
+class FakeDatabase(connection: Connection, before: Option[String => Unit]) extends Database {
+ def this(connection: Connection) = this(connection, None)
+ def this(connection: Connection, before: String => Unit) = this(connection, Some(before))
+
def open(): Connection = {
- Time.advance(latency)
+ before.foreach { _("open") }
connection
}
def close(connection: Connection) {
- Time.advance(latency)
+ before.foreach { _("close") }
}
}
View
26 src/test/scala/com/twitter/querulous/unit/AutoDisablingQueryEvaluatorSpec.scala
@@ -18,8 +18,6 @@ class AutoDisablingQueryEvaluatorSpec extends Specification with JMocker with Cl
val disableDuration = 1.minute
val queryEvaluator = new FakeQueryEvaluator(trans, List(mock[ResultSet]))
val autoDisablingQueryEvaluator = new AutoDisablingQueryEvaluator(queryEvaluator, disableErrorCount, disableDuration)
- Time.freeze()
-
"when there are no failures" >> {
autoDisablingQueryEvaluator.select("SELECT 1 FROM DUAL") { _ => 1 } mustEqual List(1)
}
@@ -60,21 +58,23 @@ class AutoDisablingQueryEvaluatorSpec extends Specification with JMocker with Cl
}
"when there are more than disableErrorCount failures but disableDuration has elapsed" >> {
- var invocationCount = 0
+ Time.withCurrentTimeFrozen { time =>
+ var invocationCount = 0
- (0 until disableErrorCount + 1) foreach { i =>
+ (0 until disableErrorCount + 1) foreach { i =>
+ autoDisablingQueryEvaluator.select("SELECT 1 FROM DUAL") { resultSet =>
+ invocationCount += 1
+ throw new SQLException
+ } must throwA[SQLException]
+ }
+ invocationCount mustEqual disableErrorCount
+
+ time.advance(1.minute)
autoDisablingQueryEvaluator.select("SELECT 1 FROM DUAL") { resultSet =>
invocationCount += 1
- throw new SQLException
- } must throwA[SQLException]
- }
- invocationCount mustEqual disableErrorCount
-
- Time.advance(1.minute)
- autoDisablingQueryEvaluator.select("SELECT 1 FROM DUAL") { resultSet =>
- invocationCount += 1
+ }
+ invocationCount mustEqual disableErrorCount + 1
}
- invocationCount mustEqual disableErrorCount + 1
}
}
}
View
2  src/test/scala/com/twitter/querulous/unit/QueryEvaluatorSpec.scala
@@ -65,7 +65,7 @@ class QueryEvaluatorSpec extends Specification with JMocker with ClassMocker {
"connection pooling" in {
val connection = mock[Connection]
- val database = new FakeDatabase(connection, 1.millis)
+ val database = new FakeDatabase(connection)
"transactionally" >> {
val queryEvaluator = new StandardQueryEvaluator(database, queryFactory)
View
15 src/test/scala/com/twitter/querulous/unit/StatsCollectingDatabaseSpec.scala
@@ -12,21 +12,24 @@ import com.twitter.util.TimeConversions._
class StatsCollectingDatabaseSpec extends Specification with JMocker with ClassMocker {
"StatsCollectingDatabase" should {
- Time.freeze()
val latency = 1.second
val connection = mock[Connection]
val stats = new FakeStatsCollector
- val pool = new StatsCollectingDatabase(new FakeDatabase(connection, latency), stats)
+ def pool(callback: String => Unit) = new StatsCollectingDatabase(new FakeDatabase(connection, callback), stats)
"collect stats" in {
"when closing" >> {
- pool.close(connection)
- stats.times("database-close-timing") mustEqual latency.inMillis
+ Time.withCurrentTimeFrozen { time =>
+ pool(s => time.advance(latency)).close(connection)
+ stats.times("database-close-timing") mustEqual latency.inMillis
+ }
}
"when opening" >> {
- pool.open()
- stats.times("database-open-timing") mustEqual latency.inMillis
+ Time.withCurrentTimeFrozen { time =>
+ pool(s => time.advance(latency)).open()
+ stats.times("database-open-timing") mustEqual latency.inMillis
+ }
}
}
}
View
28 src/test/scala/com/twitter/querulous/unit/StatsCollectingQuerySpec.scala
@@ -11,23 +11,23 @@ import com.twitter.util.TimeConversions._
class StatsCollectingQuerySpec extends Specification with JMocker {
"StatsCollectingQuery" should {
- Time.freeze()
- val latency = 1.second
- val testQuery = new FakeQuery(List(mock[ResultSet])) {
- override def select[A](f: ResultSet => A) = {
- Time.advance(latency)
- super.select(f)
- }
- }
-
"collect stats" in {
- val stats = new FakeStatsCollector
- val statsCollectingQuery = new StatsCollectingQuery(testQuery, QueryClass.Select, stats)
+ Time.withCurrentTimeFrozen { time =>
+ val latency = 1.second
+ val stats = new FakeStatsCollector
+ val testQuery = new FakeQuery(List(mock[ResultSet])) {
+ override def select[A](f: ResultSet => A) = {
+ time.advance(latency)
+ super.select(f)
+ }
+ }
+ val statsCollectingQuery = new StatsCollectingQuery(testQuery, QueryClass.Select, stats)
- statsCollectingQuery.select { _ => 1 } mustEqual List(1)
+ statsCollectingQuery.select { _ => 1 } mustEqual List(1)
- stats.counts("db-select-count") mustEqual 1
- stats.times("db-timing") mustEqual latency.inMillis
+ stats.counts("db-select-count") mustEqual 1
+ stats.times("db-timing") mustEqual latency.inMillis
+ }
}
}
}
View
2  src/test/scala/com/twitter/querulous/unit/TimingOutDatabaseSpec.scala
@@ -1,5 +1,6 @@
package com.twitter.querulous.unit
+import com.twitter.querulous._
import java.util.concurrent.{CountDownLatch, TimeUnit}
import java.sql.Connection
import com.twitter.querulous.TimeoutException
@@ -12,7 +13,6 @@ import org.specs.mock.{JMocker, ClassMocker}
class TimingOutDatabaseSpec extends Specification with JMocker with ClassMocker {
"TimingOutDatabaseSpec" should {
- Time.reset()
val latch = new CountDownLatch(1)
val timeout = 1.second
var shouldWait = false
View
54 src/test/scala/com/twitter/querulous/unit/TimingOutStatsCollectingQuerySpec.scala
@@ -1,54 +0,0 @@
-package com.twitter.querulous.unit
-
-import java.sql.ResultSet
-import org.specs.Specification
-import org.specs.mock.{ClassMocker, JMocker}
-import com.twitter.querulous.test.{FakeQuery, FakeStatsCollector}
-import com.twitter.querulous.query.TimingOutStatsCollectingQuery
-import com.twitter.util.Time
-import com.twitter.util.TimeConversions._
-
-
-class TimingOutStatsCollectingQuerySpec extends Specification with JMocker {
- "TimingOutStatsCollectingQuery" should {
- Time.freeze()
- val latency = 1.second
- val testQuery = new FakeQuery(List(mock[ResultSet])) {
- override def select[A](f: ResultSet => A) = {
- Time.advance(latency)
- super.select(f)
- }
- override def execute() = {
- Time.advance(latency)
- super.execute()
- }
- }
-
- "collect stats" in {
- val stats = new FakeStatsCollector
-
- "selects" >> {
- val query = new TimingOutStatsCollectingQuery(testQuery, "selectTest", stats)
- query.select { _ => 1 } mustEqual List(1)
- stats.times("db-select-timing") mustEqual latency.inMillis
- stats.times("x-db-query-timing-selectTest") mustEqual latency.inMillis
- stats.counts("db-select-count") mustEqual 1
- }
-
- "executes" >> {
- val query = new TimingOutStatsCollectingQuery(testQuery, "executeTest", stats)
- query.execute
- stats.times("db-execute-timing") mustEqual latency.inMillis
- stats.times("x-db-query-timing-executeTest") mustEqual latency.inMillis
- stats.counts("db-execute-count") mustEqual 1
- }
-
- "globally" >> {
- val query = new TimingOutStatsCollectingQuery(testQuery, "default", stats)
- query.select { _ => 1 } mustEqual List(1)
- stats.times("db-timing") mustEqual latency.inMillis
- }
- }
- }
-}
-
Please sign in to comment.
Something went wrong with that request. Please try again.