aglinxinyuan commented on code in PR #6311: URL: https://github.com/apache/texera/pull/6311#discussion_r3556446824
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/coordinator/promisehandlers/JumpToOperatorRegionHandlerSpec.scala: ########## @@ -0,0 +1,111 @@ +/* + * 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.coordinator.promisehandlers + +import org.apache.texera.amber.core.executor.OpExecInitInfo +import org.apache.texera.amber.core.virtualidentity.{ + ExecutionIdentity, + OperatorIdentity, + PhysicalOpIdentity, + WorkflowIdentity +} +import org.apache.texera.amber.core.workflow.{PhysicalOp, WorkflowContext} +import org.apache.texera.amber.engine.architecture.coordinator.{ + CoordinatorAsyncRPCHandlerInitializer, + CoordinatorConfig, + CoordinatorProcessor +} +import org.apache.texera.amber.engine.architecture.rpc.controlcommands.{ + AsyncRPCContext, + JumpToOperatorRegionRequest +} +import org.apache.texera.amber.engine.architecture.scheduling.{Region, RegionIdentity, Schedule} +import org.apache.texera.amber.engine.common.virtualidentity.util.COORDINATOR +import org.scalatest.flatspec.AnyFlatSpec + +class JumpToOperatorRegionHandlerSpec extends AnyFlatSpec { + + // A single-operator Region, matching the construction pattern used by + // WorkflowExecutionManagerSpec. The logical operator id (opId) is what the handler + // matches against JumpToOperatorRegionRequest.targetOperatorId. + private def singleOpRegion(regionId: Long, opId: String): Region = { + val physicalOp = PhysicalOp( + PhysicalOpIdentity(OperatorIdentity(opId), "main"), + WorkflowIdentity(0), + ExecutionIdentity(0), + OpExecInitInfo.Empty + ) + Region(RegionIdentity(regionId), Set(physicalOp), Set.empty) + } + + // Build a real CoordinatorProcessor + our own initializer (the processor's own + // initializer is private/inaccessible). Seed a 3-level, single-op-per-region schedule + // directly on the WorkflowExecutionManager, which is what the handler reads/mutates. + private def newHarness() + : (CoordinatorAsyncRPCHandlerInitializer, CoordinatorProcessor, Region, Region, Region) = { + val cp = new CoordinatorProcessor( + new WorkflowContext(), + CoordinatorConfig(None, None, None, None), + COORDINATOR, + _ => () + ) + val first = singleOpRegion(1, "first") + val second = singleOpRegion(2, "second") + val third = singleOpRegion(3, "third") + cp.workflowExecutionManager.schedule = Schedule( + Map( + 0 -> Set(first), + 1 -> Set(second), + 2 -> Set(third) + ) + ) + val init = new CoordinatorAsyncRPCHandlerInitializer(cp) + (init, cp, first, second, third) + } + + private val ctx: AsyncRPCContext = AsyncRPCContext(COORDINATOR, COORDINATOR) + + "JumpToOperatorRegionHandler" should + "move the schedule cursor to the level whose region contains the target operator" in { + val (init, cp, first, second, _) = newHarness() + + // Pull the first region so the cursor is no longer at level 0. + assert(cp.workflowExecutionManager.schedule.next() == Set(first)) + + // collectFirst finds level 1 (which holds "second") and the foreach rebuilds the schedule + // with initialLevelIndex = 1. + init.jumpToOperatorRegion(JumpToOperatorRegionRequest(OperatorIdentity("second")), ctx) + + assert(cp.workflowExecutionManager.schedule.next() == Set(second)) Review Comment: Right — it wasn't discriminating. Reworked it: consume levels 0 and 1 (cursor at 2, natural next = `third`), then jump *back* to "first" (level 0) and assert the next pull is `first`, not `third` — which only holds if the cursor was actually repositioned (c8da7a3). -- 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]
