Skip to content
Merged
Show file tree
Hide file tree
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 @@ -52,7 +52,7 @@ case class OperatorExecution() {
*/
def initWorkerExecution(workerId: ActorVirtualIdentity): WorkerExecution = {
assert(
!workerExecutions.contains(workerId),
!workerExecutions.containsKey(workerId),
Comment thread
carloea2 marked this conversation as resolved.
s"WorkerExecution already exists for workerId: $workerId"
)
workerExecutions.put(workerId, WorkerExecution())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,34 +78,15 @@ class OperatorExecutionSpec extends AnyFlatSpec {
assert(opExec.getWorkerExecution(w) eq workerExec)
}

// The class docstring claims `initWorkerExecution` throws
// `AssertionError` on a duplicate worker id, but the implementation's
// `workerExecutions.contains(workerId)` call resolves to Java
// `ConcurrentHashMap.contains(Object)`, which checks VALUES rather than
// KEYS — so the assertion never fires and the second call silently
// overwrites the prior WorkerExecution. We pin the CURRENT (broken)
// behavior here so a future fix is noticed in CI, and document the
// intended contract with `pendingUntilFixed` so the failure surfaces
// the day the implementation is corrected.

it should
"currently overwrite the previous WorkerExecution on a second init for the same id " +
"(characterization of the contains-by-value bug)" in {
"reject a second init for the same id without replacing the existing execution" in {
val opExec = OperatorExecution()
val w = workerId("w-1")
val firstExec = opExec.initWorkerExecution(w)
val secondExec = opExec.initWorkerExecution(w)
assert(firstExec ne secondExec, "current impl replaces the prior WorkerExecution instance")
assert(opExec.getWorkerExecution(w) eq secondExec)
}

it should "(desired) throw AssertionError when initWorkerExecution is called twice for the same id" in pendingUntilFixed {
val opExec = OperatorExecution()
val w = workerId("w-1")
opExec.initWorkerExecution(w)
assertThrows[AssertionError] {
opExec.initWorkerExecution(w)
}
assert(opExec.getWorkerExecution(w) eq firstExec)
}

"OperatorExecution.getWorkerIds" should "be empty on a freshly constructed operator" in {
Expand Down
Loading