Sha256: 2fa9701269e1dfff003e15161fb5449f9e4b35d07b60ad5de019fe4719b4426a

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

package org.embulk.output.fluentd

import java.io.IOException
import java.net.ServerSocket
import java.util.concurrent.ThreadLocalRandom

import akka.actor.{ActorRef, ActorSystem}
import akka.stream.ActorMaterializer
import akka.testkit.TestActorRef
import org.embulk.output.fluentd.sender._

import scala.concurrent.ExecutionContext

case class TestActorManager(s: ActorSystem) extends ActorManager {
  implicit val system = s
  val port: Int       = freePort(8888, 8999)
  val host: String    = "127.0.0.1"

  def freePort(from: Int, to: Int): Int = {
    var port = from
    while (true) {
      if (isLocalPortFree(port)) return port
      else port = ThreadLocalRandom.current.nextInt(from, to)
    }
    port
  }

  private def isLocalPortFree(port: Int) =
    try {
      new ServerSocket(port).close()
      true
    } catch {
      case _: IOException =>
        false
    }

  val testActorRef = TestActorRef(new SuperVisor)

  override val supervisor: ActorRef                     = testActorRef
  override implicit val materializer: ActorMaterializer = ActorMaterializer()
  override implicit val dispatcher: ExecutionContext    = ExecutionContext.global
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
embulk-output-fluentd-0.1.0 src/test/scala/org/embulk/output/fluentd/TestActorManager.scala