From d442f2024b49396c6e8748dc8eb845a305ddfebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Antonsson?= Date: Fri, 12 Oct 2012 14:21:54 +0200 Subject: [PATCH] More Duration cleanup, and changed use of ScalaNumber to ScalaNumericConversions. #2504 --- .../test/scala/akka/util/DurationSpec.scala | 9 +++++---- .../src/main/scala/akka/camel/Consumer.scala | 1 + .../java/akka/camel/CustomRouteTestBase.java | 1 - .../camel/SampleErrorHandlingConsumer.java | 2 +- .../scala/akka/camel/CamelConfigSpec.scala | 2 +- .../cluster/ClusterMetricsCollector.scala | 20 +++++++++---------- .../contrib/pattern/ReliableProxySpec.scala | 4 ++-- .../scala/akka/dataflow/DataflowSpec.scala | 4 +--- 8 files changed, 21 insertions(+), 22 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala b/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala index 39f8f769f5..d5c020be49 100644 --- a/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala @@ -33,11 +33,12 @@ class DurationSpec extends WordSpec with MustMatchers { val one = 1.second val inf = Duration.Inf val minf = Duration.MinusInf + val undefined = Duration.Undefined (-inf) must be(minf) - intercept[IllegalArgumentException] { minf + inf } - intercept[IllegalArgumentException] { inf - inf } - intercept[IllegalArgumentException] { inf + minf } - intercept[IllegalArgumentException] { minf - minf } + (minf + inf) must be(undefined) + (inf - inf) must be(undefined) + (inf + minf) must be(undefined) + (minf - minf) must be(undefined) (inf + inf) must be(inf) (inf - minf) must be(inf) (minf - inf) must be(minf) diff --git a/akka-camel/src/main/scala/akka/camel/Consumer.scala b/akka-camel/src/main/scala/akka/camel/Consumer.scala index 8a5db0a8ed..2915235745 100644 --- a/akka-camel/src/main/scala/akka/camel/Consumer.scala +++ b/akka-camel/src/main/scala/akka/camel/Consumer.scala @@ -8,6 +8,7 @@ import akka.camel.internal.CamelSupervisor.Register import org.apache.camel.model.{ RouteDefinition, ProcessorDefinition } import akka.actor._ import scala.concurrent.duration._ +import akka.dispatch.Mapper /** * Mixed in by Actor implementations that consume message from Camel endpoints. diff --git a/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java b/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java index c002bceec1..ae6d9c5531 100644 --- a/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java +++ b/akka-camel/src/test/java/akka/camel/CustomRouteTestBase.java @@ -17,7 +17,6 @@ import org.apache.camel.component.mock.MockEndpoint; import org.junit.Before; import org.junit.After; import org.junit.Test; -import scala.concurrent.util.FiniteDuration; import java.util.concurrent.TimeUnit; diff --git a/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java b/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java index 9c6af3ba2b..e8a057e1ac 100644 --- a/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java +++ b/akka-camel/src/test/java/akka/camel/SampleErrorHandlingConsumer.java @@ -12,7 +12,7 @@ import org.apache.camel.builder.Builder; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.RouteDefinition; import scala.Option; -import scala.concurrent.util.FiniteDuration; +import scala.concurrent.duration.FiniteDuration; /** * @author Martin Krasser diff --git a/akka-camel/src/test/scala/akka/camel/CamelConfigSpec.scala b/akka-camel/src/test/scala/akka/camel/CamelConfigSpec.scala index 9f4b802081..ca7b4ba3cc 100644 --- a/akka-camel/src/test/scala/akka/camel/CamelConfigSpec.scala +++ b/akka-camel/src/test/scala/akka/camel/CamelConfigSpec.scala @@ -6,7 +6,7 @@ package akka.camel import org.scalatest.matchers.MustMatchers import org.scalatest.WordSpec import akka.actor.ActorSystem -import scala.concurrent.util.Duration +import scala.concurrent.duration.Duration import java.util.concurrent.TimeUnit._ class CamelConfigSpec extends WordSpec with MustMatchers { diff --git a/akka-cluster/src/main/scala/akka/cluster/ClusterMetricsCollector.scala b/akka-cluster/src/main/scala/akka/cluster/ClusterMetricsCollector.scala index 180d3eb40a..984c7fa3b6 100644 --- a/akka-cluster/src/main/scala/akka/cluster/ClusterMetricsCollector.scala +++ b/akka-cluster/src/main/scala/akka/cluster/ClusterMetricsCollector.scala @@ -9,7 +9,7 @@ import scala.concurrent.duration._ import scala.collection.immutable.{ SortedSet, Map } import scala.concurrent.forkjoin.ThreadLocalRandom import scala.util.{ Try, Success, Failure } -import scala.math.ScalaNumber +import scala.math.ScalaNumericConversions import scala.runtime.{ RichLong, RichDouble, RichInt } import akka.actor._ @@ -238,7 +238,7 @@ private[cluster] case class MetricsGossipEnvelope(from: Address, gossip: Metrics * * @param startTime the time of initial sampling for this data stream */ -private[cluster] case class DataStream(decay: Int, ewma: ScalaNumber, startTime: Long, timestamp: Long) +private[cluster] case class DataStream(decay: Int, ewma: ScalaNumericConversions, startTime: Long, timestamp: Long) extends ClusterMessage with MetricNumericConverter { /** @@ -249,13 +249,13 @@ private[cluster] case class DataStream(decay: Int, ewma: ScalaNumber, startTime: /** * Calculates the exponentially weighted moving average for a given monitored data set. - * The datam can be too large to fit into an int or long, thus we use ScalaNumber, + * The datam can be too large to fit into an int or long, thus we use ScalaNumericConversions, * and defer to BigInt or BigDecimal. * * @param xn the new data point * @return an new [[akka.cluster.DataStream]] with the updated yn and timestamp */ - def :+(xn: ScalaNumber): DataStream = convert(xn) fold ( + def :+(xn: ScalaNumericConversions): DataStream = convert(xn) fold ( nl ⇒ copy(ewma = BigInt(α * nl + 1 - α * ewma.longValue()), timestamp = newTimestamp), nd ⇒ copy(ewma = BigDecimal(α * nd + 1 - α * ewma.doubleValue()), timestamp = newTimestamp)) @@ -273,7 +273,7 @@ private[cluster] case class DataStream(decay: Int, ewma: ScalaNumber, startTime: */ private[cluster] object DataStream { - def apply(decay: Int, data: ScalaNumber): Option[DataStream] = if (decay > 0) + def apply(decay: Int, data: ScalaNumericConversions): Option[DataStream] = if (decay > 0) Some(DataStream(decay, data, newTimestamp, newTimestamp)) else None } @@ -288,7 +288,7 @@ private[cluster] object DataStream { * @param average the data stream of the metric value, for trending over time. Metrics that are already * averages (e.g. system load average) or finite (e.g. as total cores), are not trended. */ -private[cluster] case class Metric(name: String, value: Option[ScalaNumber], average: Option[DataStream]) +private[cluster] case class Metric(name: String, value: Option[ScalaNumericConversions], average: Option[DataStream]) extends ClusterMessage with MetricNumericConverter { /** @@ -352,7 +352,7 @@ private[cluster] object Metric extends MetricNumericConverter { * or defined for the OS (JMX). If undefined we set the value option to None and do not modify * the latest sampled metric to avoid skewing the statistical trend. */ - def apply(name: String, value: Option[ScalaNumber]): Metric = value match { + def apply(name: String, value: Option[ScalaNumericConversions]): Metric = value match { case Some(v) if defined(v) ⇒ Metric(name, value, None) case _ ⇒ Metric(name, None, None) } @@ -409,15 +409,15 @@ private[cluster] trait MetricNumericConverter { * */ - def defined(value: ScalaNumber): Boolean = convert(value) fold (a ⇒ value != -1, b ⇒ !(b.isNaN || b.isInfinite)) + def defined(value: ScalaNumericConversions): Boolean = + convert(value) fold (a ⇒ value.underlying != -1, b ⇒ !(b.isNaN || b.isInfinite)) /** * May involve rounding or truncation. */ - def convert(from: ScalaNumber): Either[Long, Double] = from match { + def convert(from: ScalaNumericConversions): Either[Long, Double] = from match { case n: BigInt ⇒ Left(n.longValue()) case n: BigDecimal ⇒ Right(n.doubleValue()) - // FIXME: these are rejected as unreachable by the new pattern matcher case n: RichInt ⇒ Left(n.abs) case n: RichLong ⇒ Left(n.self) case n: RichDouble ⇒ Right(n.self) diff --git a/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala b/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala index 870028a3f2..3595b9887a 100644 --- a/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala +++ b/akka-contrib/src/multi-jvm/scala/akka/contrib/pattern/ReliableProxySpec.scala @@ -14,7 +14,7 @@ import akka.remote.testconductor.Direction import akka.actor.Props import akka.actor.Actor import akka.testkit.ImplicitSender -import scala.concurrent.util.duration._ +import scala.concurrent.duration._ import akka.actor.FSM import akka.actor.ActorRef import akka.testkit.TestProbe @@ -195,4 +195,4 @@ class ReliableProxySpec extends MultiNodeSpec(ReliableProxySpec) with STMultiNod } } -} \ No newline at end of file +} diff --git a/akka-dataflow/src/test/scala/akka/dataflow/DataflowSpec.scala b/akka-dataflow/src/test/scala/akka/dataflow/DataflowSpec.scala index 8af04d0e0a..0543b557c3 100644 --- a/akka-dataflow/src/test/scala/akka/dataflow/DataflowSpec.scala +++ b/akka-dataflow/src/test/scala/akka/dataflow/DataflowSpec.scala @@ -271,9 +271,7 @@ class DataflowSpec extends AkkaSpec with DefaultTimeout { assert(checkType(rString, classTag[String])) assert(checkType(rInt, classTag[Int])) assert(!checkType(rInt, classTag[String])) - assert(intercept[java.lang.Exception] { - assert(!checkType(rInt, classTag[Nothing])) - }.getMessage == "Nothing is a bottom type, therefore its erasure does not return a value") // When this fails, remove the intercept + assert(!checkType(rInt, classTag[Nothing])) assert(!checkType(rInt, classTag[Any])) Await.result(rString, timeout.duration)