aglinxinyuan commented on code in PR #4914: URL: https://github.com/apache/texera/pull/4914#discussion_r3180099793
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/worker/PauseTypeSpec.scala: ########## @@ -0,0 +1,142 @@ +/* + * 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.worker + +import org.apache.texera.amber.core.virtualidentity.EmbeddedControlMessageIdentity +import org.scalatest.flatspec.AnyFlatSpec + +class PauseTypeSpec extends AnyFlatSpec { + + // --- singletons ------------------------------------------------------------ + + "PauseType singletons" should "all extend the sealed trait PauseType" in { + val all: List[PauseType] = List(UserPause, BackpressurePause, OperatorLogicPause) + all.foreach(p => assert(p.isInstanceOf[PauseType])) Review Comment: Done in 54259be03e — agreed; the runtime check is tautological because `all: List[PauseType] = ...` already enforces subtype membership at compile time. Removed the entire test (it was the only assertion in it) and replaced it with a short comment block in the spec documenting the design choice, so future contributors don't reflexively re-add it. ########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/worker/PauseTypeSpec.scala: ########## @@ -0,0 +1,142 @@ +/* + * 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.worker + +import org.apache.texera.amber.core.virtualidentity.EmbeddedControlMessageIdentity +import org.scalatest.flatspec.AnyFlatSpec + +class PauseTypeSpec extends AnyFlatSpec { + + // --- singletons ------------------------------------------------------------ + + "PauseType singletons" should "all extend the sealed trait PauseType" in { + val all: List[PauseType] = List(UserPause, BackpressurePause, OperatorLogicPause) + all.foreach(p => assert(p.isInstanceOf[PauseType])) + } + + it should "compare equal to themselves and unequal to each other" in { + // Widen to PauseType so the compiler doesn't reduce inter-singleton + // comparisons to constant `false` at compile time. + val u: PauseType = UserPause + val b: PauseType = BackpressurePause + val o: PauseType = OperatorLogicPause + assert(u == UserPause) + assert(b == BackpressurePause) + assert(o == OperatorLogicPause) + assert(u != b) + assert(u != o) + assert(b != o) + } + + it should "be the same singleton instance per access (object identity)" in { + assert((UserPause: AnyRef) eq UserPause) + assert((BackpressurePause: AnyRef) eq BackpressurePause) + assert((OperatorLogicPause: AnyRef) eq OperatorLogicPause) + } + + // --- ECMPause -------------------------------------------------------------- + + "ECMPause" should "carry the EmbeddedControlMessageIdentity it was constructed with" in { + val id = EmbeddedControlMessageIdentity("ckpt-1") + val p = ECMPause(id) + assert(p.id == id) + } + + it should "support case-class value equality and hashCode (same id → equal)" in { + val a = ECMPause(EmbeddedControlMessageIdentity("ckpt-1")) + val b = ECMPause(EmbeddedControlMessageIdentity("ckpt-1")) + val c = ECMPause(EmbeddedControlMessageIdentity("ckpt-2")) + assert(a == b) + assert(a.hashCode == b.hashCode) + assert(a != c) + } + + it should "be a PauseType but not equal to any of the singleton PauseTypes" in { + val p: PauseType = ECMPause(EmbeddedControlMessageIdentity("ckpt")) + assert(p.isInstanceOf[PauseType]) Review Comment: Done in 54259be03e — same reasoning, dropped the redundant `assert(p.isInstanceOf[PauseType])` from the ECMPause-vs-singleton test (the `val p: PauseType = ...` ascription already proves the relationship). Renamed the test to `"not equal any of the singleton PauseTypes"` so the description matches what's actually being asserted. -- 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]
