|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.spark.deploy.rest.mesos |
| 19 | + |
| 20 | +import javax.servlet.http.HttpServletResponse |
| 21 | + |
| 22 | +import org.scalatest.mockito.MockitoSugar |
| 23 | + |
| 24 | +import org.apache.spark.{SparkConf, SparkFunSuite} |
| 25 | +import org.apache.spark.deploy.TestPrematureExit |
| 26 | +import org.apache.spark.deploy.mesos.MesosDriverDescription |
| 27 | +import org.apache.spark.deploy.rest.{CreateSubmissionRequest, CreateSubmissionResponse, SubmitRestProtocolMessage, SubmitRestProtocolResponse} |
| 28 | +import org.apache.spark.internal.config |
| 29 | +import org.apache.spark.scheduler.cluster.mesos.{MesosClusterPersistenceEngineFactory, MesosClusterScheduler} |
| 30 | + |
| 31 | +class MesosRestServerSuite extends SparkFunSuite |
| 32 | + with TestPrematureExit with MockitoSugar { |
| 33 | + |
| 34 | + test("test default driver overhead memory") { |
| 35 | + testOverheadMemory(new SparkConf(), "2000M", 2384) |
| 36 | + } |
| 37 | + |
| 38 | + test("test driver overhead memory with overhead factor") { |
| 39 | + testOverheadMemory(new SparkConf(), "5000M", 5500) |
| 40 | + } |
| 41 | + |
| 42 | + test("test configured driver overhead memory") { |
| 43 | + val conf = new SparkConf() |
| 44 | + conf.set(config.DRIVER_MEMORY_OVERHEAD.key, "1000") |
| 45 | + testOverheadMemory(conf, "2000M", 3000) |
| 46 | + } |
| 47 | + |
| 48 | + def testOverheadMemory(conf: SparkConf, driverMemory: String, expectedResult: Int) { |
| 49 | + conf.set("spark.master", "testmaster") |
| 50 | + conf.set("spark.app.name", "testapp") |
| 51 | + conf.set(config.DRIVER_MEMORY.key, driverMemory) |
| 52 | + var actualMem = 0 |
| 53 | + class TestMesosClusterScheduler extends MesosClusterScheduler( |
| 54 | + mock[MesosClusterPersistenceEngineFactory], conf) { |
| 55 | + override def submitDriver(desc: MesosDriverDescription): CreateSubmissionResponse = { |
| 56 | + actualMem = desc.mem |
| 57 | + mock[CreateSubmissionResponse] |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + class TestServlet extends MesosSubmitRequestServlet(new TestMesosClusterScheduler, conf) { |
| 62 | + override def handleSubmit( |
| 63 | + requestMessageJson: String, |
| 64 | + requestMessage: SubmitRestProtocolMessage, |
| 65 | + responseServlet: HttpServletResponse): SubmitRestProtocolResponse = { |
| 66 | + super.handleSubmit(requestMessageJson, requestMessage, responseServlet) |
| 67 | + } |
| 68 | + |
| 69 | + override def findUnknownFields( |
| 70 | + requestJson: String, |
| 71 | + requestMessage: SubmitRestProtocolMessage): Array[String] = { |
| 72 | + Array() |
| 73 | + } |
| 74 | + } |
| 75 | + val servlet = new TestServlet() |
| 76 | + val request = new CreateSubmissionRequest() |
| 77 | + request.appResource = "testresource" |
| 78 | + request.mainClass = "mainClass" |
| 79 | + request.appArgs = Array("appArgs") |
| 80 | + request.environmentVariables = Map("envVar" -> "envVal") |
| 81 | + request.sparkProperties = conf.getAll.toMap |
| 82 | + servlet.handleSubmit("null", request, null) |
| 83 | + assert(actualMem == expectedResult) |
| 84 | + } |
| 85 | +} |
0 commit comments