Skip to content

Commit f337a24

Browse files
committed
Fix server ports
1 parent c1c137e commit f337a24

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/test/scala/nl/gideondk/sentinel/RequestResponse.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class RequestResponseSpec extends WordSpec with ShouldMatchers {
3939

4040
//def worker(implicit system: ActorSystem) = system.actorOf(Props(new SentinelClientWorker(new InetSocketAddress("localhost", 9999), PingPong.stages, "Worker")(1, 1, 10)).withDispatcher("nl.gideondk.sentinel.sentinel-dispatcher"))
4141

42-
def client(implicit system: ActorSystem) = Client("localhost", 9999, RandomRouter(16), "Worker", 5 seconds, SimpleMessage.stages)(system)
42+
def client(portNumber: Int)(implicit system: ActorSystem) = Client("localhost", portNumber, RandomRouter(16), "Worker", 5 seconds, SimpleMessage.stages)(system)
4343

44-
def server(implicit system: ActorSystem) = SentinelServer(9999, SimpleServerHandler)(SimpleMessage.stages)(system)
44+
def server(portNumber: Int)(implicit system: ActorSystem) = SentinelServer(portNumber, SimpleServerHandler)(SimpleMessage.stages)(system)
4545

4646
"A client" should {
4747
// "return a exception when a request is done when no connection is available" in new TestKitSpec {
@@ -52,17 +52,19 @@ class RequestResponseSpec extends WordSpec with ShouldMatchers {
5252
// evaluating { result.get } should produce[SentinelClientWorker.NoConnectionAvailable]
5353
// }
5454

55-
// "be able to request a response from a server" in new TestKitSpec {
56-
// val s = server
57-
// val c = client
55+
"be able to request a response from a server" in new TestKitSpec {
56+
val portNumber = TestHelpers.portNumber.getAndIncrement()
57+
val s = server(portNumber)
58+
val c = client(portNumber)
5859

59-
// val action = c <~< SimpleCommand(PING_PONG_COMMAND, "")
60-
// action.run.isSuccess
61-
// }
60+
val action = c <~< SimpleCommand(PING_PONG_COMMAND, "")
61+
action.run.isSuccess
62+
}
6263

6364
"be able to stream requests to a server" in new TestKitSpec {
64-
val s = server
65-
val c = client
65+
val portNumber = TestHelpers.portNumber.getAndIncrement()
66+
val s = server(portNumber)
67+
val c = client(portNumber)
6668

6769
val chunks = List.fill(5)(SimpleStreamChunk("ABCDE"))
6870
val action = c <<?~~< (SimpleCommand(TOTAL_CHUNK_SIZE, ""), Process.emitRange(0, 500) |> process1.lift(x SimpleStreamChunk("ABCDE")) onComplete (Process.emit(SimpleStreamChunk(""))))

src/test/scala/nl/gideondk/sentinel/TestHelpers.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import akka.testkit._
2525
import scala.concurrent.duration._
2626
import scala.concurrent._
2727

28+
import java.util.concurrent.atomic.AtomicInteger
29+
2830
import protocols._
2931

3032
import java.net.InetSocketAddress
@@ -34,7 +36,13 @@ abstract class TestKitSpec extends TestKit(ActorSystem())
3436
with ShouldMatchers
3537
with BeforeAndAfterAll
3638
with ImplicitSender {
37-
override def afterAll = system.shutdown()
39+
override def afterAll = {
40+
system.shutdown()
41+
}
42+
}
43+
44+
object TestHelpers {
45+
val portNumber = new AtomicInteger(10500)
3846
}
3947

4048
object BenchmarkHelpers {

src/test/scala/nl/gideondk/sentinel/protocols/SimpleMessage.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ object SimpleServerHandler extends SentinelResolver[SimpleMessageFormat, SimpleM
7373
import SimpleMessage._
7474
def process = {
7575
case SimpleCommand(PING_PONG_COMMAND, payload) answer { x Future(SimpleReply("PONG")) }
76+
7677
case SimpleCommand(TOTAL_CHUNK_SIZE, payload) consumeStream { x
7778
s
7879
s pipe process1.fold(0) { (b, a) b + a.payload.length } runLastOr (throw new Exception("")) map (x SimpleReply(x.toString))
7980
}
81+
8082
case SimpleStreamChunk(x) if (x.length > 0) consume else endStream
8183

8284
case _ throw new Exception("Unknown command")

0 commit comments

Comments
 (0)