Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - moving finagle-kestrel to ScalaTest #302

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,48 @@ import com.twitter.finagle.kestrel.protocol.Kestrel
import com.twitter.finagle.memcached.util.ChannelBufferUtils._
import com.twitter.io.Charsets
import com.twitter.util.Await
import org.specs.SpecificationWithJUnit
import com.twitter.finagle.thrift.{ClientId, ThriftClientFramedCodec}

class ClientSpec extends SpecificationWithJUnit {
"ConnectedClient" should {
skip("This test requires a Kestrel server to run. Please run manually")

"simple client" in {
val serviceFactory = ClientBuilder()
.hosts("localhost:22133")
.codec(Kestrel())
.hostConnectionLimit(1)
.buildFactory()
val client = Client(serviceFactory)

Await.result(client.delete("foo"))

"set & get" in {
Await.result(client.get("foo")) mustEqual None
Await.result(client.set("foo", "bar"))
Await.result(client.get("foo")) map { _.toString(Charsets.Utf8) } mustEqual Some("bar")
}
}
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.{BeforeAndAfter, FunSuite, Suites}

@RunWith(classOf[JUnitRunner])
class ClientTest extends Suites (
new ConnectedClientTest,
new ThriftConnectedClientTest
)

class ConnectedClientTest extends FunSuite {
val serviceFactory = ClientBuilder()
.hosts("localhost:22133")
.codec(Kestrel())
.hostConnectionLimit(1)
.buildFactory()
val client = Client(serviceFactory)

Await.result(client.delete("foo"))

ignore("simple clientset & get") {
assert(Await.result(client.get("foo")) === None)
Await.result(client.set("foo", "bar"))
assert(Await.result(client.get("foo")).map(f => f.toString(Charsets.Utf8)) === Some("bar"))
}
}

class ThriftConnectedClientTest extends FunSuite {
val serviceFactory = ClientBuilder()
.hosts("localhost:2229")
.codec(ThriftClientFramedCodec(Some(ClientId("testcase"))))
.hostConnectionLimit(1)
.buildFactory()
val client = Client.makeThrift(serviceFactory)

Await.result(client.delete("foo"))

"ThriftConnectedClient" should {
skip("This test requires a Kestrel server to run. Please run manually")

"simple client" in {
val serviceFactory = ClientBuilder()
.hosts("localhost:2229")
.codec(ThriftClientFramedCodec(Some(ClientId("testcase"))))
.hostConnectionLimit(1)
.buildFactory()
val client = Client.makeThrift(serviceFactory)

Await.result(client.delete("foo"))

"set & get" in {
Await.result(client.get("foo")) mustEqual None
Await.result(client.set("foo", "bar"))
Await.result(client.get("foo")) map { _.toString(Charsets.Utf8) } mustEqual Some("bar")
}
}
ignore("set & get") {
assert(Await.result(client.get("foo")) === None)
Await.result(client.set("foo", "bar"))
assert(Await.result(client.get("foo")).map(f => f.toString(Charsets.Utf8)) == Some("bar"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,50 @@ import com.twitter.finagle.kestrel.protocol._
import com.twitter.finagle.memcached.util.ChannelBufferUtils._
import com.twitter.util.{Await, Time}
import java.net.InetSocketAddress
import org.specs.SpecificationWithJUnit

class InterpreterServiceSpec extends SpecificationWithJUnit {
"InterpreterService" should {
var server: Server = null
var client: Service[Command, Response] = null
var address: InetSocketAddress = null

doBefore {
server = new Server(new InetSocketAddress(0))
address = server.start().localAddress.asInstanceOf[InetSocketAddress]
client = ClientBuilder()
.hosts("localhost:" + address.getPort)
.codec(Kestrel())
.hostConnectionLimit(1)
.build()
}

doAfter {
server.stop()
}

val queueName = "name"
val value = "value"

"set & get" in {
val result = for {
_ <- client(Flush(queueName))
_ <- client(Set(queueName, Time.now, value))
r <- client(Get(queueName))
} yield r
Await.result(result, 1.second) mustEqual Values(Seq(Value(queueName, value)))
}

"transactions" in {
"set & get/open & get/abort" in {
val result = for {
_ <- client(Set(queueName, Time.now, value))
_ <- client(Open(queueName))
_ <- client(Abort(queueName))
r <- client(Open(queueName))
} yield r
Await.result(result, 1.second) mustEqual Values(Seq(Value(queueName, value)))
}
}

import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
import org.scalatest.{BeforeAndAfter, FunSuite}

@RunWith(classOf[JUnitRunner])
class InterpreterServiceTest extends FunSuite with BeforeAndAfter {
var server: Server = null
var client: Service[Command, Response] = null
var address: InetSocketAddress = null

before {
server = new Server(new InetSocketAddress(0))
address = server.start().localAddress.asInstanceOf[InetSocketAddress]
client = ClientBuilder()
.hosts("localhost:" + address.getPort)
.codec(Kestrel())
.hostConnectionLimit(1)
.build()
}

after {
server.stop()
}

val queueName = "name"
val value = "value"

test("set & get") {
val result = for {
_ <- client(Flush(queueName))
_ <- client(Set(queueName, Time.now, value))
r <- client(Get(queueName))
} yield r
assert(Await.result(result, 1.second) === Values(Seq(Value(queueName, value))))
}

test("transactions - set & get/open & get/abort") {
val result = for {
_ <- client(Set(queueName, Time.now, value))
_ <- client(Open(queueName))
_ <- client(Abort(queueName))
r <- client(Open(queueName))
} yield r
assert(Await.result(result, 1.second) === Values(Seq(Value(queueName, value))))
}
}
Loading