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

Commit

Permalink
Fix a test
Browse files Browse the repository at this point in the history
  • Loading branch information
Raghavendra Prabhu committed Mar 21, 2012
1 parent 13a18a7 commit 5e81ac4
Showing 1 changed file with 3 additions and 23 deletions.
Expand Up @@ -9,20 +9,18 @@ import com.twitter.querulous.evaluator.{QueryEvaluator, ParamsApplier, Transacti
import com.twitter.querulous.database.Database
import com.twitter.querulous.query._
import com.twitter.querulous.async._
import com.twitter.querulous.test.FakeDBConnectionWrapper

class StandardAsyncQueryEvaluatorSpec extends Specification with JMocker with ClassMocker {

val workPool = AsyncQueryEvaluator.defaultWorkPool
val checkoutPool = AsyncQueryEvaluator.checkoutPool(1)

val database = mock[Database]
val connection = mock[Connection]
val database = new FakeDBConnectionWrapper(connection)
val query = mock[Query]
val queryFactory = mock[QueryFactory]

def newEvaluator() = {
new StandardAsyncQueryEvaluator(
new BlockingDatabaseWrapper(workPool, checkoutPool, database),
new BlockingDatabaseWrapper(1, database),
queryFactory
)
}
Expand All @@ -33,35 +31,26 @@ class StandardAsyncQueryEvaluatorSpec extends Specification with JMocker with Cl
"BlockingEvaluatorWrapper" should {
"select" in {
expect {
one(database).openTimeout willReturn 500.millis
one(database).open() willReturn connection
one(queryFactory).apply(connection, QueryClass.Select, "SELECT 1") willReturn query
one(query).select(fromRow) willReturn Seq(1)
one(database).close(connection)
}

newEvaluator().select("SELECT 1")(fromRow).get()
}

"selectOne" in {
expect {
one(database).openTimeout willReturn 500.millis
one(database).open() willReturn connection
one(queryFactory).apply(connection, QueryClass.Select, "SELECT 1") willReturn query
one(query).select(fromRow) willReturn Seq(1)
one(database).close(connection)
}

newEvaluator().selectOne("SELECT 1")(fromRow).get()
}

"count" in {
expect {
one(database).openTimeout willReturn 500.millis
one(database).open() willReturn connection
one(queryFactory).apply(connection, QueryClass.Select, "SELECT 1") willReturn query
one(query).select(any[ResultSet => Int]) willReturn Seq(1)
one(database).close(connection)
}

newEvaluator().count("SELECT 1").get()
Expand All @@ -71,11 +60,8 @@ class StandardAsyncQueryEvaluatorSpec extends Specification with JMocker with Cl
val sql = "INSERT INTO foo (id) VALUES (1)"

expect {
one(database).openTimeout willReturn 500.millis
one(database).open() willReturn connection
one(queryFactory).apply(connection, QueryClass.Execute, sql) willReturn query
one(query).execute() willReturn 1
one(database).close(connection)
}

newEvaluator().execute("INSERT INTO foo (id) VALUES (1)").get()
Expand All @@ -85,12 +71,9 @@ class StandardAsyncQueryEvaluatorSpec extends Specification with JMocker with Cl
val sql = "INSERT INTO foo (id) VALUES (?)"

expect {
one(database).openTimeout willReturn 500.millis
one(database).open() willReturn connection
one(queryFactory).apply(connection, QueryClass.Execute, sql) willReturn query
one(query).addParams(1)
one(query).execute() willReturn 1
one(database).close(connection)
}

newEvaluator().executeBatch("INSERT INTO foo (id) VALUES (?)")(_(1)).get()
Expand All @@ -100,14 +83,11 @@ class StandardAsyncQueryEvaluatorSpec extends Specification with JMocker with Cl
val sql = "INSERT INTO foo (id) VALUES (1)"

expect {
one(database).openTimeout willReturn 500.millis
one(database).open() willReturn connection
one(connection).setAutoCommit(false)
one(queryFactory).apply(connection, QueryClass.Execute, sql) willReturn query
one(query).execute() willReturn 1
one(connection).commit()
one(connection).setAutoCommit(true)
one(database).close(connection)
}

newEvaluator().transaction(_.execute("INSERT INTO foo (id) VALUES (1)")).get()
Expand Down

0 comments on commit 5e81ac4

Please sign in to comment.