Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #5380][UT] Create PySpark batch jobs tests for RESTful API #5498

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.engine.spark.SparkProcessBuilder

trait BatchTestHelper {
val sparkBatchTestBatchType = "SPARK"

val sparkBatchTestMainClass = "org.apache.spark.examples.SparkPi"

val sparkBatchTestAppName = "Spark Pi" // the app name is hard coded in spark example code
Expand Down Expand Up @@ -56,7 +58,7 @@ trait BatchTestHelper {
conf: Map[String, String] = Map.empty,
args: Seq[String] = Seq.empty): BatchRequest = {
newBatchRequest(
"SPARK",
sparkBatchTestBatchType,
sparkBatchTestResource.get,
sparkBatchTestMainClass,
sparkBatchTestAppName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.kyuubi.server.rest.client

import java.nio.file.Paths

import org.apache.kyuubi.{BatchTestHelper, RestClientTestHelper}
import org.apache.kyuubi.client.{BatchRestApi, KyuubiRestClient}
import org.apache.kyuubi.client.api.v1.dto.Batch
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.engine.spark.SparkProcessBuilder

class PySparkBatchRestApiSuite extends RestClientTestHelper with BatchTestHelper {
override val sparkBatchTestBatchType: String = "PYSPARK"
override val sparkBatchTestMainClass: String = null // For PySpark, mainClass isn't needed.
override val sparkBatchTestAppName: String = "PythonPi"
override val sparkBatchTestResource: Option[String] = {
val sparkProcessBuilder = new SparkProcessBuilder("kyuubi", KyuubiConf())
val piScript =
Paths.get(sparkProcessBuilder.sparkHome, "examples/src/main/python/pi.py")
Some(piScript.toAbsolutePath.toString)
}

test("pyspark submit - basic batch rest client with existing resource file") {
val basicKyuubiRestClient: KyuubiRestClient =
KyuubiRestClient.builder(baseUri.toString)
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.BASIC)
.username(ldapUser)
.password(ldapUserPasswd)
.socketTimeout(30000)
.build()
val batchRestApi: BatchRestApi = new BatchRestApi(basicKyuubiRestClient)

val requestObj = newSparkBatchRequest(
conf = Map("spark.master" -> "local"),
args = Seq("10"))
val batch: Batch = batchRestApi.createBatch(requestObj)

assert(batch.getKyuubiInstance === fe.connectionUrl)
assert(batch.getBatchType === "PYSPARK")
basicKyuubiRestClient.close()
}

test("pyspark submit - basic batch rest client with uploading resource file") {
val basicKyuubiRestClient: KyuubiRestClient =
KyuubiRestClient.builder(baseUri.toString)
.authHeaderMethod(KyuubiRestClient.AuthHeaderMethod.BASIC)
.username(ldapUser)
.password(ldapUserPasswd)
.socketTimeout(30000)
.build()
val batchRestApi: BatchRestApi = new BatchRestApi(basicKyuubiRestClient)

val requestObj = newSparkBatchRequest(
conf = Map("spark.master" -> "local"),
args = Seq("10"))
val resourceFile = Paths.get(sparkBatchTestResource.get).toFile
val batch: Batch = batchRestApi.createBatch(requestObj, resourceFile)

assert(batch.getKyuubiInstance === fe.connectionUrl)
assert(batch.getBatchType === "PYSPARK")
basicKyuubiRestClient.close()
}
}
Loading