forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-29725][SQL][TESTS] Add ThriftServerPageSuite
### 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
1 parent
5853e8b
commit 90df858
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...rver/src/test/scala/org/apache/spark/sql/hive/thriftserver/ui/ThriftServerPageSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} | ||
} | ||
|