From 7f327d4849e921fb5656e79a44864bdffcd9c1cc Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Thu, 19 Jun 2014 16:18:28 -0500 Subject: [PATCH 01/10] finagle-redis tests need refactoring to from specs2 to scalatest The refactoring required for replacing all specs tests with scalatests requires a few intermediate code reviews. This commit removes none of the original tests, but adds refacorted tests from the Naggati codec and the Client Integration tests. Code review is needed before continuing. --- .../finagle/redis/FinagleRedisTest.scala | 71 +++++++ .../com/twitter/finagle/redis/Tags.scala | 8 + .../client/SimpleClientSuite.scala | 172 +++++++++++++++ .../requests/RequestEncodingSuite.scala | 26 +++ .../requests/commands/KeyCommandsSuite.scala | 200 ++++++++++++++++++ 5 files changed, 477 insertions(+) create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/FinagleRedisTest.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/Tags.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/client/SimpleClientSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/RequestEncodingSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/commands/KeyCommandsSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/FinagleRedisTest.scala new file mode 100644 index 00000000000..84e9c39686a --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/FinagleRedisTest.scala @@ -0,0 +1,71 @@ +package com.twitter.finagle.redis.naggati + +import com.twitter.finagle.builder.ClientBuilder +import com.twitter.finagle.redis.naggati.test.TestCodec +import com.twitter.finagle.redis.protocol._ +import com.twitter.finagle.redis.util.{CBToString, RedisCluster, ReplyFormat, StringToChannelBuffer} +import com.twitter.finagle.redis.{Redis, TransactionalClient} +import com.twitter.util.Await +import org.jboss.netty.buffer.ChannelBuffer +import org.scalatest.{BeforeAndAfterAll, FunSuite} + +trait FinagleRedisTest extends FunSuite { + protected def wrap(s: String): ChannelBuffer = StringToChannelBuffer(s) + protected def string2ChanBuf(s: String): ChannelBuffer = wrap(s) + + protected val foo = StringToChannelBuffer("foo") + protected val bar = StringToChannelBuffer("bar") + protected val baz = StringToChannelBuffer("baz") + protected val boo = StringToChannelBuffer("boo") + protected val moo = StringToChannelBuffer("moo") + +} + +trait FinagleRedisResponseTest extends FinagleRedisTest { + protected val replyCodec = new ReplyCodec + protected val (codec, counter) = TestCodec(replyCodec.decode, replyCodec.encode) +} + +trait FinagleRedisRequestTest extends FinagleRedisTest { + protected val commandCodec = new CommandCodec + protected val (codec, counter) = TestCodec(commandCodec.decode, commandCodec.encode) + + + def unwrap(list: Seq[AnyRef])(fn: PartialFunction[Command,Unit]) = list.toList match { + case head :: Nil => head match { + case c: Command => fn.isDefinedAt(c) match { + case true => fn(c) + case false => fail("Didn't find expected type in list: %s".format(c.getClass)) + } + case _ => fail("Expected to find a command in the list") + } + case _ => fail("Expected single element list") + } +} + +trait FinagleRedisClientSuite extends FinagleRedisTest with BeforeAndAfterAll { + + override def beforeAll(configMap: Map[String, Any]): Unit = { + RedisCluster.start() + } + + override def afterAll(configMap: Map[String, Any]): Unit = { + RedisCluster.stop() + } + + protected def withRedisClient(testCode: TransactionalClient => Any) { + val client = TransactionalClient( + ClientBuilder() + .codec(new Redis()) + .hosts(RedisCluster.hostAddresses()) + .hostConnectionLimit(1) + .buildFactory()) + Await.result(client.flushDB()) + try { + testCode(client) + } + finally { + client.release + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/Tags.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/Tags.scala new file mode 100644 index 00000000000..c5115e7e08d --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/Tags.scala @@ -0,0 +1,8 @@ +package com.twitter.finagle.redis.tags + +import org.scalatest.Tag + +object RedisTest extends Tag("com.twitter.finagle.redis.tags.RedisTest") +object IntegrationTest extends Tag("com.twitter.finagle.redis.tags.IntegrationTest") +object SlowTest extends Tag("com.twitter.finagle.redis.tags.SlowTest") +object CodecTest extends Tag("com.twitter.finagle.redis.tags.CodecTest") diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/client/SimpleClientSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/client/SimpleClientSuite.scala new file mode 100644 index 00000000000..733abcc4253 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/client/SimpleClientSuite.scala @@ -0,0 +1,172 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.util.Await +import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} + +final class SimpleClientSuite extends FinagleRedisClientSuite { + + test("Correctly perform the APPEND command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + val actualResult = Await.result(client.append(foo, baz)) + val expectedResult = 6 + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the DECRBY command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, StringToChannelBuffer("21"))) + val actualResult = Await.result(client.decrBy(foo, 2)) + val expectedResult = 19 + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the DEL command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + Await.result(client.del(Seq(foo))) + val actualResult = Await.result(client.get(foo)) + val expectedResult = None + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the EXISTS command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + val actualResult = Await.result(client.exists(foo)) + val expectedResult = true + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the GETRANGE command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, StringToChannelBuffer("boing"))) + val actualResult = CBToString(Await.result(client.getRange(foo, 0, 2)).get) + val expectedResult = "boi" + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the GET & SET commands", RedisTest, SlowTest) { + withRedisClient { client => + val actualEmptyGetResult = Await.result(client.get(foo)) + val expectedEmptyGetResult = None + assert(actualEmptyGetResult === expectedEmptyGetResult) + + Await.result(client.set(foo, bar)) + val actualGetResult = CBToString(Await.result(client.get(foo)).get) + val expectedGetResult = "bar" + assert(actualGetResult === expectedGetResult) + } + } + + test("Correctly perform the FLUSH command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + Await.result(client.flushDB()) + val actualResult = Await.result(client.get(foo)) + val expectedResult = None + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the SELECT command", RedisTest, SlowTest) { + withRedisClient { client => + val actualResult =Await.result(client.select(1)) + val expectedResult = () + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the INFO command", RedisTest, SlowTest) { + withRedisClient { client => + val info = new String(Await.result(client.info()).get.array, "UTF8") + val hasServer = info.contains("# Server") + assert(hasServer === true) + val hasRedisVersion = info.contains("redis_version:") + assert(hasRedisVersion === true) + val hasClients = info.contains("# Clients") + assert(hasClients === true) + + val cpu = new String(Await.result(client.info(StringToChannelBuffer("cpu"))).get.array, "UTF8") + val hasCpu = cpu.contains("# CPU") + assert(hasCpu === true) + val hasUsedCpuSys = cpu.contains("used_cpu_sys:") + assert(hasUsedCpuSys === true) + val cpuHasRedisVersion = cpu.contains("redis_version:") + assert(cpuHasRedisVersion === false) + } + } + + test("Correctly perform the QUIT command", RedisTest, SlowTest) { + withRedisClient { client => + val actualResult = Await.result(client.quit()) + val expectedResult = () + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the TTL command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + val time = 20L + + val actualExpireEvent = Await.result(client.expire(foo, time)) + val expectedExpireEvent = true + assert(actualExpireEvent === expectedExpireEvent) + + val result = Await.result(client.ttl(foo)) match { + case Some(num) => num + case None => fail("Could not retrieve key for TTL test") + } + val actualResult = if(result <= time) true else false + val expectedResult = true + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the EXPIREAT command", RedisTest, SlowTest) { + withRedisClient { client => + val ttl = System.currentTimeMillis() + 20000L + Await.result(client.set(foo, bar)) + val actualExpireAtEvent = Await.result(client.expireAt(foo, ttl)) + val expectedExpireAtEvent = true + assert(actualExpireAtEvent === expectedExpireAtEvent) + + val result = Await.result(client.ttl(foo)) match { + case Some(num) => num + case None => fail("Could not retrieve key for TTL") + } + val actualResult = if(result <= ttl) true else false + val expectedResult = true + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the MOVE command", RedisTest, SlowTest) { + withRedisClient { client => + val fromDb = 14 + val toDb = 15 + Await.result(client.select(toDb)) + Await.result(client.del(Seq(foo))) + Await.result(client.select(fromDb)) + + val actualEmptyKeyResult = Await.result(client.move(foo, bar)) + val expectedEmptyKeyResult = false + assert(actualEmptyKeyResult === expectedEmptyKeyResult) + + Await.result(client.set(foo, bar)) + val actualResult = Await.result(client.move(foo, StringToChannelBuffer(toDb.toString))) + val expectedResult = true + assert(actualResult === expectedResult) + + Await.result(client.del(Seq(foo))) // clean up + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/RequestEncodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/RequestEncodingSuite.scala new file mode 100644 index 00000000000..d82cc5b4ebc --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/RequestEncodingSuite.scala @@ -0,0 +1,26 @@ +package com.twitter.finagle.redis.protocol + +import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.tags.CodecTest + +final class RequestEncodingSuite extends FinagleRedisRequestTest { + + test("Correctly encode inline requests", CodecTest) { + val actualEncoding = codec.send(Get(foo)) + val expectedEncoding = List("*2\r\n$3\r\nGET\r\n$3\r\nfoo\r\n") + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode unified requests", CodecTest) { + val value = "bar\r\nbaz" + val actualEncoding = codec.send(Set(foo, string2ChanBuf(value))) + val expectedEncoding = List("*3\r\n$3\r\nSET\r\n$3\r\nfoo\r\n$%d\r\n%s\r\n".format(8, value)) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode a HSet request with an empty string as value", CodecTest) { + val actualEncoding = codec.send(HSet(foo, bar, string2ChanBuf(""))) + val expectedEncoding = List("*4\r\n$4\r\nHSET\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$0\r\n\r\n") + assert(actualEncoding === expectedEncoding) + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/commands/KeyCommandsSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/commands/KeyCommandsSuite.scala new file mode 100644 index 00000000000..5ef1725a27e --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/commands/KeyCommandsSuite.scala @@ -0,0 +1,200 @@ +package com.twitter.finagle.redis.protocol + +import com.twitter.conversions.time._ +import com.twitter.finagle.redis.ClientError +import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.tags.CodecTest +import com.twitter.util.Time + +final class KeyCommandSuite extends FinagleRedisRequestTest { + + test("Correctly encode DELETE for one key", CodecTest) { + val actualEncoding = codec(wrap("DEL foo\r\n")) + val expectedEncoding = List(Del(List(foo))) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode DELETE for two keys", CodecTest) { + val actualEncoding = codec(wrap("DEL foo bar\r\n")) + val expectedEncoding = List(Del(List(foo, bar))) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if DELETE is called with no key") { + intercept[ClientError] { + codec(wrap("DEL\r\n")) + } + } + + test("Correctly encode EXISTS for one key", CodecTest) { + val actualEncoding = codec(wrap("EXISTS foo\r\n")) + val expectedEncoding = List(Exists(foo)) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if EXISTS is called with no key") { + intercept[ClientError] { + codec(wrap("EXISTS\r\n")) + } + } + + test("Correctly encode EXPIRE for one key in 100 seconds", CodecTest) { + val actualEncoding = codec(wrap("EXPIRE moo 100\r\n")) + val expectedEncoding = List(Expire(moo, 100)) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode one key to never EXPIRE", CodecTest) { + val actualEncoding = codec(wrap("EXPIRE baz -1\r\n")) + val expectedEncoding = List(Expire(baz, -1)) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode one key to EXPIREAT at future timestamp", CodecTest) { + val actualEncoding = codec(wrap("EXPIREAT moo 100\r\n")) + val expectedEncoding = List(ExpireAt(moo, Time.fromMilliseconds(100*1000))) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode one key to EXPIREAT a future interpolated timestamp", CodecTest) { + val time = Time.now + 10.seconds + val expectedTimestamp = time.inSeconds + unwrap(codec(wrap("EXPIREAT foo %d\r\n".format(time.inSeconds)))) { + case ExpireAt(foo, timestamp) => { + val actualTimestamp = timestamp.inSeconds + assert(actualTimestamp === expectedTimestamp) + } + } + } + + test("Correctly encode a KEYS pattern", CodecTest) { + val actualEncoding = codec(wrap("KEYS h?llo\r\n")) + val expectedEncoding = List(Keys(string2ChanBuf("h?llo"))) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode MOVE for one key to another database", CodecTest) { + val actualEncoding = codec(wrap("MOVE boo moo \r\n")) + val expectedEncoding = List(Move(boo, moo)) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if MOVE is called with no key or database", CodecTest) { + intercept[ClientError] { + codec(wrap("MOVE\r\n")) + } + } + + test("Throw a ClientError if MOVE is called with a key but no database", CodecTest) { + intercept[ClientError] { + codec(wrap("MOVE foo\r\n")) + } + } + + test("Correctly encode PERSIST for one key", CodecTest) { + val actualEncoding = codec(wrap("PERSIST foo\r\n")) + val expectedEncoding =List(Persist(foo)) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if Persist is called without a key", CodecTest) { + intercept[ClientError] { + codec(wrap("PERSIST\r\n")) + } + } + + test("Correctly encode PEXPIRE for one key in 100 seconds", CodecTest) { + val actualEncoding = codec(wrap("PEXPIRE foo 100000\r\n")) + val expectedEncoding = List(PExpire(foo, 100000L)) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode one key to never PEXPIRE", CodecTest) { + val actualEncoding = codec(wrap("PEXPIRE baz -1\r\n")) + val expectedEncoding = List(PExpire(baz, -1L)) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode one key to PEXPIREAT at a future timestamp", CodecTest) { + val actualEncoding = codec(wrap("PEXPIREAT boo 100000\r\n")) + val expectedEncoding = List(PExpireAt(boo, Time.fromMilliseconds(100000))) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode one key to PEXPIREAT at a future interpolated timestamp", CodecTest) { + val time = Time.now + 10.seconds + val expectedTimestamp = time.inMilliseconds + unwrap(codec(wrap("PEXPIREAT foo %d\r\n".format(time.inMilliseconds)))) { + case PExpireAt(foo, timestamp) => { + val actualTimestamp = timestamp.inMilliseconds + assert(actualTimestamp === expectedTimestamp) + } + } + } + + test("Correctly encode a PTTL, time to live in milliseconds, for a key", CodecTest) { + val actualEncoding = codec(wrap("PTTL foo\r\n")) + val expectedEncoding = List(PTtl(foo)) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if RENAME is called with no arguments", CodecTest) { + intercept[ClientError] { + codec(wrap("RENAME\r\n")) + } + } + + test("Throw a ClientError if RENAME is called without a second argument", CodecTest) { + intercept[ClientError] { + codec(wrap("RENAME foo\r\n")) + } + } + + test("Correctly encode RENAME of one key to another", CodecTest) { + val actualEncoding = codec(wrap("RENAME foo bar\r\n")) + val expectedEncoding = List(Rename(foo, bar)) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if RENAMEX is called with no arguments", CodecTest) { + intercept[ClientError] { + codec(wrap("RENAMENX\r\n")) + } + } + + test("Throw a ClientError if RENAMEX is called without a second argument", CodecTest) { + intercept[ClientError] { + codec(wrap("RENAMENX foo\r\n")) + } + } + + test("Correctly encode RENAMEX of one key to another", CodecTest) { + val actualEncoding = codec(wrap("RENAMENX foo bar\r\n")) + val expectedEncoding = List(RenameNx(foo, bar)) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode a request for a RANDOMKEY", CodecTest) { + val actualEncoding = codec(wrap("RANDOMKEY\r\n")) + val expectedEncoding = List(Randomkey()) + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode a TTL, time to live in seconds, for a key", CodecTest) { + val actualEncoding = codec(wrap("TTL foo\r\n")) + val expectedEncoding = List(Ttl(foo)) + assert(actualEncoding === expectedEncoding) + } + + test("Throw a ClientError if TYPE is called with no key", CodecTest) { + intercept[ClientError] { + codec(wrap("TYPE\r\n")) + } + } + + test("Correctly encode a TYPE request for a provided key", CodecTest) { + val actualEncoding = codec(wrap("TYPE foo\r\n")) + val expectedEncoding = List(Type(foo)) + assert(actualEncoding === expectedEncoding) + } +} From f782176f9030312505086d3550b743321db58380 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Fri, 20 Jun 2014 10:15:13 -0500 Subject: [PATCH 02/10] Original tests should be separated from WIP tests. As part of the ongoing Specs2 to Scalatest refactoring for finagle-redis, I have separated out the original test code from the ongoing Scalatest code. --- .../scala/com/twitter/finagle/redis/{ => orig}/NaggatiSpec.scala | 0 .../finagle/redis/{ => orig}/integration/BtreeClientSpec.scala | 0 .../{ => orig}/integration/ClientServerIntegrationSpec.scala | 0 .../twitter/finagle/redis/{ => orig}/integration/ClientSpec.scala | 0 .../com/twitter/finagle/redis/{ => wip}/FinagleRedisTest.scala | 0 .../src/test/scala/com/twitter/finagle/redis/{ => wip}/Tags.scala | 0 .../redis/{integration => wip}/client/SimpleClientSuite.scala | 0 .../redis/{ => wip}/naggati/requests/RequestEncodingSuite.scala | 0 .../{ => wip}/naggati/requests/commands/KeyCommandsSuite.scala | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => orig}/NaggatiSpec.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => orig}/integration/BtreeClientSpec.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => orig}/integration/ClientServerIntegrationSpec.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => orig}/integration/ClientSpec.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => wip}/FinagleRedisTest.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => wip}/Tags.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{integration => wip}/client/SimpleClientSuite.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => wip}/naggati/requests/RequestEncodingSuite.scala (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/{ => wip}/naggati/requests/commands/KeyCommandsSuite.scala (100%) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/NaggatiSpec.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/NaggatiSpec.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/NaggatiSpec.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/NaggatiSpec.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/BtreeClientSpec.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/integration/BtreeClientSpec.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/BtreeClientSpec.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/integration/BtreeClientSpec.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/ClientServerIntegrationSpec.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/integration/ClientServerIntegrationSpec.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/ClientServerIntegrationSpec.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/integration/ClientServerIntegrationSpec.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/ClientSpec.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/integration/ClientSpec.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/ClientSpec.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/orig/integration/ClientSpec.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/FinagleRedisTest.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/Tags.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/Tags.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/Tags.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/Tags.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/client/SimpleClientSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/client/SimpleClientSuite.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/integration/client/SimpleClientSuite.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/client/SimpleClientSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/RequestEncodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/RequestEncodingSuite.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/RequestEncodingSuite.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/RequestEncodingSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/commands/KeyCommandsSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/commands/KeyCommandsSuite.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/naggati/requests/commands/KeyCommandsSuite.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/commands/KeyCommandsSuite.scala From 6567d6ac26695065e7b8da083c778d3c77274d87 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Fri, 20 Jun 2014 10:30:19 -0500 Subject: [PATCH 03/10] Refactored finagle-redis test WIP folder into future strucutre. All future scalatests for finagle-redis will fall into the folder tree of either a codec or a command, and then the proper tests underneath those layers, Codec / Client / ClientServer --- .../RequestEncodingSuite.scala | 0 .../wip/codec/ResponseDecodingSuite.scala | 304 ++++++++++++++++++ .../wip/codec/ResponseEncodingSuite.scala | 47 +++ .../keys/KeyClientIntegrationSuite.scala} | 0 .../keys/KeyCodecSuite.scala} | 0 5 files changed, 351 insertions(+) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/{naggati/requests => codec}/RequestEncodingSuite.scala (100%) create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala rename finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/{client/SimpleClientSuite.scala => commands/keys/KeyClientIntegrationSuite.scala} (100%) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/{naggati/requests/commands/KeyCommandsSuite.scala => commands/keys/KeyCodecSuite.scala} (100%) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/RequestEncodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/RequestEncodingSuite.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/RequestEncodingSuite.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/RequestEncodingSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala new file mode 100644 index 00000000000..f8d0ec2a620 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala @@ -0,0 +1,304 @@ +package com.twitter.finagle.redis.naggati + +import com.twitter.conversions.time._ +import com.twitter.finagle.redis.{ClientError, ServerError} +import com.twitter.finagle.redis.naggati.test._ +import com.twitter.finagle.redis.util._ +import com.twitter.util.Time +import org.specs.SpecificationWithJUnit +import org.jboss.netty.buffer.ChannelBuffer +import com.twitter.finagle.redis.protocol.{BulkReply, ErrorReply, IntegerReply, MBulkReply, + StatusReply, ReplyCodec} +import com.twitter.finagle.redis.util.StringToChannelBuffer +import org.jboss.netty.buffer.ChannelBuffer +import org.scalatest.FunSuite +import com.twitter.finagle.redis.protocol.{EmptyBulkReply, EmptyMBulkReply} + +final class ResponseDecodingSuite extends FinagleRedisResponseTest { + ignore("Multi-bulk replies") { + val actualEncoding = codec(wrap("*4\r\n")) + val expectedEncoding = Nil + assert(actualEncoding === expectedEncoding) + } + + ignore("Correctly decode faulty") { + val actualEncoding = codec(wrap("$3\r\n")) + val expectedEncoding = Nil + assert(actualEncoding === expectedEncoding) + } + + ignore("Correctly decode ") { + val actualEncoding = Nil + val expectedEncoding = Nil + assert(actualEncoding === expectedEncoding) + } + + + /*"multi-bulk replies" >> { + codec(wrap("*4\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("foo\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("bar\r\n")) mustEqual Nil + codec(wrap("$5\r\n")) mustEqual Nil + codec(wrap("Hello\r\n")) mustEqual Nil + codec(wrap("$5\r\n")) mustEqual Nil + codec(wrap("World\r\n")) match { + case reply :: Nil => reply match { + case MBulkReply(msgs) => + ReplyFormat.toString(msgs) mustEqual List("foo","bar","Hello","World") + case _ => fail("Expected MBulkReply") + } + case _ => fail("Expected one element in list") + } + + codec(wrap("*3\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("foo\r\n")) mustEqual Nil + codec(wrap("$-1\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("bar\r\n")) match { + case reply :: Nil => reply match { + case MBulkReply(msgs) => + ReplyFormat.toString(msgs) mustEqual List( + "foo", + "nil", + "bar") + case _ => fail("Expected MBulkReply") + } + case _ => fail("Expected one element in list") + } + + codec(wrap("*4\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("foo\r\n")) mustEqual Nil + codec(wrap("$0\r\n")) mustEqual Nil + codec(wrap("\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("moo\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("bar\r\n")) match { + case reply :: Nil => reply match { + case MBulkReply(msgs) => + ReplyFormat.toString(msgs) mustEqual List( + "foo", + "", + "moo", + "bar") + case _ => fail("Expected MBulkReply") + } + case _ => fail("Expected one element in list") + } + + } + "nested multi-bulk replies" >> { + codec(wrap("*3\r\n")) mustEqual Nil + codec(wrap(":1\r\n")) mustEqual Nil + codec(wrap("*2\r\n")) mustEqual Nil + codec(wrap("$3\r\n")) mustEqual Nil + codec(wrap("one\r\n")) mustEqual Nil + codec(wrap("$5\r\n")) mustEqual Nil + codec(wrap("three\r\n")) mustEqual Nil + codec(wrap(":3\r\n")) match { + case reply :: Nil => reply match { + case MBulkReply(List(a, b, c)) => + a mustEqual IntegerReply(1) + b match { + case MBulkReply(xs) => + ReplyFormat.toString(xs) mustEqual List("one", "three") + case xs => fail("Expected MBulkReply, got: %s" format xs) + } + c mustEqual IntegerReply(3) + case xs => fail("Expected 3-element MBulkReply, got: %s" format xs) + } + case xs => fail("Expected one reply, got: %s" format xs) + } + + codec(wrap("*4\r\n")) mustEqual Nil + codec(wrap(":0\r\n")) mustEqual Nil + codec(wrap(":1\r\n")) mustEqual Nil + codec(wrap("*3\r\n")) mustEqual Nil + codec(wrap(":10\r\n")) mustEqual Nil + codec(wrap("*0\r\n")) mustEqual Nil + codec(wrap("*2\r\n")) mustEqual Nil + codec(wrap("*0\r\n")) mustEqual Nil + codec(wrap(":100\r\n")) mustEqual Nil + codec(wrap(":2\r\n")) match { + case reply :: Nil => reply match { + case MBulkReply(List(a, b, c, d)) => + a mustEqual IntegerReply(0) + b mustEqual IntegerReply(1) + c match { + case MBulkReply(List(aa, ab, ac)) => + aa mustEqual IntegerReply(10) + ab mustEqual EmptyMBulkReply() + ac match { + case MBulkReply(List(aaa, aab)) => + aaa mustEqual EmptyMBulkReply() + aab mustEqual IntegerReply(100) + case xs => fail("Expected 2-element MBulkReply, got: %s" format xs) + } + case xs => fail("Expected 3-element, got: %s" format xs) + } + d mustEqual IntegerReply(2) + case xs => fail("Expected 4-element MBulkReply, got: %s" format xs) + } + case xs => fail("Expected one reply, got: %s" format xs) + } + } +}*/ + ignore("Correctly decode OK status reply") { + val actualDecoding = codec(wrap("+OK\r\n")) + val expectedDecoding = List(StatusReply("OK")) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode OK status reply with message") { + val actualDecoding = codec(wrap("+OK\r\n+Hello World\r\n")) + val expectedDecoding = List(StatusReply("OK"), StatusReply("Hello World")) + assert(actualDecoding === expectedDecoding) + } + + ignore("Throw ServerError when decoding BLANK OK reply") { + intercept[ServerError] { + codec(wrap("+\r\n")) + } + } + + ignore("Correctly decode BAD error reply") { + val actualDecoding = codec(wrap("-BAD\r\n")) + val expectedDecoding = List(ErrorReply("BAD")) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode BAD error reply with message") { + val actualDecoding = codec(wrap("-BAD\r\n-Bad Thing\r\n")) + val expectedDecoding = List(ErrorReply("BAD"), ErrorReply("Bad Thing")) + assert(actualDecoding === expectedDecoding) + } + + ignore("Throw ServerError when decoding BLANK error reply") { + intercept[ServerError] { + codec(wrap("-\r\n")) + } + } + + ignore("Correctly decode negative integer reply") { + val actualDecoding = codec(wrap(":-2147483648\r\n")) + val expectedDecoding = List(IntegerReply(-2147483648)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode zero integer reply") { + val actualDecoding = codec(wrap(":0\r\n")) + val expectedDecoding = List(IntegerReply(0)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode positive integer reply") { + val actualDecoding = codec(wrap(":2147483647\r\n")) + val expectedDecoding = List(IntegerReply(2147483647)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode positive integer to long reply") { + val actualDecoding = codec(wrap(":2147483648\r\n")) + val expectedDecoding = List(IntegerReply(2147483648L)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode negative integer to long reply") { + val actualDecoding = codec(wrap(":-2147483649\r\n")) + val expectedDecoding = List(IntegerReply(-2147483649L)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode Long.MaxValue reply") { + val actualDecoding = codec(wrap(":9223372036854775807\r\n")) + val expectedDecoding = List(IntegerReply(9223372036854775807L)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Throw ServerError when decoding Long.MaxValue + 1") { + intercept[ServerError] { + codec(wrap(":9223372036854775808\r\n")) + } + } + + ignore("Correctly decode Long.MinValue") { + val actualDecoding = codec(wrap(":-9223372036854775807\r\n")) + val expectedDecoding = List(IntegerReply(-9223372036854775807L)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Throw ServerError when decoding Long.MinValue -1") { + intercept[ServerError] { + codec(wrap(":-9223372036854775809\r\n")) + } + } + + ignore("Correctly decode multiple integers in one reply") { + val actualDecoding = codec(wrap(":1\r\n:2\r\n")) + val expectedDecoding = List(IntegerReply(1), IntegerReply(2)) + assert(actualDecoding === expectedDecoding) + } + + ignore("Throw ServerError when decoding BLANK integer reply") { + intercept[ServerError] { + codec(wrap(":\r\n")) + } + } + + ignore("Correctly decode single word bulk reply") { + val actualDecoding = decomposeSingleElemDecoding(codec(wrap("$3\r\nfoo\r\n"))) + val expectedDecoding = "foo" + assert(actualDecoding._1 === expectedDecoding, actualDecoding._2) + } + + ignore("Correctly decode multi word bulk reply") { + val actualDecoding = decomposeSingleElemDecoding(codec(wrap("$8\r\nfoo\r\nbar\r\n"))) + val expectedDecoding = "foo\r\nbar" + assert(actualDecoding._1 === expectedDecoding, actualDecoding._2) + } + + ignore("Correctly decodec multi line reply") { + val actualDecoding = decomposeMultiElemDecoding(codec(wrap("$3\r\nfoo\r\n$3\r\nbar\r\n"))) + val expectedDecoding = ("foo", "bar") + assert(actualDecoding === expectedDecoding) + } + + ignore("Correctly decode EMPTY bulk reply") { + val actualDecodingClass = codec(wrap("$-1\r\n")).head.getClass + val expectedDecodingClass = classOf[EmptyBulkReply] + assert(actualDecodingClass === expectedDecodingClass) + } + + ignore("Correctly decode empty multi-bulk replies") { + val actualEmptyDecoding = codec(wrap("*0\r\n")).head.getClass + val expectedEmptyDecoding = classOf[EmptyMBulkReply] + assert(actualEmptyDecoding === expectedEmptyDecoding) + } + + private[this] def decomposeSingleElemDecoding(reply: List[AnyRef]): (String, String) = reply match { + case reply :: Nil => reply match { + case BulkReply(msg) => (CBToString(msg), "") + case _ => ("USE FAILURE MSG, NOT THIS VALUE", "Expected BulkReply, got something else") + } + case _ => ("USE FAILURE MSG, NOT THIS VALUE", "Found no or multiple reply lines") + } + + private[this] def decomposeMultiElemDecoding(reply: List[AnyRef]): (String, String) = reply match { + case fooR :: booR :: Nil => { + val fooMsg = fooR match { + case BulkReply(msg) => CBToString(msg) + case _ => "Expected Bulk Reply" + } + val barMsg = booR match { + case BulkReply(msg) => CBToString(msg) + case _ => "Expected Bulk Reply" + } + (fooMsg, barMsg) + } + case _ => fail("Expected two element in list") + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala new file mode 100644 index 00000000000..1ee891ddde5 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala @@ -0,0 +1,47 @@ +package com.twitter.finagle.redis.naggati + +import com.twitter.finagle.redis.protocol.{BulkReply, ErrorReply, IntegerReply, MBulkReply, + StatusReply, ReplyCodec} +import com.twitter.finagle.redis.tags.CodecTest +import com.twitter.finagle.redis.util.StringToChannelBuffer + +final class ResponseEncodingSuite extends FinagleRedisResponseTest { + + test("Correctly encode status replies", CodecTest) { + val actualEncoding = codec.send(StatusReply("OK")) + val expectedEncoding = List("+OK\r\n") + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode error replies", CodecTest) { + val actualEncoding = codec.send(ErrorReply("BAD")) + val expectedEncoding = List("-BAD\r\n") + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode positive integer replies", CodecTest) { + val actualEncoding = codec.send(IntegerReply(123)) + val expectedEncoding = List(":123\r\n") + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode negative integer replies", CodecTest) { + val actualEncoding = codec.send(IntegerReply(-123)) + val expectedEncoding = List(":-123\r\n") + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode bulk replies", CodecTest) { + val actualEncoding = codec.send(BulkReply(StringToChannelBuffer("foo\r\nbar"))) + val expectedEncoding = List("$8\r\nfoo\r\nbar\r\n") + assert(actualEncoding === expectedEncoding) + } + + test("Correctly encode multi bulk replies", CodecTest) { + val messages = List(BulkReply(StringToChannelBuffer("foo")), + BulkReply(StringToChannelBuffer("bar"))) + val actualEncoding = codec.send(MBulkReply(messages)) + val expectedEncoding = List("*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n") + assert(actualEncoding === expectedEncoding) + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/client/SimpleClientSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/client/SimpleClientSuite.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/commands/KeyCommandsSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala similarity index 100% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/naggati/requests/commands/KeyCommandsSuite.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala From 1e6f859c92f8d82ca5f1401844fb4cad6952d380 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Fri, 20 Jun 2014 12:36:01 -0500 Subject: [PATCH 04/10] Refactored finagle-redis SimpleClientSuite into comand based hierarchy for tests --- .../ConnectionClientIntegrationSuite.scala | 25 ++++ .../keys/KeyClientIntegrationSuite.scala | 125 ++++++------------ .../KeyClientServerIntegrationSuite.scala | 6 + .../wip/commands/keys/KeyCodecSuite.scala | 2 +- .../server/ServerClientIntegrationSuite.scala | 39 ++++++ .../StringClientIntegrationSuite.scala | 50 +++++++ 6 files changed, 159 insertions(+), 88 deletions(-) create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala new file mode 100644 index 00000000000..2894c8fb6e6 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala @@ -0,0 +1,25 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.util.Await +import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} + +final class ConnectionClientIntegrationSuite extends FinagleRedisClientSuite { + + test("Correctly perform the SELECT command", RedisTest, SlowTest) { + withRedisClient { client => + val actualResult =Await.result(client.select(1)) + val expectedResult = () + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the QUIT command", RedisTest, SlowTest) { + withRedisClient { client => + val actualResult = Await.result(client.quit()) + val expectedResult = () + assert(actualResult === expectedResult) + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala index 733abcc4253..91dda400719 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala @@ -5,25 +5,7 @@ import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} -final class SimpleClientSuite extends FinagleRedisClientSuite { - - test("Correctly perform the APPEND command", RedisTest, SlowTest) { - withRedisClient { client => - Await.result(client.set(foo, bar)) - val actualResult = Await.result(client.append(foo, baz)) - val expectedResult = 6 - assert(actualResult === expectedResult) - } - } - - test("Correctly perform the DECRBY command", RedisTest, SlowTest) { - withRedisClient { client => - Await.result(client.set(foo, StringToChannelBuffer("21"))) - val actualResult = Await.result(client.decrBy(foo, 2)) - val expectedResult = 19 - assert(actualResult === expectedResult) - } - } +final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { test("Correctly perform the DEL command", RedisTest, SlowTest) { withRedisClient { client => @@ -44,74 +26,6 @@ final class SimpleClientSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the GETRANGE command", RedisTest, SlowTest) { - withRedisClient { client => - Await.result(client.set(foo, StringToChannelBuffer("boing"))) - val actualResult = CBToString(Await.result(client.getRange(foo, 0, 2)).get) - val expectedResult = "boi" - assert(actualResult === expectedResult) - } - } - - test("Correctly perform the GET & SET commands", RedisTest, SlowTest) { - withRedisClient { client => - val actualEmptyGetResult = Await.result(client.get(foo)) - val expectedEmptyGetResult = None - assert(actualEmptyGetResult === expectedEmptyGetResult) - - Await.result(client.set(foo, bar)) - val actualGetResult = CBToString(Await.result(client.get(foo)).get) - val expectedGetResult = "bar" - assert(actualGetResult === expectedGetResult) - } - } - - test("Correctly perform the FLUSH command", RedisTest, SlowTest) { - withRedisClient { client => - Await.result(client.set(foo, bar)) - Await.result(client.flushDB()) - val actualResult = Await.result(client.get(foo)) - val expectedResult = None - assert(actualResult === expectedResult) - } - } - - test("Correctly perform the SELECT command", RedisTest, SlowTest) { - withRedisClient { client => - val actualResult =Await.result(client.select(1)) - val expectedResult = () - assert(actualResult === expectedResult) - } - } - - test("Correctly perform the INFO command", RedisTest, SlowTest) { - withRedisClient { client => - val info = new String(Await.result(client.info()).get.array, "UTF8") - val hasServer = info.contains("# Server") - assert(hasServer === true) - val hasRedisVersion = info.contains("redis_version:") - assert(hasRedisVersion === true) - val hasClients = info.contains("# Clients") - assert(hasClients === true) - - val cpu = new String(Await.result(client.info(StringToChannelBuffer("cpu"))).get.array, "UTF8") - val hasCpu = cpu.contains("# CPU") - assert(hasCpu === true) - val hasUsedCpuSys = cpu.contains("used_cpu_sys:") - assert(hasUsedCpuSys === true) - val cpuHasRedisVersion = cpu.contains("redis_version:") - assert(cpuHasRedisVersion === false) - } - } - - test("Correctly perform the QUIT command", RedisTest, SlowTest) { - withRedisClient { client => - val actualResult = Await.result(client.quit()) - val expectedResult = () - assert(actualResult === expectedResult) - } - } - test("Correctly perform the TTL command", RedisTest, SlowTest) { withRedisClient { client => Await.result(client.set(foo, bar)) @@ -169,4 +83,41 @@ final class SimpleClientSuite extends FinagleRedisClientSuite { Await.result(client.del(Seq(foo))) // clean up } } + + test("Correctly perform the PEXPIRE & PTL commands", RedisTest, SlowTest) { + withRedisClient { client => + val ttl = 100000L + Await.result(client.set(foo, bar)) + val didSetPEXPIRE = Await.result(client.pExpire(foo, ttl)) + val expectedPEXPIREResult = true + assert(didSetPEXPIRE === expectedPEXPIREResult) + + val result = Await.result(client.pTtl(foo)) match { + case Some(num) => num + case None => fail("Could not retrieve pTtl for key") + } + val actualResult = if(result <= ttl) true else false + val expectedResult = true + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the PEXPIREAT & PTL commands", RedisTest, SlowTest) { + withRedisClient { client => + val horizon = 20000L + val ttl = System.currentTimeMillis() + horizon + Await.result(client.set(foo, bar)) + val didSetPEXPIREAT = Await.result(client.pExpireAt(foo, ttl)) + val expectedPEXPIREATResult = true + assert(didSetPEXPIREAT === expectedPEXPIREATResult) + + val result = Await.result(client.pTtl(foo)) match { + case Some(num) => num + case None => fail("Could not retrieve pTtl for key") + } + val actualResult = if(result <= horizon) true else false + val expectedResult = true + assert(actualResult === expectedResult) + } + } } diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala new file mode 100644 index 00000000000..a19a7dc729c --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala @@ -0,0 +1,6 @@ +package com.twitter.finagle.redis.integration + + +final class KeyClientServerIntegrationSuite { + +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala index 5ef1725a27e..b1033ed5cdc 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala @@ -6,7 +6,7 @@ import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest import com.twitter.finagle.redis.tags.CodecTest import com.twitter.util.Time -final class KeyCommandSuite extends FinagleRedisRequestTest { +final class KeyCodecSuite extends FinagleRedisRequestTest { test("Correctly encode DELETE for one key", CodecTest) { val actualEncoding = codec(wrap("DEL foo\r\n")) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala new file mode 100644 index 00000000000..8a26e6fbbce --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala @@ -0,0 +1,39 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.util.Await +import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} + +final class ServerClientIntegrationSuite extends FinagleRedisClientSuite { + + test("Correctly perform the FLUSHDB command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + Await.result(client.flushDB()) + val actualResult = Await.result(client.get(foo)) + val expectedResult = None + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the INFO command", RedisTest, SlowTest) { + withRedisClient { client => + val info = new String(Await.result(client.info()).get.array, "UTF8") + val hasServer = info.contains("# Server") + assert(hasServer === true) + val hasRedisVersion = info.contains("redis_version:") + assert(hasRedisVersion === true) + val hasClients = info.contains("# Clients") + assert(hasClients === true) + + val cpu = new String(Await.result(client.info(StringToChannelBuffer("cpu"))).get.array, "UTF8") + val hasCpu = cpu.contains("# CPU") + assert(hasCpu === true) + val hasUsedCpuSys = cpu.contains("used_cpu_sys:") + assert(hasUsedCpuSys === true) + val cpuHasRedisVersion = cpu.contains("redis_version:") + assert(cpuHasRedisVersion === false) + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala new file mode 100644 index 00000000000..59afefc9c70 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala @@ -0,0 +1,50 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.util.Await +import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} + +final class StringClientIntegrationSuite extends FinagleRedisClientSuite { + + test("Correctly perform the APPEND command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, bar)) + val actualResult = Await.result(client.append(foo, baz)) + val expectedResult = 6 + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the DECRBY command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, StringToChannelBuffer("21"))) + val actualResult = Await.result(client.decrBy(foo, 2)) + val expectedResult = 19 + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the GETRANGE command", RedisTest, SlowTest) { + withRedisClient { client => + Await.result(client.set(foo, StringToChannelBuffer("boing"))) + val actualResult = CBToString(Await.result(client.getRange(foo, 0, 2)).get) + val expectedResult = "boi" + assert(actualResult === expectedResult) + } + } + + test("Correctly perform the GET & SET commands", RedisTest, SlowTest) { + withRedisClient { client => + val actualEmptyGetResult = Await.result(client.get(foo)) + val expectedEmptyGetResult = None + assert(actualEmptyGetResult === expectedEmptyGetResult) + + Await.result(client.set(foo, bar)) + val actualGetResult = CBToString(Await.result(client.get(foo)).get) + val expectedGetResult = "bar" + assert(actualGetResult === expectedGetResult) + } + } + +} From 25eb30ca1823a1591ccfa6f3a12b868b70747ea2 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Fri, 4 Jul 2014 15:05:37 -0500 Subject: [PATCH 05/10] Completed refactoring of all KEY command tests, along with all formerly 'Simple' tests in the ClientIntegrationTest --- .../finagle/redis/wip/FinagleRedisTest.scala | 94 ++++- .../com/twitter/finagle/redis/wip/Tags.scala | 4 +- .../ConnectionClientIntegrationSuite.scala | 6 +- .../keys/KeyClientIntegrationSuite.scala | 16 +- .../KeyClientServerIntegrationSuite.scala | 382 +++++++++++++++++- .../server/ServerClientIntegrationSuite.scala | 6 +- .../StringClientIntegrationSuite.scala | 10 +- 7 files changed, 485 insertions(+), 33 deletions(-) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala index 84e9c39686a..510d9210934 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala @@ -1,13 +1,17 @@ package com.twitter.finagle.redis.naggati -import com.twitter.finagle.builder.ClientBuilder +import com.twitter.finagle.builder.{ClientBuilder, ServerBuilder} import com.twitter.finagle.redis.naggati.test.TestCodec import com.twitter.finagle.redis.protocol._ -import com.twitter.finagle.redis.util.{CBToString, RedisCluster, ReplyFormat, StringToChannelBuffer} +import com.twitter.finagle.redis.util.{BytesToString, CBToString, RedisCluster, ReplyFormat, StringToChannelBuffer} import com.twitter.finagle.redis.{Redis, TransactionalClient} -import com.twitter.util.Await +import com.twitter.util.{Await, Future, Time} import org.jboss.netty.buffer.ChannelBuffer import org.scalatest.{BeforeAndAfterAll, FunSuite} +import java.net.InetSocketAddress +import com.twitter.finagle.Service +import com.twitter.finagle.redis.Client + trait FinagleRedisTest extends FunSuite { protected def wrap(s: String): ChannelBuffer = StringToChannelBuffer(s) @@ -45,13 +49,8 @@ trait FinagleRedisRequestTest extends FinagleRedisTest { trait FinagleRedisClientSuite extends FinagleRedisTest with BeforeAndAfterAll { - override def beforeAll(configMap: Map[String, Any]): Unit = { - RedisCluster.start() - } - - override def afterAll(configMap: Map[String, Any]): Unit = { - RedisCluster.stop() - } + override def beforeAll(configMap: Map[String, Any]): Unit = RedisCluster.start() + override def afterAll(configMap: Map[String, Any]): Unit = RedisCluster.stop() protected def withRedisClient(testCode: TransactionalClient => Any) { val client = TransactionalClient( @@ -69,3 +68,78 @@ trait FinagleRedisClientSuite extends FinagleRedisTest with BeforeAndAfterAll { } } } + +trait FinagleRedisClientServerIntegrationTest extends FinagleRedisTest with BeforeAndAfterAll { + + private[this] lazy val svcClient = ClientBuilder() + .name("redis-client") + .codec(Redis()) + .hosts(RedisCluster.hostAddresses()) + .hostConnectionLimit(2) + .retries(2) + .build() + + private[this] val service = new Service[Command, Reply] { + def apply(cmd: Command): Future[Reply] = { + svcClient(cmd) + } + } + + private[this] val server = ServerBuilder() + .name("redis-server") + .codec(Redis()) + .bindTo(new InetSocketAddress(0)) + .build(service) + + override def beforeAll(configMap: Map[String, Any]): Unit = RedisCluster.start() + override def afterAll(configMap: Map[String, Any]): Unit = RedisCluster.stop() + + protected val OKStatusReply = StatusReply("OK") + + protected def withRedisClient(testCode: Service[Command, Reply] => Any) { + val client = ClientBuilder() + .name("redis-client") + .codec(Redis()) + .hosts(server.localAddress) + .hostConnectionLimit(1) + .retries(2) + .build() + try { + testCode(client) + } + finally { + Await.result(client(FlushDB)) + client.close() + } + } + + protected def assertMBulkReply(reply: Future[Reply], expects: List[String], + contains: Boolean = false) = Await.result(reply) match { + case MBulkReply(msgs) => contains match { + case true => + assert(expects.isEmpty === false, "Test did no supply a list of expected replies.") + val newMsgs = ReplyFormat.toString(msgs) + expects.foreach({ msg => + val doesMBulkReplyContainMessage = newMsgs.contains(msg) + assert(doesMBulkReplyContainMessage === true) + }) + case false => + val actualMessages = ReplyFormat.toChannelBuffers(msgs).map({ msg => + CBToString(msg) + }) + assert(actualMessages == expects) + } + case EmptyMBulkReply() => { + val isEmpty = true + val actualReply = expects.isEmpty + assert(actualReply === isEmpty) + } + case r: Reply => fail("Expected MBulkReply, got %s".format(r)) + case _ => fail("Expected MBulkReply") + } + + def assertBulkReply(reply: Future[Reply], expects: String) = Await.result(reply) match { + case BulkReply(msg) => assert(BytesToString(msg.array) === expects) + case _ => fail("Expected BulkReply") + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/Tags.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/Tags.scala index c5115e7e08d..08a7cfe87d0 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/Tags.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/Tags.scala @@ -3,6 +3,6 @@ package com.twitter.finagle.redis.tags import org.scalatest.Tag object RedisTest extends Tag("com.twitter.finagle.redis.tags.RedisTest") -object IntegrationTest extends Tag("com.twitter.finagle.redis.tags.IntegrationTest") -object SlowTest extends Tag("com.twitter.finagle.redis.tags.SlowTest") object CodecTest extends Tag("com.twitter.finagle.redis.tags.CodecTest") +object ClientTest extends Tag("com.twitter.finagle.redis.tags.ClientTest") +object ClientServerTest extends Tag("com.twitter.finagle.redis.tags.ClientServerTest") diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala index 2894c8fb6e6..13b9c1d1fb5 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala @@ -1,13 +1,13 @@ package com.twitter.finagle.redis.integration import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite -import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} final class ConnectionClientIntegrationSuite extends FinagleRedisClientSuite { - test("Correctly perform the SELECT command", RedisTest, SlowTest) { + test("Correctly perform the SELECT command", RedisTest, ClientTest) { withRedisClient { client => val actualResult =Await.result(client.select(1)) val expectedResult = () @@ -15,7 +15,7 @@ final class ConnectionClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the QUIT command", RedisTest, SlowTest) { + test("Correctly perform the QUIT command", RedisTest, ClientTest) { withRedisClient { client => val actualResult = Await.result(client.quit()) val expectedResult = () diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala index 91dda400719..d2f7ce4658c 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala @@ -1,13 +1,13 @@ package com.twitter.finagle.redis.integration import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite -import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { - test("Correctly perform the DEL command", RedisTest, SlowTest) { + test("Correctly perform the DEL command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, bar)) Await.result(client.del(Seq(foo))) @@ -17,7 +17,7 @@ final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the EXISTS command", RedisTest, SlowTest) { + test("Correctly perform the EXISTS command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, bar)) val actualResult = Await.result(client.exists(foo)) @@ -26,7 +26,7 @@ final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the TTL command", RedisTest, SlowTest) { + test("Correctly perform the TTL command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, bar)) val time = 20L @@ -45,7 +45,7 @@ final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the EXPIREAT command", RedisTest, SlowTest) { + test("Correctly perform the EXPIREAT command", RedisTest, ClientTest) { withRedisClient { client => val ttl = System.currentTimeMillis() + 20000L Await.result(client.set(foo, bar)) @@ -63,7 +63,7 @@ final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the MOVE command", RedisTest, SlowTest) { + test("Correctly perform the MOVE command", RedisTest, ClientTest) { withRedisClient { client => val fromDb = 14 val toDb = 15 @@ -84,7 +84,7 @@ final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the PEXPIRE & PTL commands", RedisTest, SlowTest) { + test("Correctly perform the PEXPIRE & PTL commands", RedisTest, ClientTest) { withRedisClient { client => val ttl = 100000L Await.result(client.set(foo, bar)) @@ -102,7 +102,7 @@ final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the PEXPIREAT & PTL commands", RedisTest, SlowTest) { + test("Correctly perform the PEXPIREAT & PTL commands", RedisTest, ClientTest) { withRedisClient { client => val horizon = 20000L val ttl = System.currentTimeMillis() + horizon diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala index a19a7dc729c..53972e8cd5e 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala @@ -1,6 +1,384 @@ package com.twitter.finagle.redis.integration +import com.twitter.conversions.time._ +import com.twitter.finagle.redis.ClientError +import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.protocol._ +import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} +import com.twitter.util.{Await, Future, Time} +import org.jboss.netty.buffer.ChannelBuffer -final class KeyClientServerIntegrationSuite { - +final class KeyClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { + + test("DELETE two keys", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply0 = Await.result(client(Set(foo, bar))) + assert(actualSetReply0 === OKStatusReply) + + val actualSetReply1 = Await.result(client(Set(moo, baz))) + assert(actualSetReply1 === OKStatusReply) + + val actualDeletedReply = Await.result(client(Del(List(foo, moo)))) + val expectedDeletedReply = IntegerReply(2) + assert(actualDeletedReply === expectedDeletedReply) + } + } + + test("DELETE should throw ClientError when given null list", ClientServerTest, RedisTest) { + withRedisClient { client => + intercept[ClientError] { + Await.result(client(Del(null:List[ChannelBuffer]))) + } + } + } + + test("DELETE should throw ClientError when given an empty List", ClientServerTest, RedisTest) { + withRedisClient { client => + intercept[ClientError] { + Await.result(client(Del(List[ChannelBuffer]()))) + } + } + } + + test("EXISTS should return an IntegerReply of 0 for a non-existent key", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualReply = Await.result(client(Exists(string2ChanBuf("nosuchkey")))) + val expectedReply = IntegerReply(0) + assert(actualReply === expectedReply) + } + } + + test("EXISTS should return and IntegerReply of 1 for an existing key", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val actualReply = Await.result(client(Exists(foo))) + val expectedReply = IntegerReply(1) + assert(actualReply === expectedReply) + } + } + + test("EXISTS should throw ClientError when given a null ChannelBuffer", + ClientServerTest, RedisTest) { + withRedisClient { client => + intercept[ClientError] { + Await.result(client(Exists(null:ChannelBuffer))) + } + } + } + + test("EXPIRE should return an IntegerReply of 0 to verify a INVALID timeout was set", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualExpireReply = Await.result(client(Expire(baz, 30))) + val expectedExpireReply = IntegerReply(0) + assert(actualExpireReply === expectedExpireReply) + } + } + + test("EXPIRE should return an IntegerReply of 1 to verify a VALID timeout was set", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val actualExpireReply = Await.result(client(Expire(foo, 30))) + val expectedExpireReply = IntegerReply(1) + assert(actualExpireReply === expectedExpireReply) + } + } + + test("EXPIRE should throw ClientError when given a null key", ClientServerTest, RedisTest) { + withRedisClient { client => + intercept[ClientError] { + Await.result(client(Expire(null:ChannelBuffer, 30))) + } + } + } + + test("EXPIREAT should return an IntegerReply of 0 to verify a INVALID timeout was set", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualExpireReply = Await.result(client(ExpireAt(boo, Time.now + 3600.seconds))) + val expectedExpireReply = IntegerReply(0) + assert(actualExpireReply === expectedExpireReply) + } + } + + test("EXPIREAT should return an IntegerReply of 1 to verify a VALID timeout was set", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val actualExpireReply = Await.result(client(ExpireAt(foo, Time.now + 3600.seconds))) + val expectedExpireReply = IntegerReply(1) + assert(actualExpireReply === expectedExpireReply) + } + } + + test("EXPIREAT should throw ClientError when given a null key", ClientServerTest, RedisTest) { + withRedisClient { client => + intercept[ClientError] { + Await.result(client(ExpireAt(null:ChannelBuffer, Time.now + 3600.seconds))) + } + } + } + + test("KEYS should return a list of all keys in the database that match the provided pattern", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val request = client(Keys(string2ChanBuf("*"))) + val expects = List("foo") + assertMBulkReply(request, expects, true) + } + } + + test("MOVE should throw ClientError when given an empty or null key", + ClientServerTest, RedisTest) { + withRedisClient { client => + val toDBDoesNotMatter = string2ChanBuf("71") + val blankKey = string2ChanBuf("") + intercept[ClientError] { + Await.result(client(Move(blankKey, toDBDoesNotMatter))) + } + val nullKey = null:ChannelBuffer + intercept[ClientError] { + Await.result(client(Move(nullKey, toDBDoesNotMatter))) + } + } + } + + test("MOVE should throw ClientError when given an empty or null toDatabase", + ClientServerTest, RedisTest) { + withRedisClient { client => + val blankToDb = string2ChanBuf("") + intercept[ClientError] { + Await.result(client(Move(moo, blankToDb))) + } + val nullToDb = null:ChannelBuffer + intercept[ClientError] { + Await.result(client(Move(moo, nullToDb))) + } + } + } + + test("MOVE should return an Integer Reply of 1 to verify a key was moved", + ClientServerTest, RedisTest) { + withRedisClient { client => + val fromDb = 14 + val toDb = 15 + assert(Await.result(client(Select(toDb))) === OKStatusReply) + Await.result(client(Del(List(baz)))) + assert(Await.result(client(Select(fromDb))) === OKStatusReply) + + val actualSetReply = Await.result(client(Set(baz, bar))) + assert(actualSetReply === OKStatusReply) + + val actualMoveReply = Await.result(client(Move(baz, string2ChanBuf(toDb.toString)))) + val expectedMoveReply = IntegerReply(1) + assert(actualMoveReply === expectedMoveReply) + } + } + + test("MOVE should return an Integer Reply of 0 to show a MOVE was not completed", + ClientServerTest, RedisTest) { + withRedisClient { client => + Await.result(client(Select(1))) + val toDb = string2ChanBuf("14") + val actualMoveReply= Await.result(client(Move(moo, toDb))) + val expectedMoveReply = IntegerReply(0) + assert(actualMoveReply === expectedMoveReply) + } + } + + test("PERSIST should return an IntegerReply of 0 when no key is found", + ClientServerTest, RedisTest) { + withRedisClient { client => + val expectedReply = IntegerReply(0) + val actualReply = Await.result(client(Persist(string2ChanBuf("nosuchKey")))) + assert(actualReply === expectedReply) + } + } + + test("PERSIST should return an IntegerReply of 0 when a found key has no associated timeout", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val expectedReply = IntegerReply(0) + val actualReply = Await.result(client(Persist(foo))) + assert(actualReply === expectedReply) + } + } + + test("PERSIST should return an IntegerReply of 1 when removing an associated timeout", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(baz, bar))) + assert(actualSetReply === OKStatusReply) + val actualExpireReply = Await.result(client(Expire(baz, 30))) + val expectedExpireReply = IntegerReply(1) + assert(actualExpireReply === expectedExpireReply, "FATAL could not expire existing key") + + val expectedReply = IntegerReply(1) + val actualReply = Await.result(client(Persist(baz))) + assert(actualReply === expectedReply) + } + } + + test("RENAME should return an ErrorReply when renaming a key to the original name", + ClientServerTest, RedisTest) { + withRedisClient { client => + val originalKeyName = string2ChanBuf("rename1") + val actualSetReply = Await.result(client(Set(originalKeyName, bar))) + assert(actualSetReply === OKStatusReply) + + val actualReply = Await.result(client(Rename(originalKeyName, originalKeyName))) + val actualReplyClass = actualReply.getClass.getName.split('.').last + val expectedReplyClass = ErrorReply.getClass.getName.split('.').last.dropRight(1) + assert(actualReplyClass === expectedReplyClass) + } + } + + test("RENAME should return an ErrorReply when renaming a key that does not exist", + ClientServerTest, RedisTest) { + withRedisClient { client => + val noSuchKey = string2ChanBuf("noSuchKey") + + val actualReply = Await.result(client(Rename(noSuchKey, string2ChanBuf("DOES NOT MATTER")))) + val actualReplyClass = actualReply.getClass.getName.split('.').last + val expectedReplyClass = ErrorReply.getClass.getName.split('.').last.dropRight(1) + assert(actualReplyClass === expectedReplyClass) + } + } + + test("RENAME should return a StatusReply(\"OK\") after correctly renaming a key", + ClientServerTest, RedisTest) { + withRedisClient { client => + val rename1 = string2ChanBuf("rename1") + val rename2 = string2ChanBuf("rename2") + val actualSetReply = Await.result(client(Set(rename1, bar))) + assert(actualSetReply === OKStatusReply) + + val actualRenameReply = Await.result(client(Rename(rename1, rename2))) + assert(actualRenameReply === OKStatusReply) + } + } + + test("RENAMENX should return an ErrorReply when renaming a key to the original name", + ClientServerTest, RedisTest) { + withRedisClient { client => + val originalKeyName = string2ChanBuf("rename1") + val actualSetReply = Await.result(client(Set(originalKeyName, bar))) + assert(actualSetReply === OKStatusReply) + + val actualReply = Await.result(client(RenameNx(originalKeyName, originalKeyName))) + val actualReplyClass = actualReply.getClass.getName.split('.').last + val expectedReplyClass = ErrorReply.getClass.getName.split('.').last.dropRight(1) + assert(actualReplyClass === expectedReplyClass) + } + } + + test("RENAMENX should return an ErrorReply when renaming a key that does not exist", + ClientServerTest, RedisTest) { + withRedisClient { client => + val noSuchKey = string2ChanBuf("noSuchKey") + + val actualReply = Await.result(client(RenameNx(noSuchKey, string2ChanBuf("DOES NOT MATTER")))) + val actualReplyClass = actualReply.getClass.getName.split('.').last + val expectedReplyClass = ErrorReply.getClass.getName.split('.').last.dropRight(1) + assert(actualReplyClass === expectedReplyClass) + } + } + + test("RENAMENX should an IntegerReply of 1 to verify a key was renamed", + ClientServerTest, RedisTest) { + withRedisClient { client => + val rename1 = string2ChanBuf("rename1") + val rename2 = string2ChanBuf("rename2") + val actualSetReply = Await.result(client(Set(rename1, bar))) + assert(actualSetReply === OKStatusReply) + + val actualRenameReplyNx = Await.result(client(RenameNx(rename1, rename2))) + val expectedReply = IntegerReply(1) + assert(actualRenameReplyNx === expectedReply) + } + } + + test("RENAMENX should return an IntegerReply of 0 to verify a key rename did not occur when the" + + " the new key name already exists", ClientServerTest, RedisTest) { + withRedisClient { client => + val rename1 = string2ChanBuf("rename1") + val actualSetReply0 = Await.result(client(Set(rename1, bar))) + assert(actualSetReply0 === OKStatusReply) + + val rename2 = string2ChanBuf("rename2") + val actualSetReply1 = Await.result(client(Set(rename2, baz))) + assert(actualSetReply1 === OKStatusReply) + + val actualRenameNxReply = Await.result(client(RenameNx(rename1, rename2))) + val expectedReply = IntegerReply(0) + assert(actualRenameNxReply === expectedReply) + } + } + + test("RANDOMKEY should return a BulkReply", ClientServerTest, RedisTest) { + withRedisClient{ client => + val actualReply = Await.result(client(Randomkey())) + val actualReplyClass = actualReply.getClass.getName.split('.').last.takeRight(9) + val expectedReplyClass = BulkReply.getClass.getName.split('.').last.dropRight(1).takeRight(9) + assert(actualReplyClass === expectedReplyClass) + } + } + + test("TTL should throw a ClientError when given an empty key", ClientServerTest, RedisTest) { + withRedisClient { client => + val emptyKey = string2ChanBuf("") + + intercept[ClientError] { + Await.result(client(Ttl(emptyKey))) + } + } + } + + test("TTL should return an IntegerReply of -1 when the key exists and has no associated timeout", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val actualReply = Await.result(client(Ttl(foo))) + val expectedReply = IntegerReply(-1) + assert(actualReply === expectedReply) + } + } + + test("TYPE should return a StatusReply(\"string\") for a string type stored at given key", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualSetReply = Await.result(client(Set(foo, bar))) + assert(actualSetReply === OKStatusReply) + + val actualReply = Await.result(client(Type(foo))) + val expectedReply = StatusReply("string") + assert(actualReply === expectedReply) + } + } + + test("TYPE should return a StatusReply(\"none\") when given a key with no assicated value", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualReply = Await.result(client(Type(moo))) + val expectedReply = StatusReply("none") + assert(actualReply === expectedReply) + } + } } diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala index 8a26e6fbbce..671abfdf8ea 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala @@ -1,13 +1,13 @@ package com.twitter.finagle.redis.integration import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite -import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} final class ServerClientIntegrationSuite extends FinagleRedisClientSuite { - test("Correctly perform the FLUSHDB command", RedisTest, SlowTest) { + test("Correctly perform the FLUSHDB command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, bar)) Await.result(client.flushDB()) @@ -17,7 +17,7 @@ final class ServerClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the INFO command", RedisTest, SlowTest) { + test("Correctly perform the INFO command", RedisTest, ClientTest) { withRedisClient { client => val info = new String(Await.result(client.info()).get.array, "UTF8") val hasServer = info.contains("# Server") diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala index 59afefc9c70..239b3017f1b 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala @@ -1,13 +1,13 @@ package com.twitter.finagle.redis.integration import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite -import com.twitter.finagle.redis.tags.{RedisTest, SlowTest} +import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} final class StringClientIntegrationSuite extends FinagleRedisClientSuite { - test("Correctly perform the APPEND command", RedisTest, SlowTest) { + test("Correctly perform the APPEND command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, bar)) val actualResult = Await.result(client.append(foo, baz)) @@ -16,7 +16,7 @@ final class StringClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the DECRBY command", RedisTest, SlowTest) { + test("Correctly perform the DECRBY command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, StringToChannelBuffer("21"))) val actualResult = Await.result(client.decrBy(foo, 2)) @@ -25,7 +25,7 @@ final class StringClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the GETRANGE command", RedisTest, SlowTest) { + test("Correctly perform the GETRANGE command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, StringToChannelBuffer("boing"))) val actualResult = CBToString(Await.result(client.getRange(foo, 0, 2)).get) @@ -34,7 +34,7 @@ final class StringClientIntegrationSuite extends FinagleRedisClientSuite { } } - test("Correctly perform the GET & SET commands", RedisTest, SlowTest) { + test("Correctly perform the GET & SET commands", RedisTest, ClientTest) { withRedisClient { client => val actualEmptyGetResult = Await.result(client.get(foo)) val expectedEmptyGetResult = None From e1147e9d56366c42380ce4130727be2930afae06 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Fri, 4 Jul 2014 17:01:29 -0500 Subject: [PATCH 06/10] Added the FLUSHALL command to reset redis after each integration test to ensure clean state --- .../com/twitter/finagle/redis/Client.scala | 5 +++++ .../finagle/redis/protocol/Command.scala | 3 +++ .../finagle/redis/protocol/commands/Misc.scala | 15 ++++++++++----- .../finagle/redis/wip/FinagleRedisTest.scala | 4 ++-- .../server/ServerClientIntegrationSuite.scala | 14 ++++++++++++++ .../ServerClientServerIntegrationSuite.scala | 17 +++++++++++++++++ .../wip/commands/server/ServerCodecSuite.scala | 13 +++++++++++++ 7 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala diff --git a/finagle-redis/src/main/scala/com/twitter/finagle/redis/Client.scala b/finagle-redis/src/main/scala/com/twitter/finagle/redis/Client.scala index c329702cc3e..b5a7b9733d7 100644 --- a/finagle-redis/src/main/scala/com/twitter/finagle/redis/Client.scala +++ b/finagle-redis/src/main/scala/com/twitter/finagle/redis/Client.scala @@ -64,6 +64,11 @@ class BaseClient(service: Service[Command, Reply]) { case EmptyBulkReply() => Future.value(None) } + /** + * Deletes all keys in all databases + */ + def flushAll(): Future[Unit] = doRequest(FlushAll) {case StatusReply(_) => Future.Unit} + /** * Deletes all keys in current DB */ diff --git a/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/Command.scala b/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/Command.scala index d766f811953..8f9b99660cf 100755 --- a/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/Command.scala +++ b/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/Command.scala @@ -82,6 +82,7 @@ object Commands { val BRANGE = "BRANGE" // Miscellaneous + val FLUSHALL = "FLUSHALL" val FLUSHDB = "FLUSHDB" val SELECT = "SELECT" val AUTH = "AUTH" @@ -203,6 +204,7 @@ object Commands { BGET -> {BGet(_)}, // miscellaneous + FLUSHALL -> {_ => FlushAll}, FLUSHDB -> {_ => FlushDB}, SELECT -> {Select(_)}, AUTH -> {Auth(_)}, @@ -341,6 +343,7 @@ object CommandBytes { val BRANGE = StringToChannelBuffer("BRANGE") // Miscellaneous + val FLUSHALL = StringToChannelBuffer("FLUSHALL") val FLUSHDB = StringToChannelBuffer("FLUSHDB") val SELECT = StringToChannelBuffer("SELECT") val AUTH = StringToChannelBuffer("AUTH") diff --git a/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/commands/Misc.scala b/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/commands/Misc.scala index 35a33396282..53a845ffdda 100644 --- a/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/commands/Misc.scala +++ b/finagle-redis/src/main/scala/com/twitter/finagle/redis/protocol/commands/Misc.scala @@ -5,6 +5,11 @@ import com.twitter.finagle.redis.protocol.Commands.trimList import com.twitter.finagle.redis.util._ import org.jboss.netty.buffer.{ChannelBuffer, ChannelBuffers} +case object FlushAll extends Command { + def command = Commands.FLUSHALL + val toChannelBuffer = RedisCodec.toUnifiedFormat(Seq(CommandBytes.FLUSHALL)) +} + case object FlushDB extends Command { def command = Commands.FLUSHDB val toChannelBuffer = RedisCodec.toUnifiedFormat(Seq(CommandBytes.FLUSHDB)) @@ -52,7 +57,7 @@ case object Quit extends Command { val toChannelBuffer = RedisCodec.toUnifiedFormat(Seq(CommandBytes.QUIT)) } -case class ConfigSet(param: ChannelBuffer, value: ChannelBuffer) extends Config(ConfigSet.channelBuffer, Seq(param, value)) +case class ConfigSet(param: ChannelBuffer, value: ChannelBuffer) extends Config(ConfigSet.channelBuffer, Seq(param, value)) object ConfigSet extends ConfigHelper { val command = "SET" def apply(args: Seq[Array[Byte]]): ConfigSet = { @@ -61,7 +66,7 @@ object ConfigSet extends ConfigHelper { } } -case class ConfigGet(param: ChannelBuffer) extends Config(ConfigGet.channelBuffer, Seq(param)) +case class ConfigGet(param: ChannelBuffer) extends Config(ConfigGet.channelBuffer, Seq(param)) object ConfigGet extends ConfigHelper { val command = "GET" def apply(args: Seq[Array[Byte]]): ConfigGet = { @@ -70,7 +75,7 @@ object ConfigGet extends ConfigHelper { } } -case class ConfigResetStat() extends Config(sub = ConfigResetStat.channelBuffer, args = Seq()) +case class ConfigResetStat() extends Config(sub = ConfigResetStat.channelBuffer, args = Seq()) object ConfigResetStat extends ConfigHelper { val command = "RESETSTAT" def apply(args: Seq[Array[Byte]]): ConfigResetStat = new ConfigResetStat() @@ -85,7 +90,7 @@ abstract class Config(sub: ChannelBuffer, args: Seq[ChannelBuffer]) extends Comm trait ConfigHelper { def command: String def apply(args: Seq[Array[Byte]]): Config - + def channelBuffer: ChannelBuffer = StringToChannelBuffer(command) def bytes: Array[Byte] = StringToBytes(command) @@ -100,7 +105,7 @@ object Config { subCommand(args.tail) } } - + case class SlaveOf(host: ChannelBuffer, port: ChannelBuffer) extends Command { def command = Commands.SLAVEOF diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala index 510d9210934..42ebdd58afc 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala @@ -59,7 +59,7 @@ trait FinagleRedisClientSuite extends FinagleRedisTest with BeforeAndAfterAll { .hosts(RedisCluster.hostAddresses()) .hostConnectionLimit(1) .buildFactory()) - Await.result(client.flushDB()) + Await.result(client.flushAll) try { testCode(client) } @@ -104,11 +104,11 @@ trait FinagleRedisClientServerIntegrationTest extends FinagleRedisTest with Befo .hostConnectionLimit(1) .retries(2) .build() + Await.result(client(FlushAll)) try { testCode(client) } finally { - Await.result(client(FlushDB)) client.close() } } diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala index 671abfdf8ea..cdfc3b405db 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala @@ -7,6 +7,20 @@ import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} final class ServerClientIntegrationSuite extends FinagleRedisClientSuite { + test("Correctly perform the FLUSHALL command", RedisTest, ClientTest) { + withRedisClient { client => + Await.result(client.select(15)) + Await.result(client.set(foo, bar)) + Await.result(client.select(1)) + Await.result(client.flushAll()) + Await.result(client.select(15)) + + val actualResult = Await.result(client.get(foo)) + val expectedResult = None + assert(actualResult === expectedResult) + } + } + test("Correctly perform the FLUSHDB command", RedisTest, ClientTest) { withRedisClient { client => Await.result(client.set(foo, bar)) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala new file mode 100644 index 00000000000..957f4ec6cc4 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala @@ -0,0 +1,17 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.protocol._ +import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} +import com.twitter.util.Await + +final class ServerClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { + + test("FLUSHALL should return a StatusReply(\"OK\")", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFlushAllReply = Await.result(client(FlushAll)) + val expectedFlushAllReply = OKStatusReply + assert(actualFlushAllReply === expectedFlushAllReply) + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala new file mode 100644 index 00000000000..b3c79a9c16a --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala @@ -0,0 +1,13 @@ +package com.twitter.finagle.redis.protocol + +import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.tags.CodecTest + +final class ServerCodecSuite extends FinagleRedisRequestTest { + + test("Correctly encode FLUSHALL", CodecTest) { + val actualEncoding = codec(wrap("FLUSHALL\r\n")) + val expectedEncoding = List(FlushAll) + assert(actualEncoding === expectedEncoding) + } +} From 530821870f66c19d57b1ce47e185d82da9fb1e07 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Sat, 23 Aug 2014 00:51:01 -0500 Subject: [PATCH 07/10] Completed refactoring for all current LIST tests --- .../finagle/redis/wip/FinagleRedisTest.scala | 3 +- .../list/ListClientIntegrationSuite.scala | 331 ++++++++++++++++++ .../ListClientServerIntegrationSuite.scala | 224 ++++++++++++ .../wip/commands/list/ListCodecSuite.scala | 25 ++ 4 files changed, 582 insertions(+), 1 deletion(-) create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala index 42ebdd58afc..51b0a2e682b 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala @@ -16,6 +16,7 @@ import com.twitter.finagle.redis.Client trait FinagleRedisTest extends FunSuite { protected def wrap(s: String): ChannelBuffer = StringToChannelBuffer(s) protected def string2ChanBuf(s: String): ChannelBuffer = wrap(s) + protected def chanBuf2String(cb: ChannelBuffer): String = CBToString(cb) protected val foo = StringToChannelBuffer("foo") protected val bar = StringToChannelBuffer("bar") @@ -125,7 +126,7 @@ trait FinagleRedisClientServerIntegrationTest extends FinagleRedisTest with Befo }) case false => val actualMessages = ReplyFormat.toChannelBuffers(msgs).map({ msg => - CBToString(msg) + chanBuf2String(msg) }) assert(actualMessages == expects) } diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala new file mode 100644 index 00000000000..c52fa1595b9 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala @@ -0,0 +1,331 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.tags.{ClientTest, RedisTest} +import com.twitter.util.Await + +final class ListClientIntegrationSuite extends FinagleRedisClientSuite { + + val IndexFailureMessage = "Unknown failure calling Index" + val PopFailureMessage = "Failure popping element from list" + + test("Correctly push elements onto a list", RedisTest, ClientTest) { + withRedisClient { client => + val actualFirstLPushResult = Await.result(client.lPush(foo, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLPushResult = Await.result(client.lPush(foo, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + } + } + + test("Correctly pop elements off a list", RedisTest, ClientTest) { + withRedisClient { client => + val actualFirstLPushResult = Await.result(client.lPush(foo, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + val actualSecondLPushResult = Await.result(client.lPush(foo, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + val actualFirstLPopResult = Await.result(client.lPop(foo)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstLPopResult = baz + assert(actualFirstLPopResult === expectedFirstLPopResult) + + val actualSecondLPopResult = Await.result(client.lPop(foo)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondLPopResult = bar + assert(actualSecondLPopResult === expectedSecondLPopResult) + } + } + + test("Correctly measure length of an actively changing list", RedisTest, ClientTest) { + withRedisClient { client => + val key = foo + + val actualFirstLLenResult = Await.result(client.lLen(key)) + val expectedFirstLLenResult = 0 + assert(actualFirstLLenResult === expectedFirstLLenResult) + + assert(Await.result(client.lPush(foo, List(bar))) === 1, "Failed to insert list item.") + val actualSecondLLenResult = Await.result(client.lLen(key)) + val expectedSecondLLenResult = 1 + assert(actualSecondLLenResult === expectedSecondLLenResult) + + val actuallPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedlPopResult = string2ChanBuf("bar") + assert(actuallPopResult === expectedlPopResult) + + val actualFourthLLenResult = Await.result(client.lLen(key)) + val expectedFourthLLenResult = 0 + assert(actualFourthLLenResult === expectedFourthLLenResult) + } + } + + test("Correctly index elements of an actively changing list", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("lindex") + + val actualFirstLIndexResult = Await.result(client.lIndex(key, 0)) + val expectedFirstLIndexResult = None + assert(actualFirstLIndexResult === expectedFirstLIndexResult) + + val actualFirstLPushResult = Await.result(client.lPush(key, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLIndexResult = Await.result(client.lIndex(key, 0)) + .getOrElse(fail(IndexFailureMessage)) + val expectedSecondLIndexResult = bar + assert(actualSecondLIndexResult === expectedSecondLIndexResult) + + val actualSecondLPushResult = Await.result(client.lPush(key, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + val actualThirdLIndexResult = Await.result(client.lIndex(key, 0)) + .getOrElse(fail(IndexFailureMessage)) + val expectedThirdLIndexResult = baz + assert(actualThirdLIndexResult === expectedThirdLIndexResult) + + val actualFirstLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstLPopResult = baz + assert(actualFirstLPopResult === expectedFirstLPopResult) + + val actualFourthLIndexResult = Await.result(client.lIndex(key, 0)) + .getOrElse(fail(IndexFailureMessage)) + val expectedFourthLIndexResult = bar + assert(actualFourthLIndexResult === expectedFourthLIndexResult) + + val actualSecondLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondLPopResult = bar + assert(actualSecondLPopResult === expectedSecondLPopResult) + } + } + + test("Correctly insert before & after a pushed element", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("linsert") + val PivotFailureMessage = "Pivot not found" + + val actualFirstLPushResult = Await.result(client.lPush(key, List(moo))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualFirstInsertAfterResult = Await.result(client.lInsertAfter(key, moo, bar)) + .getOrElse(fail(PivotFailureMessage)) + val expectedFirstInsertAfterResult = 2 + assert(actualFirstInsertAfterResult === expectedFirstInsertAfterResult) + + val actualFirstInsertBeforeResult = Await.result(client.lInsertBefore(key, moo, foo)) + .getOrElse(fail(PivotFailureMessage)) + val expectedFirstInsertBeforeResult = 3 + assert(actualFirstInsertBeforeResult === expectedFirstInsertBeforeResult) + + val actualFirstLPopResult= Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstLPopResult = foo + assert(actualFirstLPopResult === expectedFirstLPopResult) + + val actualSecondLPopResult= Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondLPopResult = moo + assert(actualSecondLPopResult === expectedSecondLPopResult) + + val actualThirdLPopResult= Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedThirdLPopResult = bar + assert(actualThirdLPopResult === expectedThirdLPopResult) + } + } + + test("Correctly Push -->> Remove -->> Pop elements in order", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("lremove") + + val actualFirstLPushResult = Await.result(client.lPush(key, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLPushResult = Await.result(client.lPush(key, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + val actualLRemoveResult = Await.result(client.lRem(key, 1, baz)) + val expectedRemoveResult = 1 + assert(actualLRemoveResult === expectedRemoveResult) + + val actualLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedLPopResult = bar + assert(actualLPopResult === expectedLPopResult) + } + } + + test("Correctly push members, set one, then pop them off in order", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("lset") + + val actualFirstLPushResult = Await.result(client.lPush(key, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLPushResult = Await.result(client.lPush(key, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + /* + * We ingloriously side effect here as the API returns no verification, + * if the key isn't found in the List a ServerError is thrown + */ + Await.result(client.lSet(key, 0, moo)) + + val actualFirstLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstLPopResult = moo + assert(actualFirstLPopResult === expectedFirstLPopResult) + + val actualSecondLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondLPopResult = bar + assert(actualSecondLPopResult === expectedSecondLPopResult) + } + } + + test("Correctly push members, examine the range, then pop them off", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("lrange") + + val actualFirstLPushResult = Await.result(client.lPush(key, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLPushResult = Await.result(client.lPush(key, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + val actualLRangeResult = Await.result(client.lRange(key, 0, -1)) + val expectedLRangeResult = List(baz, bar) + assert(actualLRangeResult === expectedLRangeResult) + + val actualFirstLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstLPopResult = baz + assert(actualFirstLPopResult === expectedFirstLPopResult) + + val actualSecondLPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondLPopResult = bar + assert(actualSecondLPopResult === expectedSecondLPopResult) + } + } + + test("Correctly push members, the poll members queue style (RPOP)", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("rpop") + + val actualFirstLPushResult = Await.result(client.lPush(key, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLPushResult = Await.result(client.lPush(key, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + val actualFirstRPopResult = Await.result(client.rPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstRPopResult = bar + assert(actualFirstRPopResult === expectedFirstRPopResult) + + val actualSecondRPopResult = Await.result(client.rPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondRPopResult = baz + assert(actualSecondRPopResult === expectedSecondRPopResult) + } + } + + test("Correctly push then pop members from the HEAD (RPUSH RPOP)", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("rpush") + + val actualFirstRPushResult = Await.result(client.rPush(key, List(bar))) + val expectedFirstRPushResult = 1 + assert(actualFirstRPushResult === expectedFirstRPushResult) + + val actualSecondRPushResult = Await.result(client.rPush(key, List(baz))) + val expectedSecondRPushResult = 2 + assert(actualSecondRPushResult === expectedSecondRPushResult) + + val actualFirstRPopResult = Await.result(client.rPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstRPopResult = baz + assert(actualFirstRPopResult === expectedFirstRPopResult) + + val actualSecondRPopResult = Await.result(client.rPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondRPopResult = bar + assert(actualSecondRPopResult === expectedSecondRPopResult) + } + } + + ignore("Correctly push and trim members, then pop the two remaining", RedisTest, ClientTest) { + withRedisClient { client => + val key = string2ChanBuf("ltrim") + + val actualFirstLPushResult = Await.result(client.lPush(key, List(bar))) + val expectedFirstLPushResult = 1 + assert(actualFirstLPushResult === expectedFirstLPushResult) + + val actualSecondLPushResult = Await.result(client.lPush(key, List(baz))) + val expectedSecondLPushResult = 2 + assert(actualSecondLPushResult === expectedSecondLPushResult) + + val actualThirdLPushResult = Await.result(client.lPush(key, List(moo))) + val expectedThirdLPushResult = 3 + assert(actualThirdLPushResult === expectedThirdLPushResult) + + /* + * We ingloriously side effect here as the API returns no verification, + * if the key isn't found in the List a ServerError is thrown + */ + Await.result(client.lTrim(key, 0, 1)) + + val actualFourthLPushResult = Await.result(client.lPush(key, List(moo))) + val expectedFourthLPushResult = 3 + assert(actualFourthLPushResult === expectedFourthLPushResult) + + /* + * We ingloriously side effect here as the API returns no verification, + * if the key isn't found in the List a ServerError is thrown + */ + Await.result(client.lTrim(key, 0, 1)) + + val actualFirstRPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedFirstRPopResult = boo + assert(actualFirstRPopResult === expectedFirstRPopResult) + + val actualSecondRPopResult = Await.result(client.lPop(key)) + .getOrElse(fail(PopFailureMessage)) + val expectedSecondRPopResult = moo + assert(actualSecondRPopResult === expectedSecondRPopResult) + } + /*"push members, trimming as we go. then pop off the two remaining." in { + val key = StringToChannelBuffer("ltrim") + Await.result(client.lPush(key, List(bar))) mustEqual 1 + Await.result(client.lPush(key, List(baz))) mustEqual 2 + Await.result(client.lPush(key, List(boo))) mustEqual 3 + Await.result(client.lTrim(key, 0, 1)) + Await.result(client.lPush(key, List(moo))) mustEqual 3 + Await.result(client.lTrim(key, 0, 1)) + Await.result(client.rPop(key)) map (CBToString(_) mustEqual "boo") + Await.result(client.rPop(key)) map (CBToString(_) mustEqual "moo") + }*/ + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala new file mode 100644 index 00000000000..92138340b76 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala @@ -0,0 +1,224 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.protocol._ +import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} +import com.twitter.util.Await + +final class ListClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { + + test("LLEN should return the length of the list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualFirstLlenReply = Await.result(client(LLen(foo))) + val expectedFirstLlenReply = IntegerReply(1) + assert(actualFirstLlenReply === expectedFirstLlenReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualSecondLlenReply = Await.result(client(LLen(foo))) + val expectedSecondLlenReply = IntegerReply(2) + assert(actualSecondLlenReply === expectedSecondLlenReply) + } + } + + test("LINDEX should get an element from a list by its index", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualFirstLIndexReply = client(LIndex(foo, 0)) + val expectedFirstLIndexReply = chanBuf2String(bar) + assertBulkReply(actualFirstLIndexReply, expectedFirstLIndexReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(baz)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualSecondLIndexReply = client(LIndex(foo, 0)) + val expectedSecondLIndexReply = chanBuf2String(baz) + assertBulkReply(actualSecondLIndexReply, expectedSecondLIndexReply) + + val actualThirdLIndexReply = client(LIndex(foo, 1)) + val expectedThirdLIndexReply = chanBuf2String(bar) + assertBulkReply(actualThirdLIndexReply, expectedThirdLIndexReply) + } + } + + test("LINSERT should insert an element before or after another element in a list", + ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualLInsertReply = Await.result(client(LInsert(foo, "BEFORE", bar, moo))) + val expectedLInsertReply = IntegerReply(2) + assert(actualLInsertReply == expectedLInsertReply) + } + } + + test("LPOP should remove and get the first element in a list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(moo)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualFirstLPopReply = client(LPop(foo)) + val expectedFirstLPopReply = chanBuf2String(moo) + assertBulkReply(actualFirstLPopReply, expectedFirstLPopReply) + + val actualSecondLPopReply = client(LPop(foo)) + val expectedSecondLPopReply = chanBuf2String(bar) + assertBulkReply(actualSecondLPopReply, expectedSecondLPopReply) + } + } + + test("LPUSH should prepend one or multiple values to a list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualFirstLlenReply = Await.result(client(LLen(foo))) + val expectedFirstLlenReply = IntegerReply(1) + assert(actualFirstLlenReply === expectedFirstLlenReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(baz)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualSecondLlenReply = Await.result(client(LLen(foo))) + val expectedSecondLlenReply = IntegerReply(2) + assert(actualSecondLlenReply === expectedSecondLlenReply) + } + } + + test("LREM should remove elements from a list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualLRemReply = Await.result(client(LRem(foo, 1, bar))) + val expectedLRemReply = IntegerReply(1) + assert(actualLRemReply === expectedLRemReply) + + val actualLRangeReply = client(LRange(foo, 0, -1)) + val expectedLRangeReply = List(chanBuf2String(bar)) + assertMBulkReply(actualLRangeReply, expectedLRangeReply) + } + } + + test("LSET should et the value of an element in a list by its index", ClientServerTest, + RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualLSetReply = Await.result(client(LSet(foo, 1, baz))) + assert(actualLSetReply === OKStatusReply) + + val actualLRangeReply = client(LRange(foo, 0, -1)) + val expectedLRangeReply = List(chanBuf2String(bar), chanBuf2String(baz)) + assertMBulkReply(actualLRangeReply, expectedLRangeReply) + } + } + + test("LRANGE should get a range of elements from a list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualLRangeReply = client(LRange(foo, 0, -1)) + val expectedLRangeReply = List(chanBuf2String(bar), chanBuf2String(bar)) + assertMBulkReply(actualLRangeReply, expectedLRangeReply) + } + } + + test("RPOP should remove and get the last element in a list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(baz)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualFirstRPopReply = client(RPop(foo)) + val expectedFirstRPopReply = chanBuf2String(bar) + assertBulkReply(actualFirstRPopReply, expectedFirstRPopReply) + + val actualSecondRPopReply = client(RPop(foo)) + val expectedSecondRPopReply = chanBuf2String(baz) + assertBulkReply(actualSecondRPopReply, expectedSecondRPopReply) + } + } + + test("RPUSH should append one or multiple values to a list", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstRPushResult = Await.result(client(RPush(foo, List(moo)))) + val expectedFirstRPushResult = IntegerReply(1) + assert(actualFirstRPushResult === expectedFirstRPushResult) + + val actualSecondRPushResult = Await.result(client(RPush(foo, List(boo)))) + val expectedSecondRPushResult = IntegerReply(2) + assert(actualSecondRPushResult === expectedSecondRPushResult) + } + } + + test("LTRIM should trim a list to the specified range", ClientServerTest, RedisTest) { + withRedisClient { client => + val actualFirstLPushReply = Await.result(client(LPush(foo, List(moo)))) + val expectedFirstLPushReply = IntegerReply(1) + assert(actualFirstLPushReply === expectedFirstLPushReply) + + val actualSecondLPushReply = Await.result(client(LPush(foo, List(boo)))) + val expectedSecondLPushReply = IntegerReply(2) + assert(actualSecondLPushReply === expectedSecondLPushReply) + + val actualThirdLPushReply = Await.result(client(LPush(foo, List(baz)))) + val expectedThirdLPushReply = IntegerReply(3) + assert(actualThirdLPushReply === expectedThirdLPushReply) + + val actualFirstLTrimReply = Await.result(client(LTrim(foo, 0, 1))) + assert(actualFirstLTrimReply === OKStatusReply) + + val actualFourthLPushReply = Await.result(client(LPush(foo, List(bar)))) + val expectedFourthLPushReply = IntegerReply(3) + assert(actualFourthLPushReply === expectedFourthLPushReply) + + val actualSecondLTrimReply = Await.result(client(LTrim(foo, 0, 1))) + assert(actualSecondLTrimReply === OKStatusReply) + + val actualLRangeReply = client(LRange(foo, 0, -1)) + val expectedLRangeReply = List(chanBuf2String(bar), chanBuf2String(baz)) + assertMBulkReply(actualLRangeReply, expectedLRangeReply) + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala new file mode 100644 index 00000000000..e59c9c938c7 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala @@ -0,0 +1,25 @@ +package com.twitter.finagle.redis.protocol + +import com.twitter.conversions.time._ +import com.twitter.finagle.redis.ClientError +import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.tags.CodecTest +import com.twitter.finagle.redis.util.CBToString +import com.twitter.util.Time + +final class ListCodecSuite extends FinagleRedisRequestTest { + + test("Correctly encode LPUSH for key value pair", CodecTest) { + val expectedKey = "foo" + val expectedValue = "bar" + unwrap(codec(wrap("LPUSH foo bar\r\n"))) { + case LPush(key, List(value)) => { + val actualKey = CBToString(key) + assert(actualKey === expectedKey) + + val actualValue = CBToString(value) + assert(actualValue === expectedValue) + } + } + } +} From 73b84b5b14f484f882178451b022e79f3bbdc1c6 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Sat, 23 Aug 2014 01:29:36 -0500 Subject: [PATCH 08/10] Refacotred FinagleRedisClientSuite trait to naming standard of FinalgeRedisClientTest --- .../twitter/finagle/redis/wip/FinagleRedisTest.scala | 2 +- .../connection/ConnectionClientIntegrationSuite.scala | 4 ++-- .../wip/commands/keys/KeyClientIntegrationSuite.scala | 4 ++-- .../wip/commands/list/ListClientIntegrationSuite.scala | 4 ++-- .../redis/wip/commands/list/ListCodecSuite.scala | 10 +++------- .../commands/server/ServerClientIntegrationSuite.scala | 4 ++-- .../strings/StringClientIntegrationSuite.scala | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala index 51b0a2e682b..aa74b7f8877 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala @@ -48,7 +48,7 @@ trait FinagleRedisRequestTest extends FinagleRedisTest { } } -trait FinagleRedisClientSuite extends FinagleRedisTest with BeforeAndAfterAll { +trait FinagleRedisClientTest extends FinagleRedisTest with BeforeAndAfterAll { override def beforeAll(configMap: Map[String, Any]): Unit = RedisCluster.start() override def afterAll(configMap: Map[String, Any]): Unit = RedisCluster.stop() diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala index 13b9c1d1fb5..e93c82229a6 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala @@ -1,11 +1,11 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.naggati.FinagleRedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} -final class ConnectionClientIntegrationSuite extends FinagleRedisClientSuite { +final class ConnectionClientIntegrationSuite extends FinagleRedisClientTest { test("Correctly perform the SELECT command", RedisTest, ClientTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala index d2f7ce4658c..4a52410a7b8 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala @@ -1,11 +1,11 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.naggati.FinagleRedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} -final class KeyClientIntegrationSuite extends FinagleRedisClientSuite { +final class KeyClientIntegrationSuite extends FinagleRedisClientTest { test("Correctly perform the DEL command", RedisTest, ClientTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala index c52fa1595b9..952478bd6c6 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala @@ -1,10 +1,10 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.naggati.FinagleRedisClientTest import com.twitter.finagle.redis.tags.{ClientTest, RedisTest} import com.twitter.util.Await -final class ListClientIntegrationSuite extends FinagleRedisClientSuite { +final class ListClientIntegrationSuite extends FinagleRedisClientTest { val IndexFailureMessage = "Unknown failure calling Index" val PopFailureMessage = "Failure popping element from list" diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala index e59c9c938c7..592a978a4bc 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala @@ -1,23 +1,19 @@ package com.twitter.finagle.redis.protocol -import com.twitter.conversions.time._ -import com.twitter.finagle.redis.ClientError import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest import com.twitter.finagle.redis.tags.CodecTest -import com.twitter.finagle.redis.util.CBToString -import com.twitter.util.Time final class ListCodecSuite extends FinagleRedisRequestTest { test("Correctly encode LPUSH for key value pair", CodecTest) { - val expectedKey = "foo" + val expectedKey = "foo" val expectedValue = "bar" unwrap(codec(wrap("LPUSH foo bar\r\n"))) { case LPush(key, List(value)) => { - val actualKey = CBToString(key) + val actualKey = chanBuf2String(key) assert(actualKey === expectedKey) - val actualValue = CBToString(value) + val actualValue = chanBuf2String(value) assert(actualValue === expectedValue) } } diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala index cdfc3b405db..464babd82ac 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala @@ -1,11 +1,11 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.naggati.FinagleRedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} -final class ServerClientIntegrationSuite extends FinagleRedisClientSuite { +final class ServerClientIntegrationSuite extends FinagleRedisClientTest { test("Correctly perform the FLUSHALL command", RedisTest, ClientTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala index 239b3017f1b..77043516c01 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala @@ -1,11 +1,11 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientSuite +import com.twitter.finagle.redis.naggati.FinagleRedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} -final class StringClientIntegrationSuite extends FinagleRedisClientSuite { +final class StringClientIntegrationSuite extends FinagleRedisClientTest { test("Correctly perform the APPEND command", RedisTest, ClientTest) { withRedisClient { client => From 133b1a7dedaa18452cdaea02bbc7cb93cd619396 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Tue, 30 Sep 2014 15:03:58 -0500 Subject: [PATCH 09/10] Added Finagle Redis Set tests, changed assert style to match Moses request --- .../set/SetClientIntegrationSuite.scala | 113 ++++++++++++++++++ .../set/SetClientServerIntegrationSuite.scala | 101 ++++++++++++++++ .../wip/commands/set/SetCodecSuite.scala | 40 +++++++ 3 files changed, 254 insertions(+) create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala create mode 100644 finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala new file mode 100644 index 00000000000..c937c50c4f7 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala @@ -0,0 +1,113 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.tags.{ClientTest, RedisTest} +import com.twitter.util.Await +import scala.collection.{Set => CollectionSet} + +final class SetClientIntegrationSuite extends FinagleRedisClientTest { + + private[this] val oneElemAdded = 1 + private[this] val oneElemAddErrorMessage = "Could not add one element" + private[this] val key = string2ChanBuf("member") + + test("Correctly add, then pop members of a set", RedisTest, ClientTest) { + withRedisClient { client => + assert(Await.result(client.sAdd(key, List(bar))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sPop(key)) === Some(bar), "Could not remove bar") + + assert(Await.result(client.sAdd(key, List(baz))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sPop(key)) === Some(baz), "Could not remove baz") + } + } + + test("Correctly add, then pop members from a set while counting them", RedisTest, ClientTest) { + withRedisClient { client => + assert(Await.result(client.sCard(key)) === 0) + assert(Await.result(client.sAdd(key, List(bar))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sCard(key)) === 1) + + assert(Await.result(client.sAdd(key, List(baz))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sCard(key)) === 2) + + Await.result(client.sPop(key)) + assert(Await.result(client.sCard(key)) === 1) + Await.result(client.sPop(key)) + assert(Await.result(client.sCard(key)) === 0) + } + } + + test("Correctly add and pop members from a set, while looking at the set", RedisTest, + ClientTest) { + withRedisClient { client => + assert(Await.result(client.sAdd(key, List(foo))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sIsMember(key, foo)) === true, "Foo was not a member of the set") + + assert(Await.result(client.sIsMember(key, baz)) === false, "Baz was found in the set") + assert(Await.result(client.sAdd(key, List(baz))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sIsMember(key, baz)) === true, "Baz was not found in the set") + assert(Await.result(client.sIsMember(key, foo)) === true, "Foo was not a member of the set") + + Await.result(client.sPop(key)) + Await.result(client.sPop(key)) + assert(Await.result(client.sIsMember(key, baz)) === false, "Baz was found in the set") + assert(Await.result(client.sIsMember(key, foo)) === false, "Foo was found in the set") + } + } + + test("Correctly add, examine members of a set, then pop them off and reexamine", RedisTest, + ClientTest) { + withRedisClient { client => + assert(Await.result(client.sAdd(key, List(moo))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sAdd(key, List(boo))) === oneElemAdded, oneElemAddErrorMessage) + + val strings: CollectionSet[String] = Await.result(client.sMembers(key)).map(chanBuf2String(_)) + assert(strings === CollectionSet("moo", "boo")) + + Await.result(client.sPop(key)) + Await.result(client.sPop(key)) + assert(Await.result(client.sMembers(key)) === CollectionSet(), "Collection set was not EMPTY") + } + } + + test("Correctly add members to a set, then remove them", RedisTest, ClientTest) { + withRedisClient { client => + assert(Await.result(client.sAdd(key, List(moo))) === oneElemAdded, oneElemAddErrorMessage) + assert(Await.result(client.sAdd(key, List(boo))) === oneElemAdded, oneElemAddErrorMessage) + + assert(Await.result(client.sRem(key, List(moo))) === 1, "Could not remove one Element") + assert(Await.result(client.sRem(key, List(boo))) === 1, "Could not remove one Element") + assert(Await.result(client.sRem(key, List(moo))) === 0, "Removed an element when it should " + + "not have been possible") + } + } + + test("Correctly add member to a set, and return random", RedisTest, ClientTest) { + withRedisClient { client => + val allMembers = Seq(foo, bar) + val empty = Await.result(client.sRandMember(key)) + assert(empty.size === 0, "The empty set was not empty!") + + allMembers.foreach(m => { + assert(Await.result(client.sAdd(key, List(m))) === oneElemAdded, oneElemAddErrorMessage) + }) + + val oneMember = Await.result(client.sRandMember(key)) + assert(oneMember.size === 1, "The one member set had an incorrect number of members") + assert(allMembers.contains(oneMember.head) === true) + + val twoMembers = Await.result(client.sRandMember(key, count = Some(2))) + assert(twoMembers.size === 2, "The two member set had an incorrect number of members") + assert(twoMembers.forall(allMembers.contains(_)) === true, "The two member set did not " + + "match the original Sequence") + + val setMembers = Await.result(client.sRandMember(key, count = Some(5))) + assert(setMembers.size === 2) + assert(setMembers.forall(allMembers.contains(_)) === true, "The set members did not match " + + "the original Sequence") + + val negMembers = Await.result(client.sRandMember(key, count = Some(-4))) + assert(negMembers.size === 4, "The set did not handle a negative member") + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala new file mode 100644 index 00000000000..9013c81a01b --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala @@ -0,0 +1,101 @@ +package com.twitter.finagle.redis.integration + +import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.protocol._ +import com.twitter.finagle.redis.util.ReplyFormat +import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} +import com.twitter.util.Await +import scala.collection.{Set => CollectionSet} + +final class SetClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { + + private[this] val key = string2ChanBuf("member") + private[this] val addMemErrMessage = "Could not add a member to the set" + + test("SADD should return the number of elements that were added to the set", ClientServerTest, + RedisTest) { + withRedisClient { client => + assert(Await.result(client(SAdd(key, List(foo)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SAdd(key, List(foo)))) === IntegerReply(0), "Added unknown " + + "member to set") + assert(Await.result(client(SAdd(key, List(bar)))) === IntegerReply(1), addMemErrMessage) + } + } + + test("SMEMBERS should return an array of all elements in the set", ClientServerTest, RedisTest) { + withRedisClient { client => + assert(Await.result(client(SAdd(key, List(foo)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SAdd(key, List(bar)))) === IntegerReply(1), addMemErrMessage) + Await.result(client(SMembers(key))) match { + case MBulkReply(message) => { + val messageSet = ReplyFormat.toString(message).toSet + assert(messageSet === CollectionSet("foo", "bar")) + } + case EmptyMBulkReply() => fail("Should not have recieved an EmptyMBulkReply") + case _ => fail("Received incorrect reply type") + } + } + } + + test("SISMEMBER should return a 1 if a member is an element of the set", ClientServerTest, + RedisTest) { + withRedisClient { client => + assert(Await.result(client(SAdd(key, List(foo)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SIsMember(key, foo))) === IntegerReply(1), "Could not find member") + assert(Await.result(client(SAdd(key, List(bar)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SIsMember(key, bar))) === IntegerReply(1), "Could not find member") + } + } + + test("SISMEMBER should return a 0 if a member is not an element of the set", ClientServerTest, + RedisTest) { + withRedisClient { client => + assert(Await.result(client(SIsMember(key, foo))) === IntegerReply(0), "Found member where " + + "none was expected") + assert(Await.result(client(SIsMember(key, bar))) === IntegerReply(0), "Found member where " + + "none was expected") + } + } + + + test("SCARD should return the cardinality of the set, or 0 if key does not exist", RedisTest, + ClientServerTest) { + withRedisClient { client => + assert(Await.result(client(SCard(key))) === IntegerReply(0), "Found member where none was " + + "expected") + + assert(Await.result(client(SAdd(key, List(foo)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SCard(key))) === IntegerReply(1), "Found incorrect cardinality") + + assert(Await.result(client(SAdd(key, List(moo)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SCard(key))) === IntegerReply(2), "Found incorrect cardinality") + } + } + + test("SREM should return the number of members that were removed from the set", ClientServerTest, + RedisTest) { + withRedisClient { client => + assert(Await.result(client(SAdd(key, List(baz)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SAdd(key, List(moo)))) === IntegerReply(1), addMemErrMessage) + + assert(Await.result(client(SRem(key, List(moo)))) === IntegerReply(1), "Could not remove " + + "element from set") + assert(Await.result(client(SIsMember(key,moo))) === IntegerReply(0), "Found member where " + + "none was expected") + } + } + + test("SPOP should return the removed element, or 0 when key does not exist", ClientServerTest, + RedisTest) { + withRedisClient { client => + assert(Await.result(client(SAdd(key, List(baz)))) === IntegerReply(1), addMemErrMessage) + assert(Await.result(client(SAdd(key, List(bar)))) === IntegerReply(1), addMemErrMessage) + + assert(Await.result(client(SCard(key))) === IntegerReply(2), "Found incorrect cardinality") + Await.result(client(SPop(key))) + assert(Await.result(client(SCard(key))) === IntegerReply(1), "Found incorrect cardinality") + Await.result(client(SPop(key))) + assert(Await.result(client(SCard(key))) === IntegerReply(0), "Found incorrect cardinality") + } + } +} diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala new file mode 100644 index 00000000000..80aa1867e59 --- /dev/null +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala @@ -0,0 +1,40 @@ +package com.twitter.finagle.redis.protocol + +import com.twitter.finagle.redis.ClientError +import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.tags.CodecTest + +final class SetCodecSuite extends FinagleRedisRequestTest { + + test("Correctly encode SADD", CodecTest) { + unwrap(codec(wrap("SADD foo bar\r\n"))) { + case SAdd(key, List(member)) => { + assert(key === foo) + assert(member === bar) + } + } + } + + test("Throw a ClientError if SINTER is called with no key", CodecTest) { + intercept[ClientError] { + codec((wrap("SINTER\r\n"))) + } + } + + test("Corectly encode SINTER for one key", CodecTest) { + unwrap(codec(wrap("SINTER foo\r\n"))) { + case SInter(keys) => { + assert(keys(0) === foo) + } + } + } + + test("Correctly encode SINTER for two keys", CodecTest) { + unwrap(codec(wrap("SINTER foo bar\r\n"))) { + case SInter(keys) => { + assert(keys(0) === foo) + assert(keys(1) === bar) + } + } + } +} From a361b3d171108eaea2d6f036c039c152c01b990f Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Davis" Date: Fri, 3 Oct 2014 14:19:08 -0500 Subject: [PATCH 10/10] Removing Finale* from trait names, adding @RunWith(classOf[JUnitRunner]) to all tests --- .../wip/{FinagleRedisTest.scala => RedisTest.scala} | 11 +++++------ .../redis/wip/codec/RequestEncodingSuite.scala | 7 +++++-- .../redis/wip/codec/ResponseDecodingSuite.scala | 5 ++++- .../redis/wip/codec/ResponseEncodingSuite.scala | 6 +++++- .../connection/ConnectionClientIntegrationSuite.scala | 7 +++++-- .../wip/commands/keys/KeyClientIntegrationSuite.scala | 7 +++++-- .../keys/KeyClientServerIntegrationSuite.scala | 7 +++++-- .../redis/wip/commands/keys/KeyCodecSuite.scala | 7 +++++-- .../commands/list/ListClientIntegrationSuite.scala | 7 +++++-- .../list/ListClientServerIntegrationSuite.scala | 7 +++++-- .../redis/wip/commands/list/ListCodecSuite.scala | 7 +++++-- .../server/ServerClientIntegrationSuite.scala | 7 +++++-- .../server/ServerClientServerIntegrationSuite.scala | 7 +++++-- .../redis/wip/commands/server/ServerCodecSuite.scala | 7 +++++-- .../wip/commands/set/SetClientIntegrationSuite.scala | 7 +++++-- .../set/SetClientServerIntegrationSuite.scala | 7 +++++-- .../redis/wip/commands/set/SetCodecSuite.scala | 7 +++++-- .../strings/StringClientIntegrationSuite.scala | 7 +++++-- 18 files changed, 89 insertions(+), 38 deletions(-) rename finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/{FinagleRedisTest.scala => RedisTest.scala} (93%) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/RedisTest.scala similarity index 93% rename from finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala rename to finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/RedisTest.scala index aa74b7f8877..decedb6cab1 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/FinagleRedisTest.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/RedisTest.scala @@ -12,8 +12,7 @@ import java.net.InetSocketAddress import com.twitter.finagle.Service import com.twitter.finagle.redis.Client - -trait FinagleRedisTest extends FunSuite { +trait RedisTest extends FunSuite { protected def wrap(s: String): ChannelBuffer = StringToChannelBuffer(s) protected def string2ChanBuf(s: String): ChannelBuffer = wrap(s) protected def chanBuf2String(cb: ChannelBuffer): String = CBToString(cb) @@ -26,12 +25,12 @@ trait FinagleRedisTest extends FunSuite { } -trait FinagleRedisResponseTest extends FinagleRedisTest { +trait RedisResponseTest extends RedisTest { protected val replyCodec = new ReplyCodec protected val (codec, counter) = TestCodec(replyCodec.decode, replyCodec.encode) } -trait FinagleRedisRequestTest extends FinagleRedisTest { +trait RedisRequestTest extends RedisTest { protected val commandCodec = new CommandCodec protected val (codec, counter) = TestCodec(commandCodec.decode, commandCodec.encode) @@ -48,7 +47,7 @@ trait FinagleRedisRequestTest extends FinagleRedisTest { } } -trait FinagleRedisClientTest extends FinagleRedisTest with BeforeAndAfterAll { +trait RedisClientTest extends RedisTest with BeforeAndAfterAll { override def beforeAll(configMap: Map[String, Any]): Unit = RedisCluster.start() override def afterAll(configMap: Map[String, Any]): Unit = RedisCluster.stop() @@ -70,7 +69,7 @@ trait FinagleRedisClientTest extends FinagleRedisTest with BeforeAndAfterAll { } } -trait FinagleRedisClientServerIntegrationTest extends FinagleRedisTest with BeforeAndAfterAll { +trait RedisClientServerIntegrationTest extends RedisTest with BeforeAndAfterAll { private[this] lazy val svcClient = ClientBuilder() .name("redis-client") diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/RequestEncodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/RequestEncodingSuite.scala index d82cc5b4ebc..69374f821d3 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/RequestEncodingSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/RequestEncodingSuite.scala @@ -1,9 +1,12 @@ package com.twitter.finagle.redis.protocol -import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.naggati.RedisRequestTest import com.twitter.finagle.redis.tags.CodecTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class RequestEncodingSuite extends FinagleRedisRequestTest { +@RunWith(classOf[JUnitRunner]) +final class RequestEncodingSuite extends RedisRequestTest { test("Correctly encode inline requests", CodecTest) { val actualEncoding = codec.send(Get(foo)) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala index f8d0ec2a620..ac65e5fec0e 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseDecodingSuite.scala @@ -13,8 +13,11 @@ import com.twitter.finagle.redis.util.StringToChannelBuffer import org.jboss.netty.buffer.ChannelBuffer import org.scalatest.FunSuite import com.twitter.finagle.redis.protocol.{EmptyBulkReply, EmptyMBulkReply} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ResponseDecodingSuite extends FinagleRedisResponseTest { +@RunWith(classOf[JUnitRunner]) +final class ResponseDecodingSuite extends RedisResponseTest { ignore("Multi-bulk replies") { val actualEncoding = codec(wrap("*4\r\n")) val expectedEncoding = Nil diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala index 1ee891ddde5..3f0585065a2 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/codec/ResponseEncodingSuite.scala @@ -4,8 +4,12 @@ import com.twitter.finagle.redis.protocol.{BulkReply, ErrorReply, IntegerReply, StatusReply, ReplyCodec} import com.twitter.finagle.redis.tags.CodecTest import com.twitter.finagle.redis.util.StringToChannelBuffer +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ResponseEncodingSuite extends FinagleRedisResponseTest { + +@RunWith(classOf[JUnitRunner]) +final class ResponseEncodingSuite extends RedisResponseTest { test("Correctly encode status replies", CodecTest) { val actualEncoding = codec.send(StatusReply("OK")) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala index e93c82229a6..3380f24f126 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/connection/ConnectionClientIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.naggati.RedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ConnectionClientIntegrationSuite extends FinagleRedisClientTest { +@RunWith(classOf[JUnitRunner]) +final class ConnectionClientIntegrationSuite extends RedisClientTest { test("Correctly perform the SELECT command", RedisTest, ClientTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala index 4a52410a7b8..d46cf278cc2 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.naggati.RedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class KeyClientIntegrationSuite extends FinagleRedisClientTest { +@RunWith(classOf[JUnitRunner]) +final class KeyClientIntegrationSuite extends RedisClientTest { test("Correctly perform the DEL command", RedisTest, ClientTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala index 53972e8cd5e..a00d36a4e40 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyClientServerIntegrationSuite.scala @@ -2,13 +2,16 @@ package com.twitter.finagle.redis.integration import com.twitter.conversions.time._ import com.twitter.finagle.redis.ClientError -import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.naggati.RedisClientServerIntegrationTest import com.twitter.finagle.redis.protocol._ import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} import com.twitter.util.{Await, Future, Time} import org.jboss.netty.buffer.ChannelBuffer +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class KeyClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { +@RunWith(classOf[JUnitRunner]) +final class KeyClientServerIntegrationSuite extends RedisClientServerIntegrationTest { test("DELETE two keys", ClientServerTest, RedisTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala index b1033ed5cdc..936180ce44a 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/keys/KeyCodecSuite.scala @@ -2,11 +2,14 @@ package com.twitter.finagle.redis.protocol import com.twitter.conversions.time._ import com.twitter.finagle.redis.ClientError -import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.naggati.RedisRequestTest import com.twitter.finagle.redis.tags.CodecTest import com.twitter.util.Time +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class KeyCodecSuite extends FinagleRedisRequestTest { +@RunWith(classOf[JUnitRunner]) +final class KeyCodecSuite extends RedisRequestTest { test("Correctly encode DELETE for one key", CodecTest) { val actualEncoding = codec(wrap("DEL foo\r\n")) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala index 952478bd6c6..d12eeaf8512 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientIntegrationSuite.scala @@ -1,10 +1,13 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.naggati.RedisClientTest import com.twitter.finagle.redis.tags.{ClientTest, RedisTest} import com.twitter.util.Await +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ListClientIntegrationSuite extends FinagleRedisClientTest { +@RunWith(classOf[JUnitRunner]) +final class ListClientIntegrationSuite extends RedisClientTest { val IndexFailureMessage = "Unknown failure calling Index" val PopFailureMessage = "Failure popping element from list" diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala index 92138340b76..3f523627a6c 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListClientServerIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.naggati.RedisClientServerIntegrationTest import com.twitter.finagle.redis.protocol._ import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} import com.twitter.util.Await +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ListClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { +@RunWith(classOf[JUnitRunner]) +final class ListClientServerIntegrationSuite extends RedisClientServerIntegrationTest { test("LLEN should return the length of the list", ClientServerTest, RedisTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala index 592a978a4bc..b2c332a4bf1 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/list/ListCodecSuite.scala @@ -1,9 +1,12 @@ package com.twitter.finagle.redis.protocol -import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.naggati.RedisRequestTest import com.twitter.finagle.redis.tags.CodecTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ListCodecSuite extends FinagleRedisRequestTest { +@RunWith(classOf[JUnitRunner]) +final class ListCodecSuite extends RedisRequestTest { test("Correctly encode LPUSH for key value pair", CodecTest) { val expectedKey = "foo" diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala index 464babd82ac..362c606b9ca 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.naggati.RedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ServerClientIntegrationSuite extends FinagleRedisClientTest { +@RunWith(classOf[JUnitRunner]) +final class ServerClientIntegrationSuite extends RedisClientTest { test("Correctly perform the FLUSHALL command", RedisTest, ClientTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala index 957f4ec6cc4..245e0a6649a 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerClientServerIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.naggati.RedisClientServerIntegrationTest import com.twitter.finagle.redis.protocol._ import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} import com.twitter.util.Await +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ServerClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { +@RunWith(classOf[JUnitRunner]) +final class ServerClientServerIntegrationSuite extends RedisClientServerIntegrationTest { test("FLUSHALL should return a StatusReply(\"OK\")", ClientServerTest, RedisTest) { withRedisClient { client => diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala index b3c79a9c16a..bd1baeb7429 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/server/ServerCodecSuite.scala @@ -1,9 +1,12 @@ package com.twitter.finagle.redis.protocol -import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.naggati.RedisRequestTest import com.twitter.finagle.redis.tags.CodecTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class ServerCodecSuite extends FinagleRedisRequestTest { +@RunWith(classOf[JUnitRunner]) +final class ServerCodecSuite extends RedisRequestTest { test("Correctly encode FLUSHALL", CodecTest) { val actualEncoding = codec(wrap("FLUSHALL\r\n")) diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala index c937c50c4f7..168d3c79c14 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.naggati.RedisClientTest import com.twitter.finagle.redis.tags.{ClientTest, RedisTest} import com.twitter.util.Await import scala.collection.{Set => CollectionSet} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class SetClientIntegrationSuite extends FinagleRedisClientTest { +@RunWith(classOf[JUnitRunner]) +final class SetClientIntegrationSuite extends RedisClientTest { private[this] val oneElemAdded = 1 private[this] val oneElemAddErrorMessage = "Could not add one element" diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala index 9013c81a01b..c0587d1de38 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetClientServerIntegrationSuite.scala @@ -1,13 +1,16 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientServerIntegrationTest +import com.twitter.finagle.redis.naggati.RedisClientServerIntegrationTest import com.twitter.finagle.redis.protocol._ import com.twitter.finagle.redis.util.ReplyFormat import com.twitter.finagle.redis.tags.{ClientServerTest, RedisTest} import com.twitter.util.Await import scala.collection.{Set => CollectionSet} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class SetClientServerIntegrationSuite extends FinagleRedisClientServerIntegrationTest { +@RunWith(classOf[JUnitRunner]) +final class SetClientServerIntegrationSuite extends RedisClientServerIntegrationTest { private[this] val key = string2ChanBuf("member") private[this] val addMemErrMessage = "Could not add a member to the set" diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala index 80aa1867e59..307b4ed0af3 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/set/SetCodecSuite.scala @@ -1,10 +1,13 @@ package com.twitter.finagle.redis.protocol import com.twitter.finagle.redis.ClientError -import com.twitter.finagle.redis.naggati.FinagleRedisRequestTest +import com.twitter.finagle.redis.naggati.RedisRequestTest import com.twitter.finagle.redis.tags.CodecTest +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class SetCodecSuite extends FinagleRedisRequestTest { +@RunWith(classOf[JUnitRunner]) +final class SetCodecSuite extends RedisRequestTest { test("Correctly encode SADD", CodecTest) { unwrap(codec(wrap("SADD foo bar\r\n"))) { diff --git a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala index 77043516c01..d81ef75936f 100644 --- a/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala +++ b/finagle-redis/src/test/scala/com/twitter/finagle/redis/wip/commands/strings/StringClientIntegrationSuite.scala @@ -1,11 +1,14 @@ package com.twitter.finagle.redis.integration -import com.twitter.finagle.redis.naggati.FinagleRedisClientTest +import com.twitter.finagle.redis.naggati.RedisClientTest import com.twitter.finagle.redis.tags.{RedisTest, ClientTest} import com.twitter.util.Await import com.twitter.finagle.redis.util.{CBToString, StringToChannelBuffer} +import org.junit.runner.RunWith +import org.scalatest.junit.JUnitRunner -final class StringClientIntegrationSuite extends FinagleRedisClientTest { +@RunWith(classOf[JUnitRunner]) +final class StringClientIntegrationSuite extends RedisClientTest { test("Correctly perform the APPEND command", RedisTest, ClientTest) { withRedisClient { client =>