diff --git a/akka-actor-tests/src/test/scala/akka/TestUtils.scala b/akka-actor-tests/src/test/scala/akka/TestUtils.scala index da3732af9f..6bcdaaa0af 100644 --- a/akka-actor-tests/src/test/scala/akka/TestUtils.scala +++ b/akka-actor-tests/src/test/scala/akka/TestUtils.scala @@ -11,6 +11,8 @@ import java.nio.channels.{ DatagramChannel, ServerSocketChannel } import akka.actor.{ ActorSystem, ActorRef } import akka.testkit.TestProbe +import language.reflectiveCalls + object TestUtils { // Structural type needed since DatagramSocket and ServerSocket has no common ancestor apart from Object diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorFireForgetRequestReplySpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorFireForgetRequestReplySpec.scala deleted file mode 100644 index c51372400d..0000000000 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorFireForgetRequestReplySpec.scala +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ - -package akka.actor - -import akka.testkit._ -import org.scalatest.BeforeAndAfterEach -import scala.concurrent.duration._ -import scala.concurrent.Await -import akka.pattern.ask - -object ActorFireForgetRequestReplySpec { - - class ReplyActor extends Actor { - def receive = { - case "Send" ⇒ - sender() ! "Reply" - case "SendImplicit" ⇒ - sender() ! "ReplyImplicit" - } - } - - class CrashingActor extends Actor { - import context.system - def receive = { - case "Die" ⇒ - state.finished.await - throw new Exception("Expected exception") - } - } - - class SenderActor(replyActor: ActorRef) extends Actor { - import context.system - def receive = { - case "Init" ⇒ - replyActor ! "Send" - case "Reply" ⇒ { - state.s = "Reply" - state.finished.await - } - case "InitImplicit" ⇒ replyActor ! "SendImplicit" - case "ReplyImplicit" ⇒ { - state.s = "ReplyImplicit" - state.finished.await - } - } - } - - object state { - var s = "NIL" - val finished = TestBarrier(2) - } -} - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class ActorFireForgetRequestReplySpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout { - import ActorFireForgetRequestReplySpec._ - - override def beforeEach() = { - state.finished.reset - } - - "An Actor" must { - - "reply to bang message using reply" in { - val replyActor = system.actorOf(Props[ReplyActor]) - val senderActor = system.actorOf(Props(new SenderActor(replyActor))) - senderActor ! "Init" - state.finished.await - state.s should be("Reply") - } - - "reply to bang message using implicit sender" in { - val replyActor = system.actorOf(Props[ReplyActor]) - val senderActor = system.actorOf(Props(new SenderActor(replyActor))) - senderActor ! "InitImplicit" - state.finished.await - state.s should be("ReplyImplicit") - } - - "shutdown crashed temporary actor" in { - filterEvents(EventFilter[Exception]("Expected exception")) { - val supervisor = system.actorOf(Props(new Supervisor( - OneForOneStrategy(maxNrOfRetries = 0)(List(classOf[Exception]))))) - val actor = Await.result((supervisor ? Props[CrashingActor]).mapTo[ActorRef], timeout.duration) - actor.isTerminated should be(false) - actor ! "Die" - state.finished.await - Thread.sleep(1.second.dilated.toMillis) - actor.isTerminated should be(true) - system.stop(supervisor) - } - } - } -} diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorMailboxSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorMailboxSpec.scala index 583237ffaf..27c23dd796 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorMailboxSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorMailboxSpec.scala @@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit import akka.util.Helpers.ConfigOps object ActorMailboxSpec { - val mailboxConf = ConfigFactory.parseString(""" + val mailboxConf = ConfigFactory.parseString(s""" unbounded-dispatcher { mailbox-type = "akka.dispatch.UnboundedMailbox" } @@ -46,7 +46,7 @@ object ActorMailboxSpec { requiring-balancing-bounded-dispatcher { type = "akka.dispatch.BalancingDispatcherConfigurator" - mailbox-requirement = "akka.actor.ActorMailboxSpec$MCBoundedMessageQueueSemantics" + mailbox-requirement = "akka.actor.ActorMailboxSpec$$MCBoundedMessageQueueSemantics" } unbounded-mailbox { @@ -68,7 +68,7 @@ object ActorMailboxSpec { mc-bounded-mailbox { mailbox-capacity = 1000 mailbox-push-timeout-time = 10s - mailbox-type = "akka.actor.ActorMailboxSpec$MCBoundedMailbox" + mailbox-type = "akka.actor.ActorMailboxSpec$$MCBoundedMailbox" } akka.actor.deployment { @@ -142,7 +142,7 @@ object ActorMailboxSpec { } akka.actor.mailbox.requirements { - "akka.actor.ActorMailboxSpec$MCBoundedMessageQueueSemantics" = + "akka.actor.ActorMailboxSpec$$MCBoundedMessageQueueSemantics" = mc-bounded-mailbox } """) diff --git a/akka-actor-tests/src/test/scala/akka/actor/UidClashTest.scala b/akka-actor-tests/src/test/scala/akka/actor/UidClashTest.scala index aa12696d6c..42dc1e9f32 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/UidClashTest.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/UidClashTest.scala @@ -16,12 +16,12 @@ object UidClashTest { @volatile var oldActor: ActorRef = _ - class EvilCollidingActorRef(override val provider: ActorRefProvider, - override val path: ActorPath, - val eventStream: EventStream) extends MinimalActorRef { + private[akka] class EvilCollidingActorRef(override val provider: ActorRefProvider, + override val path: ActorPath, + val eventStream: EventStream) extends MinimalActorRef { //Ignore everything - override def isTerminated(): Boolean = true + override def isTerminated: Boolean = true override def sendSystemMessage(message: SystemMessage): Unit = () override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = () } diff --git a/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala b/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala index fad739a570..104b1425a1 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala @@ -51,6 +51,27 @@ object FutureSpec { final case class Req[T](req: T) final case class Res[T](res: T) + + sealed trait IntAction { def apply(that: Int): Int } + final case class IntAdd(n: Int) extends IntAction { def apply(that: Int) = that + n } + final case class IntSub(n: Int) extends IntAction { def apply(that: Int) = that - n } + final case class IntMul(n: Int) extends IntAction { def apply(that: Int) = that * n } + final case class IntDiv(n: Int) extends IntAction { def apply(that: Int) = that / n } + + sealed trait FutureAction { + def /:(that: Try[Int]): Try[Int] + def /:(that: Future[Int]): Future[Int] + } + + final case class MapAction(action: IntAction)(implicit ec: ExecutionContext) extends FutureAction { + def /:(that: Try[Int]): Try[Int] = that map action.apply + def /:(that: Future[Int]): Future[Int] = that map action.apply + } + + final case class FlatMapAction(action: IntAction)(implicit ec: ExecutionContext) extends FutureAction { + def /:(that: Try[Int]): Try[Int] = that map action.apply + def /:(that: Future[Int]): Future[Int] = that flatMap (n ⇒ Future.successful(action(n))) + } } class JavaFutureSpec extends JavaFutureTests with JUnitSuiteLike @@ -628,7 +649,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa "filter result" in { f { (future, result) ⇒ Await.result((future filter (_ ⇒ true)), timeout.duration) should be(result) - evaluating { Await.result((future filter (_ ⇒ false)), timeout.duration) } should produce[java.util.NoSuchElementException] + intercept[java.util.NoSuchElementException] { Await.result((future filter (_ ⇒ false)), timeout.duration) } } } "transform result with map" in { f((future, result) ⇒ Await.result((future map (_.toString.length)), timeout.duration) should be(result.toString.length)) } @@ -648,7 +669,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa "zip properly" in { f { (future, result) ⇒ Await.result(future zip Promise.successful("foo").future, timeout.duration) should be((result, "foo")) - (evaluating { Await.result(future zip Promise.failed(new RuntimeException("ohnoes")).future, timeout.duration) } should produce[RuntimeException]).getMessage should be("ohnoes") + (intercept[RuntimeException] { Await.result(future zip Promise.failed(new RuntimeException("ohnoes")).future, timeout.duration) }).getMessage should be("ohnoes") } } "not recover from exception" in { f((future, result) ⇒ Await.result(future.recover({ case _ ⇒ "pigdog" }), timeout.duration) should be(result)) } @@ -659,7 +680,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa Await.result(p.future, timeout.duration) should be(result) } } - "not project a failure" in { f((future, result) ⇒ (evaluating { Await.result(future.failed, timeout.duration) } should produce[NoSuchElementException]).getMessage should be("Future.failed not completed with a throwable.")) } + "not project a failure" in { f((future, result) ⇒ (intercept[NoSuchElementException] { Await.result(future.failed, timeout.duration) }).getMessage should be("Future.failed not completed with a throwable.")) } "not perform action on exception" is pending "cast using mapTo" in { f((future, result) ⇒ Await.result(future.mapTo[Boolean].recover({ case _: ClassCastException ⇒ false }), timeout.duration) should be(false)) } } @@ -674,20 +695,20 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa f.getMessage should be(message) }) } - "throw exception with 'get'" in { f((future, message) ⇒ (evaluating { Await.result(future, timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) } - "throw exception with 'Await.result'" in { f((future, message) ⇒ (evaluating { Await.result(future, timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) } + "throw exception with 'get'" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future, timeout.duration) }).getMessage should be(message)) } + "throw exception with 'Await.result'" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future, timeout.duration) }).getMessage should be(message)) } "retain exception with filter" in { f { (future, message) ⇒ - (evaluating { Await.result(future filter (_ ⇒ true), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message) - (evaluating { Await.result(future filter (_ ⇒ false), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message) + (intercept[java.lang.Exception] { Await.result(future filter (_ ⇒ true), timeout.duration) }).getMessage should be(message) + (intercept[java.lang.Exception] { Await.result(future filter (_ ⇒ false), timeout.duration) }).getMessage should be(message) } } - "retain exception with map" in { f((future, message) ⇒ (evaluating { Await.result(future map (_.toString.length), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) } - "retain exception with flatMap" in { f((future, message) ⇒ (evaluating { Await.result(future flatMap (_ ⇒ Promise.successful[Any]("foo").future), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) } + "retain exception with map" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future map (_.toString.length), timeout.duration) }).getMessage should be(message)) } + "retain exception with flatMap" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future flatMap (_ ⇒ Promise.successful[Any]("foo").future), timeout.duration) }).getMessage should be(message)) } "not perform action with foreach" is pending "zip properly" in { - f { (future, message) ⇒ (evaluating { Await.result(future zip Promise.successful("foo").future, timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message) } + f { (future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future zip Promise.successful("foo").future, timeout.duration) }).getMessage should be(message) } } "recover from exception" in { f((future, message) ⇒ Await.result(future.recover({ case e if e.getMessage == message ⇒ "pigdog" }), timeout.duration) should be("pigdog")) } "not perform action on result" is pending @@ -702,27 +723,6 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa "always cast successfully using mapTo" in { f((future, message) ⇒ (evaluating { Await.result(future.mapTo[java.lang.Thread], timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) } } - sealed trait IntAction { def apply(that: Int): Int } - final case class IntAdd(n: Int) extends IntAction { def apply(that: Int) = that + n } - final case class IntSub(n: Int) extends IntAction { def apply(that: Int) = that - n } - final case class IntMul(n: Int) extends IntAction { def apply(that: Int) = that * n } - final case class IntDiv(n: Int) extends IntAction { def apply(that: Int) = that / n } - - sealed trait FutureAction { - def /:(that: Try[Int]): Try[Int] - def /:(that: Future[Int]): Future[Int] - } - - final case class MapAction(action: IntAction) extends FutureAction { - def /:(that: Try[Int]): Try[Int] = that map action.apply - def /:(that: Future[Int]): Future[Int] = that map action.apply - } - - final case class FlatMapAction(action: IntAction) extends FutureAction { - def /:(that: Try[Int]): Try[Int] = that map action.apply - def /:(that: Future[Int]): Future[Int] = that flatMap (n ⇒ Future.successful(action(n))) - } - implicit def arbFuture: Arbitrary[Future[Int]] = Arbitrary(for (n ← arbitrary[Int]) yield Future(n)) implicit def arbFutureAction: Arbitrary[FutureAction] = Arbitrary { diff --git a/akka-actor-tests/src/test/scala/akka/event/EventStreamSpec.scala b/akka-actor-tests/src/test/scala/akka/event/EventStreamSpec.scala index b884fa7c04..a3ae2bc68d 100644 --- a/akka-actor-tests/src/test/scala/akka/event/EventStreamSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/event/EventStreamSpec.scala @@ -56,9 +56,9 @@ object EventStreamSpec { // class hierarchy for subchannel test class A - class B1 extends A class B2 extends A - class C extends B1 + class B3 extends A + class C extends B2 trait T trait AT extends T @@ -137,12 +137,12 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) { "manage sub-channels using classes" in { val a = new A - val b1 = new B1 - val b2 = new B2 + val b1 = new B2 + val b2 = new B3 val c = new C val bus = new EventStream(system, false) within(2 seconds) { - bus.subscribe(testActor, classOf[B2]) should be(true) + bus.subscribe(testActor, classOf[B3]) should be(true) bus.publish(c) bus.publish(b2) expectMsg(b2) @@ -151,7 +151,7 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) { expectMsg(c) bus.publish(b1) expectMsg(b1) - bus.unsubscribe(testActor, classOf[B1]) should be(true) + bus.unsubscribe(testActor, classOf[B2]) should be(true) bus.publish(c) bus.publish(b2) bus.publish(a) diff --git a/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala b/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala index fed90d381a..229c3da911 100644 --- a/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/event/LoggerSpec.scala @@ -97,9 +97,10 @@ object LoggerSpec { override def mdc(currentMessage: Any): MDC = { reqId += 1 val always = Map("requestId" -> reqId) + val cmim = "Current Message in MDC" val perMessage = currentMessage match { - case cm @ "Current Message in MDC" ⇒ Map("currentMsg" -> cm, "currentMsgLength" -> cm.length) - case _ ⇒ Map() + case `cmim` ⇒ Map[String, Any]("currentMsg" -> cmim, "currentMsgLength" -> cmim.length) + case _ ⇒ Map() } always ++ perMessage } diff --git a/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala b/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala index 8454c152a4..d14fdf9c4a 100644 --- a/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/serialization/SerializeSpec.scala @@ -20,7 +20,7 @@ import org.apache.commons.codec.binary.Hex.encodeHex object SerializationTests { - val serializeConf = """ + val serializeConf = s""" akka { actor { serialize-messages = off @@ -29,13 +29,13 @@ object SerializationTests { } serialization-bindings { - "akka.serialization.SerializationTests$Person" = java - "akka.serialization.SerializationTests$Address" = java + "akka.serialization.SerializationTests$$Person" = java + "akka.serialization.SerializationTests$$Address" = java "akka.serialization.TestSerializable" = test - "akka.serialization.SerializationTests$PlainMessage" = test - "akka.serialization.SerializationTests$A" = java - "akka.serialization.SerializationTests$B" = test - "akka.serialization.SerializationTests$D" = test + "akka.serialization.SerializationTests$$PlainMessage" = test + "akka.serialization.SerializationTests$$A" = java + "akka.serialization.SerializationTests$$B" = test + "akka.serialization.SerializationTests$$D" = test } } } diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index f0850e4893..81c16e596b 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -294,6 +294,8 @@ object AkkaBuild extends Build { // compile options scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"), scalacOptions in Compile ++= (if (deprecation) Seq("-deprecation") else Nil), + scalacOptions in Test := (scalacOptions in Test).value.filterNot(_ == "-Xlog-reflective-calls"), + // -XDignore.symbol.file suppresses sun.misc.Unsafe warnings javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-XDignore.symbol.file"), javacOptions in compile ++= (if (deprecation) Seq("-Xlint:deprecation") else Nil), javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.6"),