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


##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/resourcePolicies/ResourcePoliciesSpec.scala:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.resourcePolicies
+
+import org.apache.texera.amber.core.workflow.{PortIdentity, WorkflowContext}
+import org.apache.texera.amber.engine.architecture.scheduling.{Region, 
RegionIdentity}
+import org.apache.texera.amber.engine.e2e.TestUtils.buildWorkflow
+import org.apache.texera.amber.operator.TestOperators
+import org.apache.texera.workflow.LogicalLink
+import org.scalatest.flatspec.AnyFlatSpec
+
+class ResourcePoliciesSpec extends AnyFlatSpec {
+
+  // 
---------------------------------------------------------------------------
+  // ExecutionClusterInfo
+  // 
---------------------------------------------------------------------------
+
+  "ExecutionClusterInfo" should "construct without arguments" in {
+    val info = new ExecutionClusterInfo()
+    assert(info != null)
+  }
+
+  // 
---------------------------------------------------------------------------
+  // DefaultResourceAllocator (helpers + tests)
+  // 
---------------------------------------------------------------------------
+
+  /** Build a small linear `csv -> keyword` workflow to feed the allocator. */
+  private def buildLinearWorkflow() = {
+    val csv = TestOperators.headerlessSmallCsvScanOpDesc()
+    val keyword = TestOperators.keywordSearchOpDesc("column-1", "Asia")
+    buildWorkflow(
+      List(csv, keyword),
+      List(
+        LogicalLink(
+          csv.operatorIdentifier,
+          PortIdentity(0),
+          keyword.operatorIdentifier,
+          PortIdentity(0)
+        )
+      ),
+      new WorkflowContext()
+    )
+  }
+
+  private def newAllocator(): (DefaultResourceAllocator, Region) = {
+    val workflow = buildLinearWorkflow()
+    val allocator = new DefaultResourceAllocator(
+      workflow.physicalPlan,
+      new ExecutionClusterInfo(),
+      workflow.context.workflowSettings
+    )
+    val region = Region(
+      id = RegionIdentity(0),
+      physicalOps = workflow.physicalPlan.operators,
+      physicalLinks = workflow.physicalPlan.links
+    )
+    (allocator, region)
+  }
+
+  "DefaultResourceAllocator.allocate" should "return zero cost (placeholder)" 
in {
+    val (allocator, region) = newAllocator()
+    val (_, cost) = allocator.allocate(region)
+    assert(cost == 0d)
+  }
+
+  it should "produce an OperatorConfig entry for every operator in the region" 
in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    val opIds = region.getOperators.map(_.id)
+    assert(resourceConfig.operatorConfigs.keySet == opIds)
+  }
+
+  it should "respect parallelizable / suggested-worker settings on each 
PhysicalOp" in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    region.getOperators.foreach { op =>
+      val workers = resourceConfig.operatorConfigs(op.id).workerConfigs.size
+      val expected =
+        if (!op.parallelizable) 1
+        else
+          op.suggestedWorkerNum.getOrElse(
+            
org.apache.texera.amber.config.ApplicationConfig.numWorkerPerOperatorByDefault
+          )
+      assert(workers == expected, s"unexpected worker count for ${op.id}")
+    }
+  }
+
+  it should "emit distinct worker ids per operator" in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    val ids = 
resourceConfig.operatorConfigs.values.flatMap(_.workerConfigs.map(_.workerId)).toList
+    assert(ids.distinct.size == ids.size, s"duplicate worker ids in $ids")
+  }
+
+  it should "produce a LinkConfig entry for every physical link in the region" 
in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    assert(resourceConfig.linkConfigs.keySet == region.getLinks)
+  }
+
+  it should "wire each LinkConfig with a non-empty channel layout and a 
Partitioning" in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    resourceConfig.linkConfigs.values.foreach { link =>
+      assert(link.channelConfigs.nonEmpty)
+      assert(link.partitioning != null)

Review Comment:
   `link.partitioning` is a non-nullable `Partitioning` value in `LinkConfig`, 
so `assert(link.partitioning != null)` is effectively redundant unless the 
production code is explicitly constructing LinkConfig with null. If the intent 
is to validate correctness, consider asserting something stronger (e.g., 
expected partitioning type or that its channels align with channelConfigs).
   



