Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.concurrent.duration._
import scala.util.{Random, Try}
import scala.util.control.NonFatal

import java.util.{Base64, Comparator}
import java.util.{Base64, Collections, Comparator}
import java.util.concurrent.ConcurrentSkipListSet
import java.util.concurrent.atomic.{AtomicLong, AtomicReference}

Expand Down Expand Up @@ -60,11 +60,11 @@ import java.util.concurrent.atomic.{AtomicLong, AtomicReference}
* }}}
*/
final class TestContext private (_seed: Long) extends ExecutionContext { self =>
import TestContext.{ConcurrentState, Encoder, State, Task}
import TestContext.{InternalState, Encoder, State, Task}

private[this] val random = new Random(_seed)

private[this] val stateRef = new ConcurrentState()
private[this] val stateRef = new InternalState()

def execute(runnable: Runnable): Unit = {
val current = stateRef
Expand Down Expand Up @@ -280,13 +280,22 @@ object TestContext {
def apply(seed: String): TestContext =
new TestContext(new String(Decoder.decode(seed)).toLong)

@deprecated("Not intended to be public", "3.7.1")
final class ConcurrentState(
Comment on lines +283 to 284
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To comply with our no-source-breaking-patches versioning scheme, we may want to hold off the deprecation until 3.8.

val currentID: AtomicLong = new AtomicLong(),
val currentNanos: AtomicLong = new AtomicLong(),
val tasks: ConcurrentSkipListSet[Task] = new ConcurrentSkipListSet(Task.comparator),
val lastReportedFailure: AtomicReference[Throwable] = new AtomicReference()
)

private final class InternalState(
val currentID: AtomicLong = new AtomicLong(),
val currentNanos: AtomicLong = new AtomicLong(),
val tasks: java.util.SortedSet[Task] =
Collections.synchronizedSortedSet(new ConcurrentSkipListSet(Task.comparator)),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just use a ju.TreeSet instead the ConcurrentSkipListSet. As it is now, on the JVM it's "doubly thread safe". (Which is not incorrect, of course, just unnecessary.)

val lastReportedFailure: AtomicReference[Throwable] = new AtomicReference()
)

/**
* Used internally by [[TestContext]], represents the internal state used for task scheduling
* and execution.
Expand Down
Loading