PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/finagle-memcached/src/test/scala/com/twitter/finagle/memcached/stress/InterpreterServiceSpec.scala

http://github.com/twitter/finagle
Scala | 47 lines | 41 code | 5 blank | 1 comment | 0 complexity | a7a8d2a24dd01549cebb7caedd2122f4 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.twitter.finagle.memcached.stress
  2. import com.twitter.finagle.Service
  3. import com.twitter.finagle.builder.ClientBuilder
  4. import com.twitter.finagle.memcached.integration.InProcessMemcached
  5. import com.twitter.finagle.memcached.protocol._
  6. import com.twitter.finagle.memcached.protocol.text.Memcached
  7. import com.twitter.finagle.memcached.util.ChannelBufferUtils._
  8. import com.twitter.util.{Await, Time}
  9. import java.net.InetSocketAddress
  10. import org.specs.SpecificationWithJUnit
  11. class InterpreterServiceSpec extends SpecificationWithJUnit {
  12. "InterpreterService" should {
  13. var server: InProcessMemcached = null
  14. var client: Service[Command, Response] = null
  15. doBefore {
  16. server = new InProcessMemcached(new InetSocketAddress(0))
  17. val address = server.start().localAddress
  18. client = ClientBuilder()
  19. .hosts(address)
  20. .codec(new Memcached)
  21. .hostConnectionLimit(1)
  22. .build()
  23. }
  24. doAfter {
  25. server.stop()
  26. }
  27. "set & get" in {
  28. val _key = "key"
  29. val value = "value"
  30. val zero = "0"
  31. val start = System.currentTimeMillis
  32. (0 until 100) map { i =>
  33. val key = _key + i
  34. Await.result(client(Delete(key)))
  35. Await.result(client(Set(key, 0, Time.epoch, value)))
  36. Await.result(client(Get(Seq(key)))) mustEqual Values(Seq(Value(key, value, None, Some(zero))))
  37. }
  38. val end = System.currentTimeMillis
  39. // println("%d ms".format(end - start))
  40. }
  41. }
  42. }