Skip to content

Commit

Permalink
fix test cases issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
evolv34 committed Dec 16, 2018
1 parent 65ed747 commit 7d187fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import scala.concurrent.duration.Duration

class GraphiteReporterSpec extends UnitSpec {
val mockServerPort = 12003
val mockServer = MockServer(mockServerPort)

"GraphiteReporter.write" should "take the time from message and write the sink record to timeseries database" in {
val serverFuture = mockServer.init()
val serverFuture = MockServer(mockServerPort).init()
val graphiteReporter = GraphiteReporter("localhost", mockServerPort.toString)
val (metric, sinkRecord) = getSinkRecord(Some((System.currentTimeMillis / 1000).toString))

Expand All @@ -24,7 +23,7 @@ class GraphiteReporterSpec extends UnitSpec {
}

it should "take the current time and write the sink record to timeseries database" in {
val serverFuture = mockServer.init()
val serverFuture = MockServer(mockServerPort).init()
val graphiteReporter = GraphiteReporter("localhost", mockServerPort.toString)
val (metric, sinkRecord) = getSinkRecord(None)

Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/com/evolv/metrics/utils/MockServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.concurrent.Future


class MockServer(port: Int) {

def init():Future[String] = Future {
val server = new ServerSocket(port)
val s = server.accept()
Expand All @@ -17,10 +18,10 @@ class MockServer(port: Int) {

val data = serverInputStream.readLine()
serverInputStream.close()
s.close()
server.close()
data
}
TimeUnit.SECONDS.sleep(5)
}

object MockServer {
Expand Down

0 comments on commit 7d187fe

Please sign in to comment.