Github user sryza commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6394#discussion_r33317386
  
    --- Diff: 
yarn/src/test/scala/org/apache/spark/deploy/yarn/ContainerPlacementStrategySuite.scala
 ---
    @@ -0,0 +1,147 @@
    +/*
    + * 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.spark.deploy.yarn
    +
    +import org.scalatest.{BeforeAndAfterEach, Matchers}
    +
    +import org.apache.spark.SparkFunSuite
    +
    +class ContainerPlacementStrategySuite extends SparkFunSuite with Matchers 
with BeforeAndAfterEach {
    +
    +  private val yarnAllocatorSuite = new YarnAllocatorSuite
    +  import yarnAllocatorSuite._
    +
    +  override def beforeEach() {
    +    yarnAllocatorSuite.beforeEach()
    +  }
    +
    +  override def afterEach() {
    +    yarnAllocatorSuite.afterEach()
    +  }
    +
    +  test("allocate locality preferred containers with enough resource and no 
matched existed " +
    +    "containers") {
    +    // 1. All the locations of current containers cannot satisfy the new 
requirements
    +    // 2. Current requested container number can fully satisfy the pending 
tasks.
    +
    +    val handler = createAllocator(2)
    +    handler.updateResourceRequests()
    +    handler.handleAllocatedContainers(Array(
    +      createContainer("host1"),
    +      createContainer("host2")))
    +
    +    val nodeLocalities =
    +      handler.containerPlacementStrategy.localityOfRequestedContainers(3, 
15,
    +        Map("host3" -> 15, "host4" -> 15, "host5" -> 10))
    +          .map(_.nodes)
    +
    +    assert(nodeLocalities === Array(
    +      Array("host3", "host4", "host5"),
    +      Array("host3", "host4", "host5"),
    +      Array("host3", "host4")))
    +  }
    +
    +  test("allocate locality preferred containers with enough resource and 
partially matched " +
    +    "containers") {
    +    // 1. Parts of current containers' locations can satisfy the new 
requirements
    +    // 2. Current requested container number can fully satisfy the pending 
tasks.
    +
    +    val handler = createAllocator(3)
    +    handler.updateResourceRequests()
    +    handler.handleAllocatedContainers(Array(
    +      createContainer("host1"),
    +      createContainer("host1"),
    +      createContainer("host2")
    +    ))
    +
    +    val nodeLocalities =
    +      handler.containerPlacementStrategy.localityOfRequestedContainers(3, 
15,
    +        Map("host1" -> 15, "host2" -> 15, "host3" -> 10))
    +          .map(_.nodes)
    +
    +    assert(nodeLocalities === Array(
    +      null, // requested requested container with no locality preference
    +      Array("host2", "host3"),
    +      Array("host2", "host3")))
    +  }
    +
    +  test("allocate locality preferred containers with limited resource and 
partially matched " +
    +    "containers") {
    +    // 1. Parts of current containers' locations can satisfy the new 
requirements
    +    // 2. Current requested container number cannot fully satisfy the 
pending tasks.
    +
    +    val handler = createAllocator(3)
    +    handler.updateResourceRequests()
    +    handler.handleAllocatedContainers(Array(
    +      createContainer("host1"),
    +      createContainer("host1"),
    +      createContainer("host2")
    +    ))
    +
    +    val nodeLocalities =
    +      handler.containerPlacementStrategy.localityOfRequestedContainers(1, 
15,
    +        Map("host1" -> 15, "host2" -> 15, "host3" -> 10))
    +          .map(_.nodes)
    +
    +    assert(nodeLocalities === Array(
    +      /** newly requested locality preferred containers */
    +      Array("host2", "host3")))
    +  }
    +
    +  test("allocate locality preferred containers with fully matched 
containers") {
    +    // Current containers' locations can fully satisfy the new requirements
    +
    +    val handler = createAllocator(5)
    +    handler.updateResourceRequests()
    +    handler.handleAllocatedContainers(Array(
    +      createContainer("host1"),
    +      createContainer("host1"),
    +      createContainer("host2"),
    +      createContainer("host2"),
    +      createContainer("host3")
    +    ))
    +
    +    val nodeLocalities =
    +      handler.containerPlacementStrategy.localityOfRequestedContainers(3, 
15,
    +        Map("host1" -> 15, "host2" -> 15, "host3" -> 10))
    +          .map(_.nodes)
    +
    +    assert(nodeLocalities === Array(
    +      /** newly requested locality preferred containers */
    +      null,
    +      null,
    +      null))
    +  }
    +
    +  test("allocate containers with no locality preference") {
    +    // Request new container without locality preference
    +
    +    val handler = createAllocator(2)
    +    handler.updateResourceRequests()
    +    handler.handleAllocatedContainers(Array(
    --- End diff --
    
    can go on one line


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to