Copilot commented on code in PR #4838:
URL: https://github.com/apache/texera/pull/4838#discussion_r3177622964


##########
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:
   These `CheckpointState.save`/`load` calls also hit `AmberRuntime.serde` 
under the hood, so this spec still creates a global Pekko `ActorSystem` without 
ever terminating it. Even if the direct `SerializedState.fromObject(..., 
AmberRuntime.serde)` test is fixed, the suite will continue to leak runtime 
threads until it owns a local actor system and shuts it down in `afterAll`.



##########
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:
   This test calls `AmberRuntime.serde`, which lazily creates a new 
`ActorSystem("Amber", ...)` when no runtime has been initialized yet. Because 
the spec never shuts that system down—and `AmberRuntime.serde` does not even 
keep a handle to the temporary system it creates—the suite leaks Pekko threads 
globally, which can make the test process hang or interfere with later tests. 
Please use a suite-local `ActorSystem`/`SerializationExtension` that is 
terminated in `afterAll` instead of the global singleton here.



-- 
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]

Reply via email to