-
Notifications
You must be signed in to change notification settings - Fork 143
/
TransactionsSpec.scala
66 lines (61 loc) · 2.04 KB
/
TransactionsSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package redis.commands
import redis._
import scala.concurrent.Await
import akka.util.ByteString
import redis.actors.ReplyErrorException
import redis.protocol.{Bulk, Status, MultiBulk}
class TransactionsSpec extends RedisStandaloneServer {
"Transactions commands" should {
"basic" in {
val redisTransaction = redis.transaction()
redisTransaction.exec()
redisTransaction.watch("a")
val set = redisTransaction.set("a", "abc")
val decr = redisTransaction.decr("a")
val get = redisTransaction.get("a")
redisTransaction.exec()
val r = for {
s <- set
g <- get
} yield {
s mustEqual true
g mustEqual Some(ByteString("abc"))
}
Await.result(decr, timeOut) must throwA[ReplyErrorException]("ERR value is not an integer or out of range")
Await.result(r, timeOut)
}
"function api" in {
"empty" in {
val empty = redis.multi().exec()
Await.result(empty, timeOut) mustEqual MultiBulk(Some(Vector()))
}
val redisTransaction = redis.multi(redis => {
redis.set("a", "abc")
redis.get("a")
})
val exec = redisTransaction.exec()
"non empty" in {
Await.result(exec, timeOut) mustEqual MultiBulk(Some(Vector(Status(ByteString("OK")), Bulk(Some(ByteString("abc"))))))
}
"reused" in {
redisTransaction.get("transactionUndefinedKey")
val exec = redisTransaction.exec()
Await.result(exec, timeOut) mustEqual MultiBulk(Some(Vector(Status(ByteString("OK")), Bulk(Some(ByteString("abc"))), Bulk(None))))
}
"watch" in {
val transaction = redis.watch("transactionWatchKey")
transaction.watcher.result() mustEqual Set("transactionWatchKey")
transaction.unwatch()
transaction.watcher.result() must beEmpty
val set = transaction.set("transactionWatch", "value")
transaction.exec()
val r = for {
s <- set
} yield {
s must beTrue
}
Await.result(r, timeOut)
}
}
}
}