##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/resourcePolicies/ResourcePoliciesSpec.scala:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.resourcePolicies
+
+import org.apache.texera.amber.core.workflow.{PortIdentity, WorkflowContext}
+import org.apache.texera.amber.engine.architecture.scheduling.{Region, 
RegionIdentity}
+import org.apache.texera.amber.engine.e2e.TestUtils.buildWorkflow
+import org.apache.texera.amber.operator.TestOperators
+import org.apache.texera.workflow.LogicalLink
+import org.scalatest.flatspec.AnyFlatSpec
+
+class ResourcePoliciesSpec extends AnyFlatSpec {
+
+  // 
---------------------------------------------------------------------------
+  // ExecutionClusterInfo
+  // 
---------------------------------------------------------------------------
+
+  "ExecutionClusterInfo" should "construct without arguments" in {
+    val info = new ExecutionClusterInfo()
+    assert(info != null)
+  }
+
+  // 
---------------------------------------------------------------------------
+  // DefaultResourceAllocator (helpers + tests)
+  // 
---------------------------------------------------------------------------
+
+  /** Build a small linear `csv -> keyword` workflow to feed the allocator. */
+  private def buildLinearWorkflow() = {
+    val csv = TestOperators.headerlessSmallCsvScanOpDesc()
+    val keyword = TestOperators.keywordSearchOpDesc("column-1", "Asia")
+    buildWorkflow(
+      List(csv, keyword),
+      List(
+        LogicalLink(
+          csv.operatorIdentifier,
+          PortIdentity(0),
+          keyword.operatorIdentifier,
+          PortIdentity(0)
+        )
+      ),
+      new WorkflowContext()
+    )
+  }
+
+  private def newAllocator(): (DefaultResourceAllocator, Region) = {
+    val workflow = buildLinearWorkflow()
+    val allocator = new DefaultResourceAllocator(
+      workflow.physicalPlan,
+      new ExecutionClusterInfo(),
+      workflow.context.workflowSettings
+    )
+    val region = Region(
+      id = RegionIdentity(0),
+      physicalOps = workflow.physicalPlan.operators,
+      physicalLinks = workflow.physicalPlan.links
+    )
+    (allocator, region)
+  }
+
+  "DefaultResourceAllocator.allocate" should "return zero cost (placeholder)" 
in {
+    val (allocator, region) = newAllocator()
+    val (_, cost) = allocator.allocate(region)
+    assert(cost == 0d)
+  }
+
+  it should "produce an OperatorConfig entry for every operator in the region" 
in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    val opIds = region.getOperators.map(_.id)
+    assert(resourceConfig.operatorConfigs.keySet == opIds)
+  }
+
+  it should "respect parallelizable / suggested-worker settings on each 
PhysicalOp" in {
+    val (allocator, region) = newAllocator()
+    val (resourceConfig, _) = allocator.allocate(region)
+    region.getOperators.foreach { op =>
+      val workers = resourceConfig.operatorConfigs(op.id).workerConfigs.size
+      val expected =
+        if (!op.parallelizable) 1
+        else
+          op.suggestedWorkerNum.getOrElse(
+            
org.apache.texera.amber.config.ApplicationConfig.numWorkerPerOperatorByDefault
+          )
+      assert(workers == expected, s"unexpected worker count for ${op.id}")
+    }
+  }

Review Comment:
   The "respect parallelizable / suggested-worker" test setup only includes 
CSVScanSource (non-parallelizable) and KeywordSearch (parallelizable but does 
not set suggestedWorkerNum), so it never exercises the 
suggestedWorkerNum=Some(n) branch in WorkerConfig.generateWorkerConfigs. Add a 
PhysicalOp with suggestedWorkerNum set (e.g., a PythonUDF op with workers > 1, 
or copy one compiled PhysicalOp with .withSuggestedWorkerNum(n)) and assert the 
allocator uses that exact worker count.



##########
amber/src/test/scala/org/apache/texera/amber/engine/architecture/scheduling/resourcePolicies/ResourcePoliciesSpec.scala:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.resourcePolicies
+
+import org.apache.texera.amber.core.workflow.{PortIdentity, WorkflowContext}
+import org.apache.texera.amber.engine.architecture.scheduling.{Region, 
RegionIdentity}
+import org.apache.texera.amber.engine.e2e.TestUtils.buildWorkflow
+import org.apache.texera.amber.operator.TestOperators
+import org.apache.texera.workflow.LogicalLink
+import org.scalatest.flatspec.AnyFlatSpec
+
+class ResourcePoliciesSpec extends AnyFlatSpec {
+
+  // 
---------------------------------------------------------------------------
+  // ExecutionClusterInfo
+  // 
---------------------------------------------------------------------------
+
+  "ExecutionClusterInfo" should "construct without arguments" in {
+    val info = new ExecutionClusterInfo()
+    assert(info != null)

Review Comment:
   `assert(info != null)` doesn't add meaningful coverage in Scala (if `new 
ExecutionClusterInfo()` returns, it's already non-null). Consider asserting 
some observable property/state (if added later) or simply verifying 
construction doesn't throw, to keep the test signal high.
   



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