add ut
This commit is contained in:
parent
24a7381c7f
commit
5345687d23
@ -6,7 +6,7 @@
|
||||
* (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
|
||||
* 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,
|
||||
@ -23,7 +23,7 @@ class ExecutionInfo(
|
||||
val statement: String,
|
||||
val sessionId: String,
|
||||
val startTimestamp: Long,
|
||||
val userName: User) {
|
||||
val userName: String) {
|
||||
var finishTimestamp: Long = 0L
|
||||
var executePlan: String = ""
|
||||
var detail: String = ""
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
* (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
|
||||
* 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,
|
||||
@ -25,23 +25,23 @@ import org.apache.spark.ui.KyuubiServerTab
|
||||
|
||||
object KyuubiServerMonitor {
|
||||
|
||||
private[this] val uiTabs = new HashMap[User, KyuubiServerTab]()
|
||||
private[this] val uiTabs = new HashMap[String, KyuubiServerTab]()
|
||||
|
||||
private[this] val listeners = new HashMap[User, KyuubiServerListener]()
|
||||
private[this] val listeners = new HashMap[String, KyuubiServerListener]()
|
||||
|
||||
def setListener(user: User, sparkListener: KyuubiServerListener): Unit = {
|
||||
def setListener(user: String, sparkListener: KyuubiServerListener): Unit = {
|
||||
listeners.put(user, sparkListener)
|
||||
}
|
||||
|
||||
def getListener(user: User): Option[KyuubiServerListener] = {
|
||||
def getListener(user: String): Option[KyuubiServerListener] = {
|
||||
listeners.get(user)
|
||||
}
|
||||
|
||||
def addUITab(user: User, ui: KyuubiServerTab): Unit = {
|
||||
def addUITab(user: String, ui: KyuubiServerTab): Unit = {
|
||||
uiTabs.put(user, ui)
|
||||
}
|
||||
|
||||
def detachUITab(user: User): Unit = {
|
||||
def detachUITab(user: String): Unit = {
|
||||
listeners.remove(user)
|
||||
uiTabs.get(user).foreach(_.detach())
|
||||
}
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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 yaooqinn.kyuubi
|
||||
|
||||
package object ui {
|
||||
|
||||
type User = String
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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 yaooqinn.kyuubi.ui
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import org.apache.spark.{KyuubiSparkUtil, SparkFunSuite}
|
||||
|
||||
class ExecutionInfoSuite extends SparkFunSuite {
|
||||
|
||||
test("execution info") {
|
||||
val statement = "show tables"
|
||||
val sessionId = UUID.randomUUID().toString
|
||||
val startTimeStamp = System.currentTimeMillis() - 1000L
|
||||
val user = KyuubiSparkUtil.getCurrentUserName()
|
||||
val info = new ExecutionInfo(statement, sessionId, startTimeStamp, user)
|
||||
assert(info.finishTimestamp === 0L)
|
||||
assert(info.executePlan === "")
|
||||
assert(info.detail === "")
|
||||
assert(info.state === ExecutionState.STARTED)
|
||||
assert(info.groupId === "")
|
||||
assert(info.jobId.isEmpty)
|
||||
assert(info.totalTime !== info.finishTimestamp - startTimeStamp)
|
||||
info.finishTimestamp = System.currentTimeMillis()
|
||||
assert(info.totalTime === info.finishTimestamp - startTimeStamp)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 yaooqinn.kyuubi.ui
|
||||
|
||||
import org.apache.spark.{KyuubiSparkUtil, SparkConf, SparkContext, SparkFunSuite}
|
||||
import org.apache.spark.ui.KyuubiServerTab
|
||||
|
||||
class KyuubiServerMonitorSuite extends SparkFunSuite {
|
||||
val conf = new SparkConf(loadDefaults = true).setAppName("monitor").setMaster("local")
|
||||
|
||||
var sc: SparkContext = _
|
||||
|
||||
override protected def beforeAll(): Unit = {
|
||||
sc = new SparkContext(conf)
|
||||
}
|
||||
|
||||
protected override def afterAll(): Unit = {
|
||||
if (sc != null) {
|
||||
sc.stop()
|
||||
}
|
||||
}
|
||||
|
||||
test("kyuubi server monitor") {
|
||||
val li = new KyuubiServerListener(conf)
|
||||
val user = KyuubiSparkUtil.getCurrentUserName()
|
||||
KyuubiServerMonitor.setListener(user, li)
|
||||
val liOp = KyuubiServerMonitor.getListener(user)
|
||||
assert(liOp.get === li)
|
||||
assert(KyuubiServerMonitor.getListener("fake").isEmpty)
|
||||
val tab = new KyuubiServerTab(user, sc)
|
||||
KyuubiServerMonitor.addUITab(user, tab)
|
||||
KyuubiServerMonitor.detachUITab(user)
|
||||
KyuubiServerMonitor.detachAllUITabs()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user