diff --git a/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala index bab56cf9df..96c24f3068 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/dispatch/DispatchersSpec.scala @@ -6,7 +6,7 @@ package akka.actor.dispatch import language.postfixOps import java.util.concurrent.{ CountDownLatch, TimeUnit } -import scala.reflect.{ Manifest } +import scala.reflect.ClassTag import akka.dispatch._ import akka.testkit.AkkaSpec import akka.testkit.ImplicitSender @@ -50,7 +50,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend val id = "id" def instance(dispatcher: MessageDispatcher): (MessageDispatcher) ⇒ Boolean = _ == dispatcher - def ofType[T <: MessageDispatcher: Manifest]: (MessageDispatcher) ⇒ Boolean = _.getClass == manifest[T].erasure + def ofType[T <: MessageDispatcher: ClassTag]: (MessageDispatcher) ⇒ Boolean = _.getClass == implicitly[ClassTag[T]].runtimeClass def typesAndValidators: Map[String, (MessageDispatcher) ⇒ Boolean] = Map( "BalancingDispatcher" -> ofType[BalancingDispatcher], 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 d5e6f6f955..af896a28e4 100644 --- a/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/dispatch/FutureSpec.scala @@ -20,6 +20,7 @@ import scala.runtime.NonLocalReturnControl import akka.pattern.ask import java.lang.{ IllegalStateException, ArithmeticException } import java.util.concurrent._ +import scala.reflect.ClassTag object FutureSpec { @@ -123,7 +124,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa "A Future" when { - "awaiting a result" that { + "awaiting a result" which { "is not completed" must { behave like emptyFuture { test ⇒ val latch = new TestLatch @@ -169,7 +170,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa } } - "from an Actor" that { + "from an Actor" which { "returns a result" must { behave like futureWithResult { test ⇒ val actor = system.actorOf(Props[TestActor]) @@ -192,7 +193,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa } } - "using flatMap with an Actor" that { + "using flatMap with an Actor" which { "will return a result" must { behave like futureWithResult { test ⇒ val actor1 = system.actorOf(Props[TestActor]) @@ -966,7 +967,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa "cast using mapTo" in { f((future, result) ⇒ Await.result(future.mapTo[Boolean].recover({ case _: ClassCastException ⇒ false }), timeout.duration) must be(false)) } } - def futureWithException[E <: Throwable: Manifest](f: ((Future[Any], String) ⇒ Unit) ⇒ Unit) { + def futureWithException[E <: Throwable: ClassTag](f: ((Future[Any], String) ⇒ Unit) ⇒ Unit) { "be completed" in { f((future, _) ⇒ future must be('completed)) } "contain a value" in { f((future, message) ⇒ { @@ -1047,5 +1048,5 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa } - def checkType[A: Manifest, B](in: Future[A], refmanifest: Manifest[B]): Boolean = manifest[A] == refmanifest + def checkType[A: ClassTag, B](in: Future[A], reftag: ClassTag[B]): Boolean = implicitly[ClassTag[A]].runtimeClass == reftag.runtimeClass } diff --git a/akka-actor/src/main/scala/akka/actor/DynamicAccess.scala b/akka-actor/src/main/scala/akka/actor/DynamicAccess.scala index 08de413717..bc5bef5d61 100644 --- a/akka-actor/src/main/scala/akka/actor/DynamicAccess.scala +++ b/akka-actor/src/main/scala/akka/actor/DynamicAccess.scala @@ -32,7 +32,7 @@ abstract class DynamicAccess { val constructor = clazz.getDeclaredConstructor(types: _*) constructor.setAccessible(true) val obj = constructor.newInstance(values: _*).asInstanceOf[T] - val t = classManifest[T].erasure + val t = implicitly[ClassTag[T]].runtimeClass if (t.isInstance(obj)) Right(obj) else Left(new ClassCastException(clazz + " is not a subtype of " + t)) } } @@ -93,7 +93,7 @@ class ReflectiveDynamicAccess(val classLoader: ClassLoader) extends DynamicAcces override def getClassFor[T: ClassTag](fqcn: String): Either[Throwable, Class[_ <: T]] = try { val c = classLoader.loadClass(fqcn).asInstanceOf[Class[_ <: T]] - val t = classManifest[T].erasure + val t = implicitly[ClassTag[T]].runtimeClass if (t.isAssignableFrom(c)) Right(c) else Left(new ClassCastException(t + " is not assignable from " + c)) } catch { case NonFatal(e) ⇒ Left(e) @@ -107,7 +107,7 @@ class ReflectiveDynamicAccess(val classLoader: ClassLoader) extends DynamicAcces val constructor = c.getDeclaredConstructor(types: _*) constructor.setAccessible(true) val obj = constructor.newInstance(values: _*) - val t = classManifest[T].erasure + val t = implicitly[ClassTag[T]].runtimeClass if (t.isInstance(obj)) Right(obj) else Left(new ClassCastException(fqcn + " is not a subtype of " + t)) } }) @@ -117,7 +117,7 @@ class ReflectiveDynamicAccess(val classLoader: ClassLoader) extends DynamicAcces withErrorHandling { val module = c.getDeclaredField("MODULE$") module.setAccessible(true) - val t = classManifest[T].erasure + val t = implicitly[ClassTag[T]].runtimeClass module.get(null) match { case null ⇒ Left(new NullPointerException) case x if !t.isInstance(x) ⇒ Left(new ClassCastException(fqcn + " is not a subtype of " + t)) diff --git a/akka-camel/src/main/scala/akka/camel/CamelMessage.scala b/akka-camel/src/main/scala/akka/camel/CamelMessage.scala index fc29e08382..6c45a66bf4 100644 --- a/akka-camel/src/main/scala/akka/camel/CamelMessage.scala +++ b/akka-camel/src/main/scala/akka/camel/CamelMessage.scala @@ -11,6 +11,7 @@ import scala.collection.JavaConversions._ import akka.japi.{ Function ⇒ JFunction } import org.apache.camel.{ CamelContext, Message ⇒ JCamelMessage } import akka.AkkaException +import scala.reflect.ClassTag /** * An immutable representation of a Camel message. @@ -132,7 +133,7 @@ case class CamelMessage(body: Any, headers: Map[String, Any]) { * The CamelContext is accessible in a [[akka.camel.javaapi.UntypedConsumerActor]] and [[akka.camel.javaapi.UntypedProducerActor]] * using the `getCamelContext` method, and is available on the [[akka.camel.CamelExtension]]. */ - def bodyAs[T](implicit m: Manifest[T], camelContext: CamelContext): T = getBodyAs(m.erasure.asInstanceOf[Class[T]], camelContext) + def bodyAs[T](implicit t: ClassTag[T], camelContext: CamelContext): T = getBodyAs(t.runtimeClass.asInstanceOf[Class[T]], camelContext) /** * Returns the body of the message converted to the type as given by the clazz @@ -152,7 +153,7 @@ case class CamelMessage(body: Any, headers: Map[String, Any]) { * The CamelContext is accessible in a [[akka.camel.javaapi.UntypedConsumerActor]] and [[akka.camel.javaapi.UntypedProducerActor]] * using the `getCamelContext` method, and is available on the [[akka.camel.CamelExtension]]. */ - def withBodyAs[T](implicit m: Manifest[T], camelContext: CamelContext): CamelMessage = withBodyAs(m.erasure.asInstanceOf[Class[T]]) + def withBodyAs[T](implicit t: ClassTag[T], camelContext: CamelContext): CamelMessage = withBodyAs(t.runtimeClass.asInstanceOf[Class[T]]) /** * Creates a CamelMessage with current body converted to type clazz. @@ -172,7 +173,7 @@ case class CamelMessage(body: Any, headers: Map[String, Any]) { * using the `getCamelContext` method, and is available on the [[akka.camel.CamelExtension]]. * */ - def headerAs[T](name: String)(implicit m: Manifest[T], camelContext: CamelContext): Option[T] = header(name).map(camelContext.getTypeConverter.mandatoryConvertTo[T](m.erasure.asInstanceOf[Class[T]], _)) + def headerAs[T](name: String)(implicit t: ClassTag[T], camelContext: CamelContext): Option[T] = header(name).map(camelContext.getTypeConverter.mandatoryConvertTo[T](t.runtimeClass.asInstanceOf[Class[T]], _)) /** * Returns the header with given name converted to type as given by the clazz @@ -183,7 +184,7 @@ case class CamelMessage(body: Any, headers: Map[String, Any]) { *

* Java API */ - def getHeaderAs[T](name: String, clazz: Class[T], camelContext: CamelContext): T = headerAs[T](name)(Manifest.classType(clazz), camelContext).get + def getHeaderAs[T](name: String, clazz: Class[T], camelContext: CamelContext): T = headerAs[T](name)(ClassTag(clazz), camelContext).get } diff --git a/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala b/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala index ca7d57a0aa..29863b146a 100644 --- a/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala +++ b/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala @@ -9,10 +9,10 @@ import language.implicitConversions import internal.CamelExchangeAdapter import org.apache.camel.impl.DefaultExchange import org.apache.camel.{ Exchange, ExchangePattern } -import akka.camel.TestSupport.{ SharedCamelSystem, MessageSugar } +import akka.camel.TestSupport.{ SharedCamelSystem } import org.scalatest.FunSuite -class CamelExchangeAdapterTest extends FunSuite with SharedCamelSystem with MessageSugar { +class CamelExchangeAdapterTest extends FunSuite with SharedCamelSystem { //TODO: Get rid of implicit. // It is here, as was easier to add this implicit than to rewrite the whole test... @@ -20,22 +20,22 @@ class CamelExchangeAdapterTest extends FunSuite with SharedCamelSystem with Mess test("mustSetInMessageFromRequestMessage") { val e1 = sampleInOnly - e1.setRequest(Message("x")) + e1.setRequest(CamelMessage("x", Map.empty)) assert(e1.getIn.getBody === "x") val e2 = sampleInOut - e2.setRequest(Message("y")) + e2.setRequest(CamelMessage("y", Map.empty)) assert(e2.getIn.getBody === "y") } test("mustSetOutMessageFromResponseMessage") { val e1 = sampleInOut - e1.setResponse(Message("y")) + e1.setResponse(CamelMessage("y", Map.empty)) assert(e1.getOut.getBody === "y") } test("mustSetInMessageFromResponseMessage") { val e1 = sampleInOnly - e1.setResponse(Message("x")) + e1.setResponse(CamelMessage("x", Map.empty)) assert(e1.getIn.getBody === "x") } @@ -50,17 +50,17 @@ class CamelExchangeAdapterTest extends FunSuite with SharedCamelSystem with Mess test("mustCreateRequestMessageFromInMessage") { val m = sampleInOnly.toRequestMessage - assert(m === Message("test-in", Map("key-in" -> "val-in"))) + assert(m === CamelMessage("test-in", Map("key-in" -> "val-in"))) } test("mustCreateResponseMessageFromInMessage") { val m = sampleInOnly.toResponseMessage - assert(m === Message("test-in", Map("key-in" -> "val-in"))) + assert(m === CamelMessage("test-in", Map("key-in" -> "val-in"))) } test("mustCreateResponseMessageFromOutMessage") { val m = sampleInOut.toResponseMessage - assert(m === Message("test-out", Map("key-out" -> "val-out"))) + assert(m === CamelMessage("test-out", Map("key-out" -> "val-out"))) } test("mustCreateFailureMessageFromExceptionAndInMessage") { @@ -83,17 +83,17 @@ class CamelExchangeAdapterTest extends FunSuite with SharedCamelSystem with Mess test("mustCreateRequestMessageFromInMessageWithAdditionalHeader") { val m = sampleInOnly.toRequestMessage(Map("x" -> "y")) - assert(m === Message("test-in", Map("key-in" -> "val-in", "x" -> "y"))) + assert(m === CamelMessage("test-in", Map("key-in" -> "val-in", "x" -> "y"))) } test("mustCreateResponseMessageFromInMessageWithAdditionalHeader") { val m = sampleInOnly.toResponseMessage(Map("x" -> "y")) - assert(m === Message("test-in", Map("key-in" -> "val-in", "x" -> "y"))) + assert(m === CamelMessage("test-in", Map("key-in" -> "val-in", "x" -> "y"))) } test("mustCreateResponseMessageFromOutMessageWithAdditionalHeader") { val m = sampleInOut.toResponseMessage(Map("x" -> "y")) - assert(m === Message("test-out", Map("key-out" -> "val-out", "x" -> "y"))) + assert(m === CamelMessage("test-out", Map("key-out" -> "val-out", "x" -> "y"))) } test("mustCreateFailureMessageFromExceptionAndInMessageWithAdditionalHeader") { diff --git a/akka-camel/src/test/scala/akka/camel/MessageScalaTest.scala b/akka-camel/src/test/scala/akka/camel/MessageScalaTest.scala index 81fa0678ed..6285f13561 100644 --- a/akka-camel/src/test/scala/akka/camel/MessageScalaTest.scala +++ b/akka-camel/src/test/scala/akka/camel/MessageScalaTest.scala @@ -7,72 +7,72 @@ package akka.camel import java.io.InputStream import org.apache.camel.NoTypeConversionAvailableException -import akka.camel.TestSupport.{ SharedCamelSystem, MessageSugar } +import akka.camel.TestSupport.{ SharedCamelSystem } import org.scalatest.FunSuite import org.scalatest.matchers.MustMatchers -class MessageScalaTest extends FunSuite with MustMatchers with SharedCamelSystem with MessageSugar { +class MessageScalaTest extends FunSuite with MustMatchers with SharedCamelSystem { implicit def camelContext = camel.context test("mustConvertDoubleBodyToString") { - Message(1.4).bodyAs[String] must be("1.4") + CamelMessage(1.4, Map.empty).bodyAs[String] must be("1.4") } test("mustThrowExceptionWhenConvertingDoubleBodyToInputStream") { intercept[NoTypeConversionAvailableException] { - Message(1.4).bodyAs[InputStream] + CamelMessage(1.4, Map.empty).bodyAs[InputStream] } } test("mustReturnDoubleHeader") { - val message = Message("test", Map("test" -> 1.4)) + val message = CamelMessage("test", Map("test" -> 1.4)) message.header("test").get must be(1.4) } test("mustConvertDoubleHeaderToString") { - val message = Message("test", Map("test" -> 1.4)) + val message = CamelMessage("test", Map("test" -> 1.4)) message.headerAs[String]("test").get must be("1.4") } test("mustReturnSubsetOfHeaders") { - val message = Message("test", Map("A" -> "1", "B" -> "2")) + val message = CamelMessage("test", Map("A" -> "1", "B" -> "2")) message.headers(Set("B")) must be(Map("B" -> "2")) } test("mustTransformBodyAndPreserveHeaders") { - Message("a", Map("A" -> "1")).mapBody((body: String) ⇒ body + "b") must be(Message("ab", Map("A" -> "1"))) + CamelMessage("a", Map("A" -> "1")).mapBody((body: String) ⇒ body + "b") must be(CamelMessage("ab", Map("A" -> "1"))) } test("mustConvertBodyAndPreserveHeaders") { - Message(1.4, Map("A" -> "1")).withBodyAs[String] must be(Message("1.4", Map("A" -> "1"))) + CamelMessage(1.4, Map("A" -> "1")).withBodyAs[String] must be(CamelMessage("1.4", Map("A" -> "1"))) } test("mustSetBodyAndPreserveHeaders") { - Message("test1", Map("A" -> "1")).withBody("test2") must be( - Message("test2", Map("A" -> "1"))) + CamelMessage("test1", Map("A" -> "1")).withBody("test2") must be( + CamelMessage("test2", Map("A" -> "1"))) } test("mustSetHeadersAndPreserveBody") { - Message("test1", Map("A" -> "1")).withHeaders(Map("C" -> "3")) must be( - Message("test1", Map("C" -> "3"))) + CamelMessage("test1", Map("A" -> "1")).withHeaders(Map("C" -> "3")) must be( + CamelMessage("test1", Map("C" -> "3"))) } test("mustAddHeaderAndPreserveBodyAndHeaders") { - Message("test1", Map("A" -> "1")).addHeader("B" -> "2") must be( - Message("test1", Map("A" -> "1", "B" -> "2"))) + CamelMessage("test1", Map("A" -> "1")).addHeader("B" -> "2") must be( + CamelMessage("test1", Map("A" -> "1", "B" -> "2"))) } test("mustAddHeadersAndPreserveBodyAndHeaders") { - Message("test1", Map("A" -> "1")).addHeaders(Map("B" -> "2")) must be( - Message("test1", Map("A" -> "1", "B" -> "2"))) + CamelMessage("test1", Map("A" -> "1")).addHeaders(Map("B" -> "2")) must be( + CamelMessage("test1", Map("A" -> "1", "B" -> "2"))) } test("mustRemoveHeadersAndPreserveBodyAndRemainingHeaders") { - Message("test1", Map("A" -> "1", "B" -> "2")).withoutHeader("B") must be( - Message("test1", Map("A" -> "1"))) + CamelMessage("test1", Map("A" -> "1", "B" -> "2")).withoutHeader("B") must be( + CamelMessage("test1", Map("A" -> "1"))) } } diff --git a/akka-camel/src/test/scala/akka/camel/TestSupport.scala b/akka-camel/src/test/scala/akka/camel/TestSupport.scala index 045f75e0ef..d5b3418cb0 100644 --- a/akka-camel/src/test/scala/akka/camel/TestSupport.scala +++ b/akka-camel/src/test/scala/akka/camel/TestSupport.scala @@ -13,6 +13,7 @@ import java.util.concurrent.{ TimeoutException, ExecutionException, TimeUnit } import org.scalatest.{ BeforeAndAfterEach, BeforeAndAfterAll, Suite } import org.scalatest.matchers.{ BePropertyMatcher, BePropertyMatchResult } import scala.concurrent.util.{ FiniteDuration, Duration } +import scala.reflect.ClassTag private[camel] object TestSupport { @@ -43,12 +44,6 @@ private[camel] object TestSupport { def routes = camel.context.getRoutes } - @deprecated - trait MessageSugar { - def Message(body: Any) = akka.camel.CamelMessage(body, Map.empty) - def Message(body: Any, headers: Map[String, Any]) = akka.camel.CamelMessage(body, headers) - } - trait SharedCamelSystem extends BeforeAndAfterAll { this: Suite ⇒ implicit lazy val system = ActorSystem("test") implicit lazy val camel = CamelExtension(system) @@ -82,8 +77,8 @@ private[camel] object TestSupport { duration millis } - def anInstanceOf[T](implicit manifest: Manifest[T]) = { - val clazz = manifest.erasure.asInstanceOf[Class[T]] + def anInstanceOf[T](implicit tag: ClassTag[T]) = { + val clazz = tag.runtimeClass.asInstanceOf[Class[T]] new BePropertyMatcher[AnyRef] { def apply(left: AnyRef) = BePropertyMatchResult( clazz.isAssignableFrom(left.getClass), diff --git a/akka-camel/src/test/scala/akka/camel/UntypedProducerTest.scala b/akka-camel/src/test/scala/akka/camel/UntypedProducerTest.scala index f7c68fa791..21e9800b87 100644 --- a/akka-camel/src/test/scala/akka/camel/UntypedProducerTest.scala +++ b/akka-camel/src/test/scala/akka/camel/UntypedProducerTest.scala @@ -32,13 +32,11 @@ class UntypedProducerTest extends WordSpec with MustMatchers with BeforeAndAfter "An UntypedProducer producing a message to a sync Camel route" must { "produce a message and receive a normal response" in { - given("a registered two-way producer") val producer = system.actorOf(Props[SampleUntypedReplyingProducer]) - when("a test message is sent to the producer with ask") val message = CamelMessage("test", Map(CamelMessage.MessageExchangeId -> "123")) val future = producer.ask(message)(timeout) - then("a normal response should have been returned by the producer") + val expected = CamelMessage("received test", Map(CamelMessage.MessageExchangeId -> "123")) Await.result(future, timeout) match { case result: CamelMessage ⇒ result must be(expected) @@ -48,13 +46,11 @@ class UntypedProducerTest extends WordSpec with MustMatchers with BeforeAndAfter } "produce a message and receive a failure response" in { - given("a registered two-way producer") val producer = system.actorOf(Props[SampleUntypedReplyingProducer]) - when("a test message causing an exception is sent to the producer with ask") val message = CamelMessage("fail", Map(CamelMessage.MessageExchangeId -> "123")) val future = producer.ask(message)(timeout).failed - then("a failure response should have been returned by the producer") + Await.ready(future, timeout).value match { case Some(Right(e: AkkaCamelException)) ⇒ e.getMessage must be("failure") @@ -67,14 +63,11 @@ class UntypedProducerTest extends WordSpec with MustMatchers with BeforeAndAfter "An UntypedProducer producing a message to a sync Camel route and then forwarding the response" must { "produce a message and send a normal response to direct:forward-test-1" in { - given("a registered one-way producer configured with a forward target") val producer = system.actorOf(Props[SampleUntypedForwardingProducer]) - when("a test message is sent to the producer with !") mockEndpoint.expectedBodiesReceived("received test") producer.tell(CamelMessage("test", Map[String, Any]()), producer) - then("a normal response should have been sent") mockEndpoint.assertIsSatisfied } diff --git a/akka-camel/src/test/scala/akka/camel/internal/ActivationTrackerTest.scala b/akka-camel/src/test/scala/akka/camel/internal/ActivationTrackerTest.scala index 1b763706ed..8b251c4f9a 100644 --- a/akka-camel/src/test/scala/akka/camel/internal/ActivationTrackerTest.scala +++ b/akka-camel/src/test/scala/akka/camel/internal/ActivationTrackerTest.scala @@ -55,46 +55,34 @@ class ActivationTrackerTest extends TestKit(ActorSystem("test")) with WordSpec w } "ActivationTracker forwards de-activation message to all awaiting parties" taggedAs TimingTest in { - given("Actor is activated") publish(EndpointActivated(actor.ref)) - given("Actor is deactivated") publish(EndpointDeActivated(actor.ref)) - when("Multiple parties await deactivation") awaiting.awaitDeActivation() anotherAwaiting.awaitDeActivation() - then("all awaiting parties are notified") awaiting.verifyDeActivated() anotherAwaiting.verifyDeActivated() } "ActivationTracker forwards de-activation message even if deactivation happened earlier" taggedAs TimingTest in { - given("Actor is activated") publish(EndpointActivated(actor.ref)) - given("Someone is awaiting de-activation") awaiting.awaitDeActivation() - when("Actor is de-activated") publish(EndpointDeActivated(actor.ref)) - then("Awaiting gets notified") awaiting.verifyDeActivated() } "ActivationTracker forwards de-activation message even if someone awaits de-activation even before activation happens" taggedAs TimingTest in { - given("Someone is awaiting de-activation") val awaiting = new Awaiting(actor) awaiting.awaitDeActivation() - given("Actor is activated") publish(EndpointActivated(actor.ref)) - when("Actor is de-activated") publish(EndpointDeActivated(actor.ref)) - then("Awaiting gets notified") awaiting.verifyDeActivated() } diff --git a/akka-docs/scala/testing.rst b/akka-docs/scala/testing.rst index 0ca0373f5f..61da6aa6f5 100644 --- a/akka-docs/scala/testing.rst +++ b/akka-docs/scala/testing.rst @@ -219,7 +219,7 @@ assertions concerning received messages. Here is the full list: An object which is an instance of the given type (after erasure) must be received within the allotted time frame; the object will be returned. This method is approximately equivalent to - ``expectMsgClass(manifest[T].erasure)``. + ``expectMsgClass(implicitly[ClassTag[T]].runtimeClass)``. * :meth:`expectMsgAnyOf[T](d: Duration, obj: T*): T` diff --git a/akka-osgi/src/test/scala/akka/osgi/PojoSRTestSupport.scala b/akka-osgi/src/test/scala/akka/osgi/PojoSRTestSupport.scala index e928f42c53..9e1b1012db 100644 --- a/akka-osgi/src/test/scala/akka/osgi/PojoSRTestSupport.scala +++ b/akka-osgi/src/test/scala/akka/osgi/PojoSRTestSupport.scala @@ -16,6 +16,7 @@ import java.util.jar.JarInputStream import java.io.{ FileInputStream, FileOutputStream, File } import org.scalatest.{ BeforeAndAfterAll, Suite } import java.util.{ UUID, Date, ServiceLoader, HashMap } +import scala.reflect.ClassTag /** * Trait that provides support for building akka-osgi tests using PojoSR @@ -55,8 +56,8 @@ trait PojoSRTestSupport extends Suite with BeforeAndAfterAll { * Convenience method to find a service by interface. If the service is not already available in the OSGi Service * Registry, this method will wait for a few seconds for the service to appear. */ - def serviceForType[T](implicit manifest: Manifest[T]): T = - context.getService(awaitReference(manifest.erasure)).asInstanceOf[T] + def serviceForType[T](implicit t: ClassTag[T]): T = + context.getService(awaitReference(t.runtimeClass)).asInstanceOf[T] def awaitReference(serviceType: Class[_]): ServiceReference = awaitReference(serviceType, START_WAIT_TIME) diff --git a/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala b/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala index b073cca23d..ba830b3855 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestActorRef.scala @@ -8,6 +8,7 @@ import akka.actor._ import java.util.concurrent.atomic.AtomicLong import akka.dispatch._ import scala.concurrent.Await +import scala.reflect.ClassTag import akka.pattern.ask /** @@ -121,10 +122,10 @@ object TestActorRef { def apply[T <: Actor](props: Props, supervisor: ActorRef, name: String)(implicit system: ActorSystem): TestActorRef[T] = new TestActorRef(system.asInstanceOf[ActorSystemImpl], system.dispatchers.prerequisites, props, supervisor.asInstanceOf[InternalActorRef], name) - def apply[T <: Actor](implicit m: Manifest[T], system: ActorSystem): TestActorRef[T] = apply[T](randomName) + def apply[T <: Actor](implicit t: ClassTag[T], system: ActorSystem): TestActorRef[T] = apply[T](randomName) - def apply[T <: Actor](name: String)(implicit m: Manifest[T], system: ActorSystem): TestActorRef[T] = apply[T](Props({ - system.asInstanceOf[ExtendedActorSystem].dynamicAccess.createInstanceFor[T](m.erasure, Seq()) match { + def apply[T <: Actor](name: String)(implicit t: ClassTag[T], system: ActorSystem): TestActorRef[T] = apply[T](Props({ + system.asInstanceOf[ExtendedActorSystem].dynamicAccess.createInstanceFor[T](t.runtimeClass, Seq()) match { case Right(value) ⇒ value case Left(exception) ⇒ throw new ActorInitializationException(null, "Could not instantiate Actor" + diff --git a/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala b/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala index 5d6d7ad0f3..6c0eb7c993 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestEventListener.scala @@ -13,6 +13,7 @@ import akka.event.Logging import java.lang.{ Iterable ⇒ JIterable } import scala.collection.JavaConverters import scala.concurrent.util.Duration +import scala.reflect.ClassTag /** * Implementation helpers of the EventFilter facilities: send `Mute` @@ -158,8 +159,8 @@ object EventFilter { * `null` does NOT work (passing `null` disables the * source filter).'' */ - def apply[A <: Throwable: Manifest](message: String = null, source: String = null, start: String = "", pattern: String = null, occurrences: Int = Int.MaxValue): EventFilter = - ErrorFilter(manifest[A].erasure, Option(source), + def apply[A <: Throwable: ClassTag](message: String = null, source: String = null, start: String = "", pattern: String = null, occurrences: Int = Int.MaxValue): EventFilter = + ErrorFilter(implicitly[ClassTag[A]].runtimeClass, Option(source), if (message ne null) Left(message) else Option(pattern) map (new Regex(_)) toRight start, message ne null)(occurrences) diff --git a/akka-testkit/src/main/scala/akka/testkit/TestKit.scala b/akka-testkit/src/main/scala/akka/testkit/TestKit.scala index 8bbb18bc64..cbdeb34a0d 100644 --- a/akka-testkit/src/main/scala/akka/testkit/TestKit.scala +++ b/akka-testkit/src/main/scala/akka/testkit/TestKit.scala @@ -14,6 +14,7 @@ import atomic.AtomicInteger import scala.annotation.tailrec import akka.util.{ Timeout, BoxedType } import scala.annotation.varargs +import scala.reflect.ClassTag import akka.japi.PurePartialFunction object TestActor { @@ -324,7 +325,7 @@ trait TestKitBase { /** * Same as `expectMsgType[T](remaining)`, but correctly treating the timeFactor. */ - def expectMsgType[T](implicit m: Manifest[T]): T = expectMsgClass_internal(remaining, m.erasure.asInstanceOf[Class[T]]) + def expectMsgType[T](implicit t: ClassTag[T]): T = expectMsgClass_internal(remaining, t.runtimeClass.asInstanceOf[Class[T]]) /** * Receive one message from the test actor and assert that it conforms to the @@ -333,7 +334,7 @@ trait TestKitBase { * * @return the received object */ - def expectMsgType[T](max: Duration)(implicit m: Manifest[T]): T = expectMsgClass_internal(max.dilated, m.erasure.asInstanceOf[Class[T]]) + def expectMsgType[T](max: Duration)(implicit t: ClassTag[T]): T = expectMsgClass_internal(max.dilated, t.runtimeClass.asInstanceOf[Class[T]]) /** * Same as `expectMsgClass(remaining, c)`, but correctly treating the timeFactor. diff --git a/akka-testkit/src/main/scala/akka/testkit/package.scala b/akka-testkit/src/main/scala/akka/testkit/package.scala index 26bdc49e5b..e9d37d8e70 100644 --- a/akka-testkit/src/main/scala/akka/testkit/package.scala +++ b/akka-testkit/src/main/scala/akka/testkit/package.scala @@ -5,6 +5,7 @@ import language.implicitConversions import akka.actor.ActorSystem import scala.concurrent.util.Duration import java.util.concurrent.TimeUnit.MILLISECONDS +import scala.reflect.ClassTag package object testkit { def filterEvents[T](eventFilters: Iterable[EventFilter])(block: ⇒ T)(implicit system: ActorSystem): T = { @@ -28,7 +29,7 @@ package object testkit { def filterEvents[T](eventFilters: EventFilter*)(block: ⇒ T)(implicit system: ActorSystem): T = filterEvents(eventFilters.toSeq)(block) - def filterException[T <: Throwable](block: ⇒ Unit)(implicit system: ActorSystem, m: Manifest[T]): Unit = EventFilter[T]() intercept (block) + def filterException[T <: Throwable](block: ⇒ Unit)(implicit system: ActorSystem, t: ClassTag[T]): Unit = EventFilter[T]() intercept (block) /** * Scala API. Scale timeouts (durations) during tests with the configured diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index 478d54c685..7bbfca5a51 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -403,7 +403,7 @@ object AkkaBuild extends Build { resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/", // compile options - scalacOptions ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", /*"-deprecation",*/ "-feature", "-unchecked", "-Xlog-reflective-calls") ++ ( + scalacOptions ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls") ++ ( if (true || (System getProperty "java.runtime.version" startsWith "1.7")) Seq() else Seq("-optimize")), // -optimize fails with jdk7 javacOptions ++= Seq("-Xlint:unchecked", "-Xlint:deprecation"),