Skip to content

Commit

Permalink
[SPARK-29725][SQL][TESTS] Add ThriftServerPageSuite
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Added UT for the classes `ThriftServerPage.scala` and `ThriftServerSessionPage.scala`

### Why are the changes needed?

Currently, there are no UTs for testing Thriftserver UI page
### Does this PR introduce any user-facing change?

No

### How was this patch tested?

UT

Closes apache#26403 from shahidki31/ut.

Authored-by: shahid <[email protected]>
Signed-off-by: HyukjinKwon <[email protected]>
  • Loading branch information
shahidki31 authored and HyukjinKwon committed Nov 6, 2019
1 parent 5853e8b commit 90df858
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sql/hive-thriftserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.jpam</groupId>
<artifactId>jpam</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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.sql.hive.thriftserver.ui

import java.util.Locale
import javax.servlet.http.HttpServletRequest

import org.mockito.Mockito.{mock, when, RETURNS_SMART_NULLS}

import org.apache.spark.SparkFunSuite
import org.apache.spark.scheduler.SparkListenerJobStart
import org.apache.spark.sql.hive.thriftserver.HiveThriftServer2
import org.apache.spark.sql.hive.thriftserver.HiveThriftServer2.HiveThriftServer2Listener
import org.apache.spark.sql.internal.SQLConf

class ThriftServerPageSuite extends SparkFunSuite {

/**
* Run a dummy session and return the listener
*/
private def getListener: HiveThriftServer2Listener = {
val listener = new HiveThriftServer2Listener(mock(classOf[HiveThriftServer2]), new SQLConf)

listener.onSessionCreated("localhost", "sessionid", "user")
listener.onStatementStart("id", "sessionid", "dummy query", "groupid", "user")
listener.onStatementParsed("id", "dummy plan")
listener.onJobStart(SparkListenerJobStart(0, System.currentTimeMillis(), Seq()))
listener.onStatementFinish("id")
listener.onOperationClosed("id")
listener.onSessionClosed("sessionid")
listener
}

test("thriftserver page should load successfully") {
val request = mock(classOf[HttpServletRequest])
val tab = mock(classOf[ThriftServerTab], RETURNS_SMART_NULLS)
when(tab.listener).thenReturn(getListener)
when(tab.appName).thenReturn("testing")
when(tab.headerTabs).thenReturn(Seq.empty)
val page = new ThriftServerPage(tab)
val html = page.render(request).toString().toLowerCase(Locale.ROOT)

// session statistics and sql statistics tables should load successfully
assert(html.contains("session statistics (1)"))
assert(html.contains("sql statistics (1)"))
assert(html.contains("dummy query"))
assert(html.contains("dummy plan"))

// Pagination support
assert(html.contains("<label>1 pages. jump to</label>"))

// Hiding table support
assert(html.contains("class=\"collapse-aggregated-sessionstat" +
" collapse-table\" onclick=\"collapsetable"))
}

test("thriftserver session page should load successfully") {
val request = mock(classOf[HttpServletRequest])
when(request.getParameter("id")).thenReturn("sessionid")
val tab = mock(classOf[ThriftServerTab], RETURNS_SMART_NULLS)
when(tab.listener).thenReturn(getListener)
when(tab.appName).thenReturn("testing")
when(tab.headerTabs).thenReturn(Seq.empty)
val page = new ThriftServerSessionPage(tab)
val html = page.render(request).toString().toLowerCase(Locale.ROOT)

// session sql statistics table should load successfully
assert(html.contains("sql statistics"))
assert(html.contains("user"))
assert(html.contains("groupid"))

// Pagination support
assert(html.contains("<label>1 pages. jump to</label>"))

// Hiding table support
assert(html.contains("collapse-aggregated-sqlsessionstat collapse-table\"" +
" onclick=\"collapsetable"))
}
}

0 comments on commit 90df858

Please sign in to comment.