Packages

final class Span extends Serializable

A time span.

A Span is used to express time spans in ScalaTest, in constructs such as the failAfter method of trait Timeouts, the timeLimit field of trait TimeLimitedTests, and the timeouts of traits Eventually, and AsyncAssertions. Here's an example:

import org.scalatest.time.Span
import org.scalatest.time.Millis
import org.scalatest.concurrent.Timeouts._

failAfter(Span(100, Millis)) { // ... }

If you prefer you can mix in or import the members of SpanSugar and place a units value after the timeout value. Here are some examples:

import org.scalatest.time.SpanSugar._
import org.scalatest.concurrent.Timeouts._

failAfter(100 millis) { // ... }
failAfter(1 second) { // ... }

In addition to expression the numeric value with an Int or a Long, you can also express it via a Float or Double. Here are some examples:

import org.scalatest.time.Span
import org.scalatest.time.Seconds
import org.scalatest.concurrent.Timeouts._

failAfter(Span(1.5, Seconds)) { // ... }
import org.scalatest.time.SpanSugar._
failAfter(0.8 seconds) { // ... }

Internally, a Span is expressed in terms of a Long number of nanoseconds. Thus, the maximum time span that can be represented is Long.MaxValue nanoseconds, or approximately 292 years. Hopefully these won't be "famous last words," but 292 years should be sufficient for software testing purposes. Any attempt to create a Span longer than Long.MaxValue nanoseconds will be met with an IllegalArgumentException:

Span(Long.MaxValue, Nanoseconds) // Produces the longest possible time.Span
Span(Long.MaxValue, Seconds)     // Produces an IllegalArgumentException

All of class Span's constructors are private. The only way you can create a new Span is via one of the two apply factory methods in Span's companion object. Here is a table showing one example of each numeric type and unit value:

Int Long Float Double
Span(1, Nanosecond) Span(1L, Nanosecond) Span(1.0F, Nanosecond) Span(1.0, Nanosecond)
Span(100, Nanoseconds) Span(100L, Nanoseconds) Span(99.8F, Nanoseconds) Span(99.8, Nanoseconds)
Span(1, Microsecond) Span(1L, Microsecond) Span(1.0F, Microsecond) Span(1.0, Microsecond)
Span(100, Microseconds) Span(100L, Microseconds) Span(99.8F, Microseconds) Span(99.8, Microseconds)
Span(1, Millisecond) Span(1L, Millisecond) Span(1.0F, Millisecond) Span(1.0, Millisecond)
Span(100, Milliseconds) Span(100L, Milliseconds) Span(99.8F, Milliseconds) Span(99.8, Milliseconds)
Span(100, Millis) Span(100L, Millis) Span(99.8F, Millis) Span(99.8, Millis)
Span(1, Second) Span(1L, Second) Span(1.0F, Second) Span(1.0, Second)
Span(100, Seconds) Span(100L, Seconds) Span(99.8F, Seconds) Span(99.8, Seconds)
Span(1, Minute) Span(1L, Minute) Span(1.0F, Minute) Span(1.0, Minute)
Span(100, Minutes) Span(100L, Minutes) Span(99.8F, Minutes) Span(99.8, Minutes)
Span(1, Hour) Span(1L, Hour) Span(1.0F, Hour) Span(1.0, Hour)
Span(100, Hours) Span(100L, Hours) Span(99.8F, Hours) Span(99.8, Hours)
Span(1, Day) Span(1L, Day) Span(1.0F, Day) Span(1.0, Day)
Span(100, Days) Span(100L, Days) Span(99.8F, Days) Span(99.8, Days)

Note that because of implicit conversions in the Span companion object, you can use a scala.concurrent.duration.Duration where a Span is needed, and vice versa.

Source
Span.scala
Linear Supertypes
Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Span
  2. Serializable
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(other: Any): Boolean

    Compares another object for equality.

    Compares another object for equality.

    If the passed object is a Span, this method will return true only if the other Span returns the exact same value as this Span for totalNanos.

    other

    the object to compare with this one for equality

    returns

    true if the other object is a Span with the same totalNanos value.

    Definition Classes
    Span → AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int

    Returns a hash code for this Span.

    Returns a hash code for this Span.

    returns

    a hash code based only on the totalNanos field.

    Definition Classes
    Span → AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. lazy val millisPart: Long

    This time span converted to milliseconds, computed via totalNanos / 1000000, which truncates off any leftover nanoseconds.

    This time span converted to milliseconds, computed via totalNanos / 1000000, which truncates off any leftover nanoseconds.

    The millisPart and nanosPart can be used, for example, when invoking Thread.sleep. For example, given a Span named span, you could write:

    Thread.sleep(span.millisPart, span.nanosPart)
    

  13. lazy val nanosPart: Int

    The number of nanoseconds remaining when this time span is converted to milliseconds, computed via (totalNanos % 1000000).toInt.

    The number of nanoseconds remaining when this time span is converted to milliseconds, computed via (totalNanos % 1000000).toInt.

    The millisPart and nanosPart can be used, for example, when invoking Thread.sleep. For example, given a Span named span, you could write:

    Thread.sleep(span.millisPart, span.nanosPart)
    

  14. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. lazy val prettyString: String

    Returns a localized string suitable for presenting to a user that describes the time span represented by this Span.

    Returns a localized string suitable for presenting to a user that describes the time span represented by this Span.

    For example, for Span(1, Millisecond), this method would return "1 millisecond". For Span(9.99, Seconds), this method would return "9.9 seconds".

    returns

    a localized string describing this Span

  18. def scaledBy(factor: Double): Span

    Returns a Span representing this Span scaled by the passed factor.

    Returns a Span representing this Span scaled by the passed factor.

    The passed factor can be any positive number or zero, including fractional numbers. A number greater than one will scale the Span up to a larger value. A fractional number will scale it down to a smaller value. A factor of 1.0 will cause the exact same Span to be returned. A factor of zero will cause Span.Zero to be returned.

    If overflow occurs, Span.Max will be returned. If underflow occurs, Span.Zero will be returned.

    Exceptions thrown

    IllegalArgumentException if the passed value is less than zero

  19. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String

    Returns a string that looks similar to a factory method call that would have produced this Span.

    Returns a string that looks similar to a factory method call that would have produced this Span.

    For example, for Span(1, Millisecond), this method would return "Span(1, Millisecond)". For Span(9.99, Seconds), this method would return "Span(9.99, Seconds)".

    returns

    a string that looks like a factory method call that would produce this Span

    Definition Classes
    Span → AnyRef → Any
  21. val totalNanos: Long

    The total number of nanoseconds in this time span.

    The total number of nanoseconds in this time span.

    This number will never be negative, but can be zero.

  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  24. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped