aglinxinyuan commented on code in PR #4838: URL: https://github.com/apache/texera/pull/4838#discussion_r3177871653
########## amber/src/test/scala/org/apache/texera/amber/engine/common/CheckpointSubsystemSpec.scala: ########## @@ -0,0 +1,143 @@ +/* + * 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 + +import org.apache.texera.amber.core.tuple.TupleLike +import org.apache.texera.amber.core.workflow.PortIdentity +import org.scalatest.flatspec.AnyFlatSpec + +class CheckpointSubsystemSpec extends AnyFlatSpec { + + // --------------------------------------------------------------------------- + // SerializedState + // --------------------------------------------------------------------------- + + "SerializedState" should "expose stable well-known key constants" in { + // These constants are referenced from outside the engine; pin the strings + // so a rename surfaces as a test failure. + assert(SerializedState.CP_STATE_KEY == "Amber_CPState") + assert(SerializedState.DP_STATE_KEY == "Amber_DPState") + assert(SerializedState.IN_FLIGHT_MSG_KEY == "Amber_Inflight_Messages") + assert(SerializedState.DP_QUEUED_MSG_KEY == "Amber_DP_Queued_Messages") + assert(SerializedState.OUTPUT_MSG_KEY == "Amber_Output_Messages") + } + + it should "round-trip a value through fromObject / toObject using the configured Serialization" in { + val original: java.lang.Integer = Integer.valueOf(42) + val state = SerializedState.fromObject(original, AmberRuntime.serde) + assert(state.bytes.length > 0) + assert(state.size() == state.bytes.length.toLong) + val restored = state.toObject[java.lang.Integer](AmberRuntime.serde) Review Comment: Done in 584dc7a880 — moved to a suite-local `ActorSystem` injected into `AmberRuntime` via reflection (`_actorSystem`/`_serde`), and added an `afterAll` that shuts it down with `TestKit.shutdownActorSystem`. The spec no longer leaks a globally-initialized Pekko system. ########## amber/src/test/scala/org/apache/texera/amber/engine/common/CheckpointSubsystemSpec.scala: ########## @@ -0,0 +1,143 @@ +/* + * 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 + +import org.apache.texera.amber.core.tuple.TupleLike +import org.apache.texera.amber.core.workflow.PortIdentity +import org.scalatest.flatspec.AnyFlatSpec + +class CheckpointSubsystemSpec extends AnyFlatSpec { + + // --------------------------------------------------------------------------- + // SerializedState + // --------------------------------------------------------------------------- + + "SerializedState" should "expose stable well-known key constants" in { + // These constants are referenced from outside the engine; pin the strings + // so a rename surfaces as a test failure. + assert(SerializedState.CP_STATE_KEY == "Amber_CPState") + assert(SerializedState.DP_STATE_KEY == "Amber_DPState") + assert(SerializedState.IN_FLIGHT_MSG_KEY == "Amber_Inflight_Messages") + assert(SerializedState.DP_QUEUED_MSG_KEY == "Amber_DP_Queued_Messages") + assert(SerializedState.OUTPUT_MSG_KEY == "Amber_Output_Messages") + } + + it should "round-trip a value through fromObject / toObject using the configured Serialization" in { + val original: java.lang.Integer = Integer.valueOf(42) + val state = SerializedState.fromObject(original, AmberRuntime.serde) + assert(state.bytes.length > 0) + assert(state.size() == state.bytes.length.toLong) + val restored = state.toObject[java.lang.Integer](AmberRuntime.serde) + assert(restored == original) + } + + it should "carry the serializer id and manifest given at construction" in { + val s = SerializedState(Array[Byte](1, 2, 3), serializerId = 7, manifest = "manifest-x") + assert(s.bytes.toSeq == Seq[Byte](1, 2, 3)) + assert(s.serializerId == 7) + assert(s.manifest == "manifest-x") + assert(s.size() == 3L) + } + + // --------------------------------------------------------------------------- + // CheckpointState + // --------------------------------------------------------------------------- + + "CheckpointState" should "default to size = 0 with no entries" in { + val cp = new CheckpointState() + assert(cp.size() == 0L) + assert(!cp.has("anything")) + } + + "CheckpointState.save / load" should "round-trip a primitive value" in { + val cp = new CheckpointState() + cp.save("answer", java.lang.Integer.valueOf(42)) + assert(cp.has("answer")) + val restored: java.lang.Integer = cp.load[java.lang.Integer]("answer") + assert(restored == java.lang.Integer.valueOf(42)) Review Comment: Done in 584dc7a880 — same fix as the sibling thread: `CheckpointState.save`/`load` now route through a suite-local `Serialization` instance injected into `AmberRuntime`, and the suite shuts the underlying `ActorSystem` down via `TestKit.shutdownActorSystem` in `afterAll`. -- 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]
