org.scalatest.time

Span

class Span extends AnyRef

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)

Attributes
final
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Span
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  7. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  9. 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
  10. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  11. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef
  12. 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
  13. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  14. 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)
    

  15. 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)
    

  16. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  17. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  18. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  19. 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

  20. 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.ZeroLength to be returned.

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

  21. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  22. 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
  23. 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.

  24. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  25. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  26. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any