Skip to content

Commit

Permalink
unit tests compiling and passing
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwills committed Apr 10, 2013
1 parent 23ea104 commit 6c835b9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ object HookupBuild extends Build {
"commons-io" % "commons-io" % "2.1",
"com.typesafe.akka" %% "akka-actor" % "2.1.2" % "compile",
"com.typesafe.akka" %% "akka-testkit" % "2.1.2" % "test",
"org.specs2" %% "specs2" % "1.14" % "test",
// "org.specs2" %% "specs2" % "1.14" % "test",
"org.specs2" %% "specs2" % "1.12.3" % "test",
"junit" % "junit" % "4.10" % "test",
"joda-time" % "joda-time" % "2.1"
),
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/io/backchat/hookup/client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ object HookupClient {
val wireFormat = new AtomicReference[WireFormat](settings.defaultProtocol)

def isConnected =
channel != null && channel.isConnected && _isConnected.isCompleted && _isConnected.future.value.get == Right(Success)
channel != null && channel.isConnected && _isConnected.isCompleted && _isConnected.future.value.get == scala.util.Success(io.backchat.hookup.Success)
// && _isConnected.future.value.get == Right(Success)

private def configureBootstrap() {
val self = this
Expand Down
12 changes: 8 additions & 4 deletions src/main/scala/io/backchat/hookup/examples/ChatClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ object ChatClient {
import DefaultConversions._
//implicit def stringToTextMessage(s: String) = TextMessage(s)

def main(args: Array[String]) {
val system = ActorSystem("ChatClient")

def makeClient(args: Array[String]) = {
if (args.isEmpty) {
sys.error("Specify a name as the argument")
}
val system = ActorSystem("ChatClient")
// val system = ActorSystem("ChatClient")

new HookupClient {
val client = new HookupClient {
val uri = URI.create("ws://localhost:8127/")

val settings: HookupClientConfig = HookupClientConfig(
Expand All @@ -42,11 +43,14 @@ object ChatClient {

connect() onSuccess {
case _
println("connected to: %s" format uri.toASCIIString)
println("connected to: %s" format uri.toASCIIString)
system.scheduler.schedule(2 seconds, 5 second) {
send(args(0) + ": message " + messageCounter.incrementAndGet().toString)
}
}
}
client
}

def main(args: Array[String]) = makeClient(args)
}
7 changes: 6 additions & 1 deletion src/main/scala/io/backchat/hookup/examples/ChatServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object ChatServer {

import DefaultConversions._

def main(args: Array[String]) {
def makeServer() = {
val server = HookupServer(ServerInfo("ChatServer", port = 8127)){
new HookupServerClient {
def receive = {
Expand All @@ -20,9 +20,14 @@ object ChatServer {
case TextMessage(text)
println("broadcasting: " + text + " from " + id)
this >< text
case m: JsonMessage
println("JsonMessage(" + pretty(render(m.content)) + ")")
}
}
}
server.start
server
}

def main(args: Array[String]) { makeServer }
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ServerConfigurationsExample extends Specification with NoTimeConversions {
"A Server with a subprotocols configuration" ! serverWithSubprotocols ^
"A Server with a flash policy configuration" ! serverWithFlashPolicy ^ end

import scala.concurrent.ExecutionContext.Implicits.global

def serverWithPing = {
/// code_ref: server_with_ping
implicit val jsonFormats: Formats = DefaultFormats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.specs2.Specification
import org.specs2.time.NoTimeConversions
import net.liftweb.json.DefaultFormats
import org.specs2.execute.Result
import org.specs2.execute.AsResult
import java.net.{ServerSocket, URI}
import akka.testkit._
import akka.actor.ActorSystem
Expand Down Expand Up @@ -120,6 +121,7 @@ class HookupClientSpec extends Specification with NoTimeConversions { def is =
val server = HookupClientSpecification.newServer(serverAddress, defaultProtocol)

def around[T <% Result](t: => T) = {
// def around[T: AsResult](t: =>T) = {
server.start
val r = t
server.stop
Expand Down
13 changes: 8 additions & 5 deletions src/test/scala/io/backchat/hookup/tests/HookupServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ class HookupServerSpec extends Specification with NoTimeConversions { def is = s
val allProtos = DefaultProtocols ++ protocols

class WsClient extends HookupServerClient {
val success: scala.util.Try[HookupServerClient] = scala.util.Success(this)
def receive = {
case Connected => client.complete(Right(this))
// case Connected => client.complete(Right(this))
// case Connected => client.complete(scala.util.Success[HookupServerClient](this))
case Connected => client.complete(success)
case TextMessage(text) => {
messages :+= text
}
Expand Down Expand Up @@ -139,7 +142,7 @@ class HookupServerSpec extends Specification with NoTimeConversions { def is = s
case TextMessage(text) => rcvd = text
}) { _ =>
l.await(3, TimeUnit.SECONDS) must beTrue and {
client.onSuccess({ case c => c ! toSend })
client.future.onSuccess({ case c => c ! toSend })
rcvd must be_==(toSend.content).eventually
}
}
Expand Down Expand Up @@ -186,7 +189,7 @@ class HookupServerSpec extends Specification with NoTimeConversions { def is = s
case JsonMessage(text) => rcvd = text
}) { c =>
l.await(3, TimeUnit.SECONDS) must beTrue and {
client.onSuccess({ case c => c ! toSend })
client.future.onSuccess({ case c => c ! toSend })
rcvd must be_==(toSend).eventually
}
}
Expand All @@ -201,7 +204,7 @@ class HookupServerSpec extends Specification with NoTimeConversions { def is = s
case Disconnected(_) =>
}) { c =>
latch.await(3, TimeUnit.SECONDS) must beTrue and {
client.onSuccess({case c => c.disconnect() })
client.future.onSuccess({case c => c.disconnect() })
disconnectionLatch.await(2, TimeUnit.SECONDS) must beTrue and (c.isConnected must beFalse.eventually)
}
}
Expand All @@ -228,7 +231,7 @@ class HookupServerSpec extends Specification with NoTimeConversions { def is = s
withClient({
case _ =>
}) { _ =>
client.onSuccess({ case c => c ! toSend.needsAck(within = 5 seconds) })
client.future.onSuccess({ case c => c ! toSend.needsAck(within = 5 seconds) })
ackRequest.await(3, TimeUnit.SECONDS) must beTrue
}
}
Expand Down

0 comments on commit 6c835b9

Please sign in to comment.