aglinxinyuan commented on code in PR #6289: URL: https://github.com/apache/texera/pull/6289#discussion_r3555601686
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/worker/WorkflowWorkerSpec.scala: ########## @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.texera.amber.engine.architecture.worker + +import org.apache.pekko.actor.{ActorSystem, Props} +import org.apache.pekko.testkit.{ImplicitSender, TestActorRef, TestKit, TestProbe} +import org.apache.texera.amber.clustering.SingleNodeListener +import org.apache.texera.amber.core.executor.OpExecWithClassName +import org.apache.texera.amber.core.virtualidentity.{ + ActorVirtualIdentity, + ChannelIdentity, + EmbeddedControlMessageIdentity +} +import org.apache.texera.amber.engine.architecture.coordinator.ReplayStatusUpdate +import org.apache.texera.amber.engine.architecture.rpc.controlcommands.{ + AsyncRPCContext, + ControlInvocation, + EmptyRequest, + InitializeExecutorRequest +} +import org.apache.texera.amber.engine.architecture.scheduling.config.WorkerConfig +import org.apache.texera.amber.engine.architecture.worker.WorkflowWorker.{ + ActorCommandElement, + DPInputQueueElement, + FaultToleranceConfig, + MainThreadDelegateMessage, + StateRestoreConfig, + TimerBasedControlElement, + TriggerSend, + WorkerReplayInitialization +} +import org.apache.texera.amber.engine.common.actormessage.Backpressure +import org.apache.texera.amber.engine.common.ambermessage.WorkflowFIFOMessage +import org.apache.texera.amber.engine.common.virtualidentity.util.COORDINATOR +import org.apache.texera.amber.engine.common.{AmberRuntime, CheckpointState, SerializedState} +import org.scalatest.BeforeAndAfterAll +import org.scalatest.flatspec.AnyFlatSpecLike + +import java.net.URI +import java.util.concurrent.{CompletableFuture, LinkedBlockingQueue, TimeUnit} +import scala.collection.mutable + +class WorkflowWorkerSpec + extends TestKit(ActorSystem("WorkflowWorkerSpec", AmberRuntime.pekkoConfig)) + with ImplicitSender + with AnyFlatSpecLike + with BeforeAndAfterAll { + + // The "Worker:...-<idx>" form is required so VirtualIdentityUtils.getWorkerIndex + // resolves an index; otherwise loadFromCheckpoint's restoreExecutorState throws. + private val identifier1 = ActorVirtualIdentity("Worker:WF1-E1-op-layer-1") + + override def beforeAll(): Unit = { + system.actorOf(Props[SingleNodeListener](), "cluster-info") + } + + override def afterAll(): Unit = { + TestKit.shutdownActorSystem(system) + } + + private def mkWorker(): TestActorRef[WorkflowWorker] = + TestActorRef( + new WorkflowWorker(WorkerConfig(identifier1), WorkerReplayInitialization()) + ) + + "WorkflowWorker" should "enqueue backpressure, run handleActorCommand directly, and preRestart" in { + val worker = mkWorker() + // Stop the DP thread first: it blocks on inputQueue.take and would otherwise + // steal the element we enqueue below before we can poll it. + worker.underlyingActor.dpThread.stop() + + // (a) handleBackpressure enqueues an ActorCommandElement(Backpressure(true)). + worker.underlyingActor.handleBackpressure(true) + assert(worker.underlyingActor.inputQueue.poll() == ActorCommandElement(Backpressure(true))) + + // (b) handleActorCommand is dead code (not wired into receive); invoke it directly + // and apply the returned PartialFunction. + val handler = worker.underlyingActor.handleActorCommand Review Comment: Agreed — same call as the dead `READY` branch in #6140. Dropped the `handleActorCommand` test here (b2ec3c0) so it isn't cemented, and opened #6305 to delete the method itself (a bare `println` `Receive` that isn't in the `receive` chain and has no callers). Resolving. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
