Copilot commented on code in PR #4821: URL: https://github.com/apache/texera/pull/4821#discussion_r3177609900
########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/config/SchedulingConfigsSpec.scala: ########## @@ -0,0 +1,291 @@ +/* + * 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.scheduling.config + +import org.apache.texera.amber.config.ApplicationConfig +import org.apache.texera.amber.core.executor.OpExecInitInfo +import org.apache.texera.amber.core.virtualidentity.{ + ActorVirtualIdentity, + ChannelIdentity, + ExecutionIdentity, + OperatorIdentity, + PhysicalOpIdentity, + WorkflowIdentity +} +import org.apache.texera.amber.core.workflow._ +import org.apache.texera.amber.engine.architecture.sendsemantics.partitionings._ +import org.scalatest.flatspec.AnyFlatSpec + +import java.net.URI + +class SchedulingConfigsSpec extends AnyFlatSpec { + + private def actor(name: String): ActorVirtualIdentity = ActorVirtualIdentity(name) + private def chan(from: ActorVirtualIdentity, to: ActorVirtualIdentity): ChannelIdentity = + ChannelIdentity(from, to, isControl = false) + + // --------------------------------------------------------------------------- + // ChannelConfig.generateChannelConfigs + // --------------------------------------------------------------------------- + + "ChannelConfig.generateChannelConfigs" should "produce a full cross-product for HashPartition" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2"), actor("t3")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), HashPartition(List("k"))) + assert(configs.size == 6) + assert(configs.map(_.channelId).toSet == (for (f <- from; t <- to) yield chan(f, t)).toSet) + configs.foreach(c => assert(c.toPortId == PortIdentity(0))) + } + + it should "produce a full cross-product for RangePartition" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + val configs = ChannelConfig.generateChannelConfigs( + from, + to, + PortIdentity(1), + new RangePartition(List("k"), 0L, 10L) + ) + assert(configs.size == 2) + } + + it should "produce a full cross-product for BroadcastPartition" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), BroadcastPartition()) + assert(configs.size == 4) + } + + it should "produce a full cross-product for UnknownPartition" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), UnknownPartition()) + assert(configs.size == 2) + } + + it should "fan-in to a single receiver for SinglePartition" in { + val from = List(actor("f1"), actor("f2"), actor("f3")) + val to = List(actor("only-receiver")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), SinglePartition()) + assert(configs.size == 3) + assert(configs.forall(_.channelId.toWorkerId == actor("only-receiver"))) + } + + it should "fail the SinglePartition assertion when toWorkerIds has more than one entry" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + assertThrows[AssertionError] { + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), SinglePartition()) + } + } + + it should "zip from/to in OneToOnePartition" in { + val from = List(actor("f1"), actor("f2"), actor("f3")) + val to = List(actor("t1"), actor("t2"), actor("t3")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), OneToOnePartition()) + assert(configs.size == 3) + val pairs = configs.map(c => (c.channelId.fromWorkerId, c.channelId.toWorkerId)) + assert( + pairs == List( + (actor("f1"), actor("t1")), + (actor("f2"), actor("t2")), + (actor("f3"), actor("t3")) + ) + ) + } + + it should "produce empty list for unhandled partition cases" in { + // The catch-all `case _ => List()` is exercised by an InternalLink-style + // partition that the matcher does not enumerate. Constructing one via the + // sealed hierarchy isn't possible without adding a new subtype, so this + // case is covered indirectly by the matcher's exhaustiveness audit. + succeed Review Comment: The test case for the `case _ => List()` branch doesn’t actually exercise that code path (it only calls `succeed`). Since `ChannelConfig.generateChannelConfigs` has a real catch-all that returns an empty list, consider triggering it explicitly (e.g., pass `null.asInstanceOf[PartitionInfo]`) and assert the result is empty, so the branch is truly covered and the test will fail if the default behavior changes. ########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/config/SchedulingConfigsSpec.scala: ########## @@ -0,0 +1,291 @@ +/* + * 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.scheduling.config + +import org.apache.texera.amber.config.ApplicationConfig +import org.apache.texera.amber.core.executor.OpExecInitInfo +import org.apache.texera.amber.core.virtualidentity.{ + ActorVirtualIdentity, + ChannelIdentity, + ExecutionIdentity, + OperatorIdentity, + PhysicalOpIdentity, + WorkflowIdentity +} +import org.apache.texera.amber.core.workflow._ +import org.apache.texera.amber.engine.architecture.sendsemantics.partitionings._ +import org.scalatest.flatspec.AnyFlatSpec + +import java.net.URI + +class SchedulingConfigsSpec extends AnyFlatSpec { + + private def actor(name: String): ActorVirtualIdentity = ActorVirtualIdentity(name) + private def chan(from: ActorVirtualIdentity, to: ActorVirtualIdentity): ChannelIdentity = + ChannelIdentity(from, to, isControl = false) + + // --------------------------------------------------------------------------- + // ChannelConfig.generateChannelConfigs + // --------------------------------------------------------------------------- + + "ChannelConfig.generateChannelConfigs" should "produce a full cross-product for HashPartition" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2"), actor("t3")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), HashPartition(List("k"))) + assert(configs.size == 6) + assert(configs.map(_.channelId).toSet == (for (f <- from; t <- to) yield chan(f, t)).toSet) + configs.foreach(c => assert(c.toPortId == PortIdentity(0))) + } + + it should "produce a full cross-product for RangePartition" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + val configs = ChannelConfig.generateChannelConfigs( + from, + to, + PortIdentity(1), + new RangePartition(List("k"), 0L, 10L) + ) + assert(configs.size == 2) + } + + it should "produce a full cross-product for BroadcastPartition" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), BroadcastPartition()) + assert(configs.size == 4) + } + + it should "produce a full cross-product for UnknownPartition" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), UnknownPartition()) + assert(configs.size == 2) + } + + it should "fan-in to a single receiver for SinglePartition" in { + val from = List(actor("f1"), actor("f2"), actor("f3")) + val to = List(actor("only-receiver")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), SinglePartition()) + assert(configs.size == 3) + assert(configs.forall(_.channelId.toWorkerId == actor("only-receiver"))) + } + + it should "fail the SinglePartition assertion when toWorkerIds has more than one entry" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + assertThrows[AssertionError] { + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), SinglePartition()) + } + } + + it should "zip from/to in OneToOnePartition" in { + val from = List(actor("f1"), actor("f2"), actor("f3")) + val to = List(actor("t1"), actor("t2"), actor("t3")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), OneToOnePartition()) + assert(configs.size == 3) + val pairs = configs.map(c => (c.channelId.fromWorkerId, c.channelId.toWorkerId)) + assert( + pairs == List( + (actor("f1"), actor("t1")), + (actor("f2"), actor("t2")), + (actor("f3"), actor("t3")) + ) + ) + } + + it should "produce empty list for unhandled partition cases" in { + // The catch-all `case _ => List()` is exercised by an InternalLink-style + // partition that the matcher does not enumerate. Constructing one via the + // sealed hierarchy isn't possible without adding a new subtype, so this + // case is covered indirectly by the matcher's exhaustiveness audit. + succeed + } + + // --------------------------------------------------------------------------- + // LinkConfig.toPartitioning + // --------------------------------------------------------------------------- + + "LinkConfig.toPartitioning" should "map HashPartition to HashBasedShufflePartitioning carrying its hash attributes" in { + val from = List(actor("f")) + val to = List(actor("t1"), actor("t2")) + val partitioning = + LinkConfig.toPartitioning(from, to, HashPartition(List("a", "b")), dataTransferBatchSize = 50) + val hashed = partitioning.asInstanceOf[HashBasedShufflePartitioning] + assert(hashed.batchSize == 50) + assert(hashed.hashAttributeNames == List("a", "b")) + assert(hashed.channels.size == 2) + } + + it should "map RangePartition to RangeBasedShufflePartitioning carrying its range bounds" in { + val from = List(actor("f")) + val to = List(actor("t1")) + val partitioning = LinkConfig.toPartitioning( + from, + to, + new RangePartition(List("a"), 0L, 99L), + dataTransferBatchSize = 10 + ) + val ranged = partitioning.asInstanceOf[RangeBasedShufflePartitioning] + assert(ranged.rangeMin == 0L) + assert(ranged.rangeMax == 99L) + assert(ranged.rangeAttributeNames == List("a")) + } Review Comment: This test passes `dataTransferBatchSize = 10` but never asserts that the resulting `RangeBasedShufflePartitioning` actually carries that batch size (only hash partition test checks batch size). If the goal is to cover parameter propagation, add an assertion on `ranged.batchSize` here (and similarly for other partitioning types where meaningful). ########## amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/config/SchedulingConfigsSpec.scala: ########## @@ -0,0 +1,291 @@ +/* + * 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.scheduling.config + +import org.apache.texera.amber.config.ApplicationConfig +import org.apache.texera.amber.core.executor.OpExecInitInfo +import org.apache.texera.amber.core.virtualidentity.{ + ActorVirtualIdentity, + ChannelIdentity, + ExecutionIdentity, + OperatorIdentity, + PhysicalOpIdentity, + WorkflowIdentity +} +import org.apache.texera.amber.core.workflow._ +import org.apache.texera.amber.engine.architecture.sendsemantics.partitionings._ +import org.scalatest.flatspec.AnyFlatSpec + +import java.net.URI + +class SchedulingConfigsSpec extends AnyFlatSpec { + + private def actor(name: String): ActorVirtualIdentity = ActorVirtualIdentity(name) + private def chan(from: ActorVirtualIdentity, to: ActorVirtualIdentity): ChannelIdentity = + ChannelIdentity(from, to, isControl = false) + + // --------------------------------------------------------------------------- + // ChannelConfig.generateChannelConfigs + // --------------------------------------------------------------------------- + + "ChannelConfig.generateChannelConfigs" should "produce a full cross-product for HashPartition" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2"), actor("t3")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), HashPartition(List("k"))) + assert(configs.size == 6) + assert(configs.map(_.channelId).toSet == (for (f <- from; t <- to) yield chan(f, t)).toSet) + configs.foreach(c => assert(c.toPortId == PortIdentity(0))) + } + + it should "produce a full cross-product for RangePartition" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + val configs = ChannelConfig.generateChannelConfigs( + from, + to, + PortIdentity(1), + new RangePartition(List("k"), 0L, 10L) + ) + assert(configs.size == 2) + } + + it should "produce a full cross-product for BroadcastPartition" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), BroadcastPartition()) + assert(configs.size == 4) + } + + it should "produce a full cross-product for UnknownPartition" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), UnknownPartition()) + assert(configs.size == 2) + } + + it should "fan-in to a single receiver for SinglePartition" in { + val from = List(actor("f1"), actor("f2"), actor("f3")) + val to = List(actor("only-receiver")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), SinglePartition()) + assert(configs.size == 3) + assert(configs.forall(_.channelId.toWorkerId == actor("only-receiver"))) + } + + it should "fail the SinglePartition assertion when toWorkerIds has more than one entry" in { + val from = List(actor("f1")) + val to = List(actor("t1"), actor("t2")) + assertThrows[AssertionError] { + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), SinglePartition()) + } + } + + it should "zip from/to in OneToOnePartition" in { + val from = List(actor("f1"), actor("f2"), actor("f3")) + val to = List(actor("t1"), actor("t2"), actor("t3")) + val configs = + ChannelConfig.generateChannelConfigs(from, to, PortIdentity(0), OneToOnePartition()) + assert(configs.size == 3) + val pairs = configs.map(c => (c.channelId.fromWorkerId, c.channelId.toWorkerId)) + assert( + pairs == List( + (actor("f1"), actor("t1")), + (actor("f2"), actor("t2")), + (actor("f3"), actor("t3")) + ) + ) + } + + it should "produce empty list for unhandled partition cases" in { + // The catch-all `case _ => List()` is exercised by an InternalLink-style + // partition that the matcher does not enumerate. Constructing one via the + // sealed hierarchy isn't possible without adding a new subtype, so this + // case is covered indirectly by the matcher's exhaustiveness audit. + succeed + } + + // --------------------------------------------------------------------------- + // LinkConfig.toPartitioning + // --------------------------------------------------------------------------- + + "LinkConfig.toPartitioning" should "map HashPartition to HashBasedShufflePartitioning carrying its hash attributes" in { + val from = List(actor("f")) + val to = List(actor("t1"), actor("t2")) + val partitioning = + LinkConfig.toPartitioning(from, to, HashPartition(List("a", "b")), dataTransferBatchSize = 50) + val hashed = partitioning.asInstanceOf[HashBasedShufflePartitioning] + assert(hashed.batchSize == 50) + assert(hashed.hashAttributeNames == List("a", "b")) + assert(hashed.channels.size == 2) + } + + it should "map RangePartition to RangeBasedShufflePartitioning carrying its range bounds" in { + val from = List(actor("f")) + val to = List(actor("t1")) + val partitioning = LinkConfig.toPartitioning( + from, + to, + new RangePartition(List("a"), 0L, 99L), + dataTransferBatchSize = 10 + ) + val ranged = partitioning.asInstanceOf[RangeBasedShufflePartitioning] + assert(ranged.rangeMin == 0L) + assert(ranged.rangeMax == 99L) + assert(ranged.rangeAttributeNames == List("a")) + } + + it should "map SinglePartition to OneToOnePartitioning fanned in to the single receiver" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("only")) + val partitioning = + LinkConfig.toPartitioning(from, to, SinglePartition(), dataTransferBatchSize = 1) + val one = partitioning.asInstanceOf[OneToOnePartitioning] + assert(one.channels.forall(_.toWorkerId == actor("only"))) + assert(one.channels.size == 2) + } + + it should "fail the SinglePartition assertion when toWorkerIds has more than one entry" in { + val from = List(actor("f")) + val to = List(actor("t1"), actor("t2")) + assertThrows[AssertionError] { + LinkConfig.toPartitioning(from, to, SinglePartition(), dataTransferBatchSize = 1) + } + } + + it should "map OneToOnePartition to OneToOnePartitioning over zipped pairs" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2")) + val partitioning = + LinkConfig.toPartitioning(from, to, OneToOnePartition(), dataTransferBatchSize = 1) + val one = partitioning.asInstanceOf[OneToOnePartitioning] + assert(one.channels.size == 2) + assert(one.channels.head == chan(actor("f1"), actor("t1"))) + } + + it should "map BroadcastPartition to BroadcastPartitioning over zipped pairs" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2")) + val partitioning = + LinkConfig.toPartitioning(from, to, BroadcastPartition(), dataTransferBatchSize = 1) + assert(partitioning.isInstanceOf[BroadcastPartitioning]) + } + + it should "map UnknownPartition to RoundRobinPartitioning across the cross-product" in { + val from = List(actor("f1"), actor("f2")) + val to = List(actor("t1"), actor("t2")) + val partitioning = + LinkConfig.toPartitioning(from, to, UnknownPartition(), dataTransferBatchSize = 1) + val rr = partitioning.asInstanceOf[RoundRobinPartitioning] + assert(rr.channels.size == 4) + } + Review Comment: `LinkConfig.toPartitioning` has a default `case _ => throw new UnsupportedOperationException()` branch, but the spec doesn’t currently assert that behavior. To fully cover all match branches (as described in the PR), add a test that passes an unhandled `PartitionInfo` value (commonly `null.asInstanceOf[PartitionInfo]` for sealed hierarchies) and assert it throws `UnsupportedOperationException`. -- 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]
