aglinxinyuan commented on code in PR #4824: URL: https://github.com/apache/texera/pull/4824#discussion_r3177865477
########## 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: Done in b3483610fc — replaced `assert(link.partitioning != null)` with a real check that `link.partitioning.channels` equals `link.channelConfigs.map(_.channelId)`, so any drift between the two would actually fail. ########## 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: Done in b3483610fc — added a dedicated test that copies the parallelizable op with `withSuggestedWorkerNum(7)` and asserts the allocator emits exactly 7 worker configs for it, exercising the `suggestedWorkerNum = Some(n)` branch. -- 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]
