提交 adf31cc9 编写于 作者: L Lachlan O'Dea

Output tests.

上级 75e5a9cf
......@@ -58,32 +58,32 @@ trait Connection {
case object BroadcastTrackingMode extends ClientFlag
}
sealed case class ClientEvents(readable: Boolean, writable: Boolean)
sealed case class ClientEvents(readable: Boolean = false, writable: Boolean = false)
sealed case class ClientInfo(
id: Long,
name: Option[String],
address: Option[InetAddress],
localAddress: Option[InetAddress],
fileDescriptor: Option[Long],
age: Option[Duration],
idle: Option[Duration],
flags: Set[ClientFlag],
databaseId: Option[Long],
subscriptions: Int,
patternSubscriptions: Int,
multiCommands: Int,
queryBufferLength: Option[Int],
queryBufferFree: Option[Int],
outputBufferLength: Option[Int],
outputListLength: Option[Int],
outputBufferMem: Option[Long],
events: ClientEvents,
lastCommand: Option[String],
argvMemory: Option[Long],
totalMemory: Option[Long],
redirectionClientId: Option[Long],
user: Option[String]
name: Option[String] = None,
address: Option[InetAddress] = None,
localAddress: Option[InetAddress] = None,
fileDescriptor: Option[Long] = None,
age: Option[Duration] = None,
idle: Option[Duration] = None,
flags: Set[ClientFlag] = Set.empty,
databaseId: Option[Long] = None,
subscriptions: Int = 0,
patternSubscriptions: Int = 0,
multiCommands: Int = 0,
queryBufferLength: Option[Int] = None,
queryBufferFree: Option[Int] = None,
outputBufferLength: Option[Int] = None,
outputListLength: Option[Int] = None,
outputBufferMem: Option[Long] = None,
events: ClientEvents = ClientEvents(),
lastCommand: Option[String] = None,
argvMemory: Option[Long] = None,
totalMemory: Option[Long] = None,
redirectionClientId: Option[Long] = None,
user: Option[String] = None
)
sealed abstract class ClientTrackingRedirect
......
package zio.redis
import java.net.InetAddress
import zio.duration._
import zio.redis.Output._
import zio.redis.RedisError._
......@@ -17,6 +19,8 @@ object OutputSpec extends BaseSpec {
private def respArrayVals(xs: RespValue*) = RespValue.Array(Chunk.fromIterable(xs))
private def respInt(i: Long) = RespValue.Integer(i)
def spec =
suite("Output decoders")(
suite("errors")(
......@@ -243,6 +247,79 @@ object OutputSpec extends BaseSpec {
res <- Task(ChunkOptionalLongOutput.unsafeDecode(input))
} yield assert(res)(equalTo(Chunk(Some(1L), Some(1L), Some(2L), Some(3L))))
}
),
suite("ClientInfo")(
testM("addresses") {
val id = 42L
val inetAddress = InetAddress.getByName("127.0.0.1")
val input = respBulkString(s"addr=${inetAddress.getHostAddress} id=$id laddr=${inetAddress.getHostAddress}")
for {
res <- Task(ClientInfoOutput.unsafeDecode(input))
} yield assert(res)(
equalTo(Chunk.single(ClientInfo(id = id, address = Some(inetAddress), localAddress = Some(inetAddress))))
)
},
testM("flags") {
import ClientFlag._
val id = 42L
val input = respBulkString(s"flags=bOPSRt id=$id")
val expectedFlags: Set[ClientFlag] = Set(
Blocked,
MonitorMode,
PubSub,
Replica,
TrackingTargetClientInvalid,
KeysTrackingEnabled
)
for {
res <- Task(ClientInfoOutput.unsafeDecode(input))
} yield assert(res)(equalTo(Chunk.single(ClientInfo(id = id, flags = expectedFlags))))
},
testM("ignores unknown flags") {
val id = 42L
val input = respBulkString(s"flags=XYZ id=$id")
for {
res <- Task(ClientInfoOutput.unsafeDecode(input))
} yield assert(res)(equalTo(Chunk.single(ClientInfo(id = id, flags = Set.empty))))
},
testM("multiple") {
val input = respBulkString(
s"""sub=4 id=42 idle=6 fd=9234
|id=99 events=r db=33
|id=1 cmd=foo""".stripMargin
)
for {
res <- Task(ClientInfoOutput.unsafeDecode(input))
} yield assert(res)(
equalTo(
Chunk(
ClientInfo(id = 42L, idle = Some(6.seconds), subscriptions = 4, fileDescriptor = Some(9234L)),
ClientInfo(id = 99, events = ClientEvents(readable = true), databaseId = Some(33L)),
ClientInfo(id = 1, lastCommand = Some("foo"))
)
)
)
}
),
suite("ClientTrackingRedirect")(
testM("Not enabled") {
val input = respInt(-1L)
for {
res <- Task(ClientTrackingRedirectOutput.unsafeDecode(input))
} yield assert(res)(equalTo(ClientTrackingRedirect.NotEnabled))
},
testM("Not redirected") {
val input = respInt(0L)
for {
res <- Task(ClientTrackingRedirectOutput.unsafeDecode(input))
} yield assert(res)(equalTo(ClientTrackingRedirect.NotRedirected))
},
testM("redirected") {
val input = respInt(42L)
for {
res <- Task(ClientTrackingRedirectOutput.unsafeDecode(input))
} yield assert(res)(equalTo(ClientTrackingRedirect.RedirectedTo(input.value)))
}
)
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册