You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "aglinxinyuan (via GitHub)" <gi...@apache.org> on 2026/05/03 01:14:40 UTC
[PR] test(amber): add unit test coverage for StateManager [texera]
aglinxinyuan opened a new pull request, #4738:
URL: https://github.com/apache/texera/pull/4738
### What changes were proposed in this PR?
Add `StateManagerSpec` covering the full public surface of `StateManager` (`amber/src/main/scala/org/apache/texera/amber/engine/common/statetransition/StateManager.scala`):
- `getCurrentState` reports the initial state
- `transitTo` advances on a valid edge, is a no-op on self-transition, throws `InvalidTransitionException` for non-successor targets, and throws for states absent from the graph keys
- `assertState` (single + varargs) returns normally on match and throws `InvalidStateException` on mismatch
- `confirmState` (single + varargs) reports membership without side effects
- `conditionalTransitTo` runs the callback only when the precondition holds, does nothing otherwise, and still validates the transition edge
### Any related issues, documentation, discussions?
Closes #4737
### How was this PR tested?
`sbt "WorkflowExecutionService/testOnly org.apache.texera.amber.engine.common.statetransition.StateManagerSpec"` — 13/13 tests pass.
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for StateManager [texera]
Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan commented on code in PR #4738:
URL: https://github.com/apache/texera/pull/4738#discussion_r3177512405
##########
amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/StateManagerSpec.scala:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.common.statetransition
+
+import org.apache.texera.amber.core.virtualidentity.ActorVirtualIdentity
+import org.apache.texera.amber.engine.common.statetransition.StateManager.{
+ InvalidStateException,
+ InvalidTransitionException
+}
+import org.scalatest.flatspec.AnyFlatSpec
+
+class StateManagerSpec extends AnyFlatSpec {
+
+ private sealed trait DummyState
+ private case object S0 extends DummyState
+ private case object S1 extends DummyState
+ private case object S2 extends DummyState
+ private case object Orphan extends DummyState
+
+ private val actorId: ActorVirtualIdentity = ActorVirtualIdentity("test-actor")
+
+ /** Linear graph S0 -> S1 -> S2; S2 is terminal. Orphan is unreachable. */
+ private def linear(initial: DummyState = S0): StateManager[DummyState] =
+ new StateManager[DummyState](
+ actorId,
+ Map(
+ S0 -> Set(S1),
+ S1 -> Set(S2),
+ S2 -> Set.empty
+ ),
+ initial
+ )
+
+ "StateManager" should "report the initial state via getCurrentState" in {
+ assert(linear(S1).getCurrentState == S1)
+ }
+
+ "StateManager.transitTo" should "advance to a state listed as a successor in the transition graph" in {
+ val sm = linear()
+ sm.transitTo(S1)
+ assert(sm.getCurrentState == S1)
+ }
+
+ it should "be a no-op when transitioning to the current state" in {
+ val sm = linear(S1)
+ sm.transitTo(S1)
+ assert(sm.getCurrentState == S1)
+ }
+
+ it should "throw InvalidTransitionException when the target is not a successor of the current state" in {
+ val sm = linear()
+ val ex = intercept[InvalidTransitionException] {
+ sm.transitTo(S2)
+ }
+ assert(ex.getMessage.contains(S0.toString))
+ assert(ex.getMessage.contains(S2.toString))
+ }
+
+ it should "throw InvalidTransitionException for a state absent from the transition graph keys" in {
+ val sm = linear(S2) // S2 has no outgoing transitions
+ intercept[InvalidTransitionException] {
+ sm.transitTo(Orphan)
+ }
+ }
+
Review Comment:
Done in 3ae9138d33. Renamed the existing case to match what it actually asserts ("transitioning out of a terminal state with no listed successors") and added a separate case that drives the absent-key path by initializing with `Orphan`, which is intentionally not a key in `linear()`.
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for StateManager [texera]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #4738:
URL: https://github.com/apache/texera/pull/4738#discussion_r3177467950
##########
amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/StateManagerSpec.scala:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.common.statetransition
+
+import org.apache.texera.amber.core.virtualidentity.ActorVirtualIdentity
+import org.apache.texera.amber.engine.common.statetransition.StateManager.{
+ InvalidStateException,
+ InvalidTransitionException
+}
+import org.scalatest.flatspec.AnyFlatSpec
+
+class StateManagerSpec extends AnyFlatSpec {
+
+ private sealed trait DummyState
+ private case object S0 extends DummyState
+ private case object S1 extends DummyState
+ private case object S2 extends DummyState
+ private case object Orphan extends DummyState
+
+ private val actorId: ActorVirtualIdentity = ActorVirtualIdentity("test-actor")
+
+ /** Linear graph S0 -> S1 -> S2; S2 is terminal. Orphan is unreachable. */
+ private def linear(initial: DummyState = S0): StateManager[DummyState] =
+ new StateManager[DummyState](
+ actorId,
+ Map(
+ S0 -> Set(S1),
+ S1 -> Set(S2),
+ S2 -> Set.empty
+ ),
+ initial
+ )
+
+ "StateManager" should "report the initial state via getCurrentState" in {
+ assert(linear(S1).getCurrentState == S1)
+ }
+
+ "StateManager.transitTo" should "advance to a state listed as a successor in the transition graph" in {
+ val sm = linear()
+ sm.transitTo(S1)
+ assert(sm.getCurrentState == S1)
+ }
+
+ it should "be a no-op when transitioning to the current state" in {
+ val sm = linear(S1)
+ sm.transitTo(S1)
+ assert(sm.getCurrentState == S1)
+ }
+
+ it should "throw InvalidTransitionException when the target is not a successor of the current state" in {
+ val sm = linear()
+ val ex = intercept[InvalidTransitionException] {
+ sm.transitTo(S2)
+ }
+ assert(ex.getMessage.contains(S0.toString))
+ assert(ex.getMessage.contains(S2.toString))
+ }
+
+ it should "throw InvalidTransitionException for a state absent from the transition graph keys" in {
+ val sm = linear(S2) // S2 has no outgoing transitions
+ intercept[InvalidTransitionException] {
+ sm.transitTo(Orphan)
+ }
+ }
+
Review Comment:
The test case labeled "throw InvalidTransitionException for a state absent from the transition graph keys" doesn't actually cover the "absent from graph keys" scenario: `S2` is present as a key in `linear()` (with `Set.empty`), and `StateManager.transitTo` only consults `stateTransitionGraph` for the *current* state key (it doesn't require the target to be a key). This currently just tests "target not a successor" again.
To cover the intended behavior, add a case where the *current* state is not in the graph keys (e.g., initialize the StateManager to `Orphan` while the graph omits `Orphan`), and assert `transitTo(...)` throws `InvalidTransitionException`. Also update the test description to match what it's asserting.
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for StateManager [texera]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #4738:
URL: https://github.com/apache/texera/pull/4738#issuecomment-4365107415
## [Codecov](https://app.codecov.io/gh/apache/texera/pull/4738?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 42.12%. Comparing base ([`a5b8957`](https://app.codecov.io/gh/apache/texera/commit/a5b895715e589f7f74c1459cd314861288126532?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`8b3ad9a`](https://app.codecov.io/gh/apache/texera/commit/8b3ad9af2cd86069e8bfba441567b29b9c3c0cda?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #4738 +/- ##
============================================
- Coverage 42.13% 42.12% -0.01%
Complexity 2001 2001
============================================
Files 957 957
Lines 34094 34094
Branches 3753 3753
============================================
- Hits 14364 14363 -1
- Misses 18952 18953 +1
Partials 778 778
```
| [Flag](https://app.codecov.io/gh/apache/texera/pull/4738/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [python](https://app.codecov.io/gh/apache/texera/pull/4738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.77% <ø> (-0.03%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/texera/pull/4738?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(amber): add unit test coverage for StateManager [texera]
Posted by "Yicong-Huang (via GitHub)" <gi...@apache.org>.
Yicong-Huang merged PR #4738:
URL: https://github.com/apache/texera/pull/4738
--
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: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org