|
| 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.master.ui |
| 19 | + |
| 20 | +import java.util.Date |
| 21 | +import javax.servlet.http.HttpServletRequest |
| 22 | + |
| 23 | +import org.mockito.Mockito.{mock, when} |
| 24 | + |
| 25 | +import org.apache.spark.SparkFunSuite |
| 26 | +import org.apache.spark.deploy.ApplicationDescription |
| 27 | +import org.apache.spark.deploy.DeployMessages.{MasterStateResponse, RequestMasterState} |
| 28 | +import org.apache.spark.deploy.master.{ApplicationInfo, ApplicationState, Master} |
| 29 | +import org.apache.spark.resource.ResourceProfile |
| 30 | +import org.apache.spark.rpc.RpcEndpointRef |
| 31 | + |
| 32 | +class ApplicationPageSuite extends SparkFunSuite { |
| 33 | + |
| 34 | + private val master = mock(classOf[Master]) |
| 35 | + when(master.historyServerUrl).thenReturn(Some("http://my-history-server:18080")) |
| 36 | + |
| 37 | + private val rp = new ResourceProfile(Map.empty, Map.empty) |
| 38 | + private val desc = ApplicationDescription("name", Some(4), null, "appUiUrl", rp) |
| 39 | + private val appFinished = new ApplicationInfo(0, "app-finished", desc, new Date, null, 1) |
| 40 | + appFinished.markFinished(ApplicationState.FINISHED) |
| 41 | + private val appLive = new ApplicationInfo(0, "app-live", desc, new Date, null, 1) |
| 42 | + |
| 43 | + private val state = mock(classOf[MasterStateResponse]) |
| 44 | + when(state.completedApps).thenReturn(Array(appFinished)) |
| 45 | + when(state.activeApps).thenReturn(Array(appLive)) |
| 46 | + |
| 47 | + private val rpc = mock(classOf[RpcEndpointRef]) |
| 48 | + when(rpc.askSync[MasterStateResponse](RequestMasterState)).thenReturn(state) |
| 49 | + |
| 50 | + private val masterWebUI = mock(classOf[MasterWebUI]) |
| 51 | + when(masterWebUI.master).thenReturn(master) |
| 52 | + when(masterWebUI.masterEndpointRef).thenReturn(rpc) |
| 53 | + |
| 54 | + test("SPARK-45774: Application Detail UI") { |
| 55 | + val request = mock(classOf[HttpServletRequest]) |
| 56 | + when(request.getParameter("appId")).thenReturn("app-live") |
| 57 | + |
| 58 | + val result = new ApplicationPage(masterWebUI).render(request).toString() |
| 59 | + assert(result.contains("Application Detail UI")) |
| 60 | + assert(!result.contains("Application History UI")) |
| 61 | + assert(!result.contains(master.historyServerUrl.get)) |
| 62 | + } |
| 63 | + |
| 64 | + test("SPARK-45774: Application History UI") { |
| 65 | + val request = mock(classOf[HttpServletRequest]) |
| 66 | + when(request.getParameter("appId")).thenReturn("app-finished") |
| 67 | + |
| 68 | + val result = new ApplicationPage(masterWebUI).render(request).toString() |
| 69 | + assert(!result.contains("Application Detail UI")) |
| 70 | + assert(result.contains("Application History UI")) |
| 71 | + assert(result.contains(master.historyServerUrl.get)) |
| 72 | + } |
| 73 | +} |
0 commit comments