tanishqgandhi1908 commented on code in PR #5799: URL: https://github.com/apache/texera/pull/5799#discussion_r3445481337
########## 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: Resolved. Deleted the overlapping PortIdentitySerdeSpec and moved its two genuinely-unique cases here, the empty Map[PortIdentity, String] round-trip and the pendingUntilFixed "eventually reject extra trailing segments". No coverage lost; this is now the single source of truth for the deserializer side. -- 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]
