-
Notifications
You must be signed in to change notification settings - Fork 122
test(amber): add unit test coverage for Schedule iterator semantics #4562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aglinxinyuan
wants to merge
1
commit into
apache:main
Choose a base branch
from
aglinxinyuan:xinyuan-test-schedule-spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
.../src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/ScheduleSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
| } | ||
|
|
||
| it should "begin iteration from the minimum level when level keys do not start at zero" in { | ||
| val r3 = region(3, "a") | ||
| val r4 = region(4, "b") | ||
| val schedule = Schedule(Map(3 -> Set(r3), 4 -> Set(r4))) | ||
|
|
||
| assert(schedule.hasNext) | ||
| assert(schedule.next() == Set(r3)) | ||
| assert(schedule.next() == Set(r4)) | ||
| assert(!schedule.hasNext) | ||
| } | ||
|
Comment on lines
+86
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should disallow.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same — non-zero starting keys are now rejected by the |
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just disallow gaps?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Added the contiguity invariant to
Scheduleitself in #4444 (commit 9472125) — it nowrequires level keys to be exactly0..N-1, so gaps are no longer permitted. This test will need to be removed (and replaced with arequirerejection test) once #4444 lands. I will update this PR to drop the gap/non-zero tests and add a rejection test.