aglinxinyuan commented on code in PR #4562: URL: https://github.com/apache/texera/pull/4562#discussion_r3171272807
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/ScheduleSpec.scala: ########## @@ -0,0 +1,96 @@ +/* + * 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.scheduling + +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 +import org.scalatest.flatspec.AnyFlatSpec + +class ScheduleSpec extends AnyFlatSpec { + + private def region(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) + } + + "Schedule.getRegions" should "return all regions across all levels" in { + val r0 = region(0, "a") + val r1a = region(1, "b") + val r1b = region(2, "c") + val schedule = Schedule(Map(0 -> Set(r0), 1 -> Set(r1a, r1b))) + + assert(schedule.getRegions.toSet == Set(r0, r1a, r1b)) + } + + it should "return an empty list when the schedule is empty" in { + assert(Schedule(Map.empty).getRegions.isEmpty) + } + + "Schedule" should "iterate level sets in ascending key order starting from the minimum level" in { + val r0 = region(0, "a") + val r1 = region(1, "b") + val r2 = region(2, "c") + val schedule = Schedule(Map(1 -> Set(r1), 0 -> Set(r0), 2 -> Set(r2))) + + assert(schedule.toList == List(Set(r0), Set(r1), Set(r2))) + } + + it should "report hasNext as false for an empty schedule" in { + assert(!Schedule(Map.empty).hasNext) + } + + it should "report hasNext as false after the last contiguous level is consumed" in { + val schedule = Schedule(Map(0 -> Set(region(0, "a")), 1 -> Set(region(1, "b")))) + schedule.next() + schedule.next() + assert(!schedule.hasNext) + } + + it should "stop iteration at the first gap in level keys" in { + val r0 = region(0, "a") + val rGapped = region(2, "b") + val schedule = Schedule(Map(0 -> Set(r0), 2 -> Set(rGapped))) + + assert(schedule.next() == Set(r0)) + assert(!schedule.hasNext) + } Review Comment: Good call. Added the contiguity invariant to `Schedule` itself in #4444 (commit 9472125611) — it now `require`s level keys to be exactly `0..N-1`, so gaps are no longer permitted. This test will need to be removed (and replaced with a `require` rejection test) once #4444 lands. I will update this PR to drop the gap/non-zero tests and add a rejection test. -- 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]
