Copilot commented on code in PR #4740: URL: https://github.com/apache/texera/pull/4740#discussion_r3177468166
########## amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/WorkerStateManagerSpec.scala: ########## @@ -0,0 +1,107 @@ +/* + * 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.architecture.worker.statistics.WorkerState +import org.apache.texera.amber.engine.architecture.worker.statistics.WorkerState._ +import org.apache.texera.amber.engine.common.statetransition.StateManager.InvalidTransitionException +import org.scalatest.flatspec.AnyFlatSpec + +class WorkerStateManagerSpec extends AnyFlatSpec { + + private val actorId: ActorVirtualIdentity = ActorVirtualIdentity("test-worker") + + private def newManager(initial: WorkerState = UNINITIALIZED): WorkerStateManager = + new WorkerStateManager(actorId, initial) + + "WorkerStateManager" should "default to the UNINITIALIZED state" in { + assert(newManager().getCurrentState == UNINITIALIZED) + } Review Comment: The helper `newManager(initial: WorkerState = UNINITIALIZED)` always passes an explicit initial state into `new WorkerStateManager(actorId, initial)`. That means the test "default to the UNINITIALIZED state" is not actually exercising `WorkerStateManager`'s own default-parameter behavior (it would still pass even if `WorkerStateManager`'s default changed). Consider constructing with `new WorkerStateManager(actorId)` in that test, or removing the default from `newManager` so the default only lives in `WorkerStateManager`. ########## amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/WorkerStateManagerSpec.scala: ########## @@ -0,0 +1,107 @@ +/* + * 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.architecture.worker.statistics.WorkerState +import org.apache.texera.amber.engine.architecture.worker.statistics.WorkerState._ +import org.apache.texera.amber.engine.common.statetransition.StateManager.InvalidTransitionException +import org.scalatest.flatspec.AnyFlatSpec + +class WorkerStateManagerSpec extends AnyFlatSpec { + + private val actorId: ActorVirtualIdentity = ActorVirtualIdentity("test-worker") + + private def newManager(initial: WorkerState = UNINITIALIZED): WorkerStateManager = + new WorkerStateManager(actorId, initial) + + "WorkerStateManager" should "default to the UNINITIALIZED state" in { + assert(newManager().getCurrentState == UNINITIALIZED) + } + + it should "honor the explicit initial state when provided" in { + assert(newManager(READY).getCurrentState == READY) + } + + // -- Allowed transitions per the documented graph -- + + it should "allow UNINITIALIZED -> READY" in { + val sm = newManager() + sm.transitTo(READY) + assert(sm.getCurrentState == READY) + } + + it should "allow READY -> RUNNING, RUNNING -> PAUSED, PAUSED -> RUNNING, RUNNING -> COMPLETED" in { + val sm = newManager(READY) + sm.transitTo(RUNNING) + sm.transitTo(PAUSED) + sm.transitTo(RUNNING) + sm.transitTo(COMPLETED) + assert(sm.getCurrentState == COMPLETED) + } + + it should "allow READY -> PAUSED and READY -> COMPLETED directly" in { + val sm1 = newManager(READY) + sm1.transitTo(PAUSED) + assert(sm1.getCurrentState == PAUSED) + + val sm2 = newManager(READY) + sm2.transitTo(COMPLETED) + assert(sm2.getCurrentState == COMPLETED) + } + + // -- Disallowed transitions -- + + it should "reject UNINITIALIZED -> RUNNING (must go through READY)" in { + val sm = newManager() + intercept[InvalidTransitionException] { + sm.transitTo(RUNNING) + } + } + + it should "treat COMPLETED as a terminal state" in { + val sm = newManager(COMPLETED) + intercept[InvalidTransitionException] { + sm.transitTo(RUNNING) + } + intercept[InvalidTransitionException] { + sm.transitTo(READY) + } + // Self-transition is a no-op, not an exception. + sm.transitTo(COMPLETED) + assert(sm.getCurrentState == COMPLETED) + } + + it should "reject transitions into TERMINATED (TERMINATED is absent from the graph)" in { + Seq(UNINITIALIZED, READY, RUNNING, PAUSED).foreach { from => + val sm = newManager(from) + intercept[InvalidTransitionException] { + sm.transitTo(TERMINATED) + } + } + } Review Comment: The test for rejecting transitions into `TERMINATED` iterates over `UNINITIALIZED`, `READY`, `RUNNING`, and `PAUSED`, but not `COMPLETED`. Since the PR description/issue states TERMINATED should be rejected from any state, consider including `COMPLETED` as well (and optionally verifying `COMPLETED -> TERMINATED` is rejected alongside other terminal-state assertions). ########## amber/src/test/scala/org/apache/texera/amber/engine/common/statetransition/WorkerStateManagerSpec.scala: ########## @@ -0,0 +1,107 @@ +/* + * 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.architecture.worker.statistics.WorkerState +import org.apache.texera.amber.engine.architecture.worker.statistics.WorkerState._ +import org.apache.texera.amber.engine.common.statetransition.StateManager.InvalidTransitionException +import org.scalatest.flatspec.AnyFlatSpec + +class WorkerStateManagerSpec extends AnyFlatSpec { + + private val actorId: ActorVirtualIdentity = ActorVirtualIdentity("test-worker") + + private def newManager(initial: WorkerState = UNINITIALIZED): WorkerStateManager = + new WorkerStateManager(actorId, initial) + + "WorkerStateManager" should "default to the UNINITIALIZED state" in { + assert(newManager().getCurrentState == UNINITIALIZED) + } + + it should "honor the explicit initial state when provided" in { + assert(newManager(READY).getCurrentState == READY) + } + + // -- Allowed transitions per the documented graph -- + + it should "allow UNINITIALIZED -> READY" in { + val sm = newManager() + sm.transitTo(READY) + assert(sm.getCurrentState == READY) + } + + it should "allow READY -> RUNNING, RUNNING -> PAUSED, PAUSED -> RUNNING, RUNNING -> COMPLETED" in { + val sm = newManager(READY) + sm.transitTo(RUNNING) + sm.transitTo(PAUSED) + sm.transitTo(RUNNING) + sm.transitTo(COMPLETED) + assert(sm.getCurrentState == COMPLETED) + } + + it should "allow READY -> PAUSED and READY -> COMPLETED directly" in { + val sm1 = newManager(READY) + sm1.transitTo(PAUSED) + assert(sm1.getCurrentState == PAUSED) + + val sm2 = newManager(READY) + sm2.transitTo(COMPLETED) + assert(sm2.getCurrentState == COMPLETED) Review Comment: This spec groups multiple allowed transitions into one test. If one edge regresses, the failure doesn’t clearly identify which transition in the sequence broke. Splitting this into separate test cases per edge (or at least per source state) would make failures more actionable while still validating the same graph. -- 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]
