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


##########
common/workflow-core/src/test/scala/org/apache/texera/amber/util/serde/PortIdentityKeyDeserializerSpec.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.util.serde
+
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import scala.jdk.CollectionConverters._
+
+class PortIdentityKeyDeserializerSpec extends AnyFlatSpec with Matchers {
+
+  private val deserializer = new PortIdentityKeyDeserializer
+
+  "PortIdentityKeyDeserializer.deserializeKey" should "parse id_internal keys 
into PortIdentity" in {
+    deserializer.deserializeKey("3_false", null) shouldBe PortIdentity(3, 
internal = false)
+    deserializer.deserializeKey("0_true", null) shouldBe PortIdentity(0, 
internal = true)
+  }
+
+  it should "round-trip serializer output for representative PortIdentity 
values" in {
+    val cases = Seq(
+      PortIdentity(0, internal = false),
+      PortIdentity(0, internal = true),
+      PortIdentity(999999, internal = false),
+      PortIdentity(999999, internal = true),
+      PortIdentity(-1, internal = false),
+      PortIdentity(-1, internal = true)
+    )
+
+    cases.foreach { portIdentity =>
+      deserializer.deserializeKey(
+        PortIdentityKeySerializer.portIdToString(portIdentity),
+        null
+      ) shouldBe portIdentity
+    }
+  }
+
+  it should "round-trip Map[PortIdentity, String] keys through 
JSONUtils.objectMapper" in {
+    val original = Map(
+      PortIdentity(0, internal = false) -> "zero-external",
+      PortIdentity(3, internal = true) -> "three-internal",
+      PortIdentity(999999, internal = false) -> "large-external",
+      PortIdentity(-1, internal = true) -> "negative-internal"
+    )
+    val json = objectMapper.writeValueAsString(original)
+    val mapType = objectMapper.getTypeFactory
+      .constructMapType(classOf[java.util.HashMap[_, _]], 
classOf[PortIdentity], classOf[String])
+
+    val restored: java.util.Map[PortIdentity, String] = 
objectMapper.readValue(json, mapType)
+
+    restored.asScala.toMap shouldBe original
+  }

Review Comment:
   Many behaviors asserted here (Jackson Map[PortIdentity, String] round-trip 
and the deserializer’s current malformed-key failure modes) are already covered 
in `PortIdentitySerdeSpec`. To avoid duplicated tests that must be updated in 
lockstep if the parser/contract changes, consider consolidating by removing the 
older coverage or limiting this spec to the additional cases it uniquely adds 
(e.g., empty-key behavior / expanded round-trip cases).



##########
common/workflow-core/src/test/scala/org/apache/texera/amber/util/serde/PortIdentityKeySerializerSpec.scala:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.util.serde
+
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class PortIdentityKeySerializerSpec extends AnyFlatSpec with Matchers {
+
+  "PortIdentityKeySerializer.portIdToString" should "format PortIdentity as 
id_internal" in {
+    PortIdentityKeySerializer
+      .portIdToString(PortIdentity(3, internal = false)) shouldBe "3_false"
+    PortIdentityKeySerializer
+      .portIdToString(PortIdentity(0, internal = true)) shouldBe "0_true"
+  }

Review Comment:
   This spec substantially overlaps with existing coverage in 
`PortIdentitySerdeSpec` (e.g., `PortIdentityKeySerializer.portIdToString` 
format and Jackson map-key serialization via `JSONUtils.objectMapper`). Having 
both sets of tests pins the same contract twice and increases maintenance cost; 
consider consolidating by either removing/moving the older tests or trimming 
this spec to only cover new edge cases not already asserted elsewhere.



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