|
Akka/Scala example source code file (LogSourceSpec.scala)
The LogSourceSpec.scala Akka example source code/** * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> */ package akka.remote import scala.concurrent.duration._ import akka.testkit.AkkaSpec import akka.actor.Actor import akka.actor.ActorLogging import akka.actor.Props import akka.event.Logging import akka.testkit.ImplicitSender import akka.testkit.TestProbe import akka.actor.Deploy import akka.event.Logging.Info import akka.actor.ExtendedActorSystem object LogSourceSpec { class Reporter extends Actor with ActorLogging { def receive = { case s: String ⇒ log.info(s) } } } @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class LogSourceSpec extends AkkaSpec( """ akka.loglevel = INFO akka.actor.provider = "akka.remote.RemoteActorRefProvider" akka.remote.netty.tcp.port = 0 """) { import LogSourceSpec._ val reporter = system.actorOf(Props[Reporter], "reporter") val logProbe = TestProbe() system.eventStream.subscribe(system.actorOf(Props(new Actor { def receive = { case i @ Info(_, _, msg: String) if msg contains "hello" ⇒ logProbe.ref ! i case _ ⇒ } }).withDeploy(Deploy.local), "logSniffer"), classOf[Logging.Info]) "Log events" must { "should include host and port for local LogSource" in { reporter ! "hello" val info = logProbe.expectMsgType[Info] info.message should be("hello") val defaultAddress = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress info.logSource should include(defaultAddress.toString) } } } Other Akka source code examplesHere is a short list of links related to this Akka LogSourceSpec.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.