spark-instrumented-optimizer/R/pkg/inst/tests/test_context.R
felixcheung bb5a2af034 [SPARK-11340][SPARKR] Support setting driver properties when starting Spark from R programmatically or from RStudio
Mapping spark.driver.memory from sparkEnvir to spark-submit commandline arguments.

shivaram suggested that we possibly add other spark.driver.* properties - do we want to add all of those? I thought those could be set in SparkConf?
sun-rui

Author: felixcheung <felixcheung_m@hotmail.com>

Closes #9290 from felixcheung/rdrivermem.
2015-10-30 13:51:32 -07:00

95 lines
3.3 KiB
R

#
# 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.
#
context("test functions in sparkR.R")
test_that("repeatedly starting and stopping SparkR", {
for (i in 1:4) {
sc <- sparkR.init()
rdd <- parallelize(sc, 1:20, 2L)
expect_equal(count(rdd), 20)
sparkR.stop()
}
})
test_that("repeatedly starting and stopping SparkR SQL", {
for (i in 1:4) {
sc <- sparkR.init()
sqlContext <- sparkRSQL.init(sc)
df <- createDataFrame(sqlContext, data.frame(a = 1:20))
expect_equal(count(df), 20)
sparkR.stop()
}
})
test_that("rdd GC across sparkR.stop", {
sparkR.stop()
sc <- sparkR.init() # sc should get id 0
rdd1 <- parallelize(sc, 1:20, 2L) # rdd1 should get id 1
rdd2 <- parallelize(sc, 1:10, 2L) # rdd2 should get id 2
sparkR.stop()
sc <- sparkR.init() # sc should get id 0 again
# GC rdd1 before creating rdd3 and rdd2 after
rm(rdd1)
gc()
rdd3 <- parallelize(sc, 1:20, 2L) # rdd3 should get id 1 now
rdd4 <- parallelize(sc, 1:10, 2L) # rdd4 should get id 2 now
rm(rdd2)
gc()
count(rdd3)
count(rdd4)
})
test_that("job group functions can be called", {
sc <- sparkR.init()
setJobGroup(sc, "groupId", "job description", TRUE)
cancelJobGroup(sc, "groupId")
clearJobGroup(sc)
})
test_that("getClientModeSparkSubmitOpts() returns spark-submit args from whitelist", {
e <- new.env()
e[["spark.driver.memory"]] <- "512m"
ops <- getClientModeSparkSubmitOpts("sparkrmain", e)
expect_equal("--driver-memory \"512m\" sparkrmain", ops)
e[["spark.driver.memory"]] <- "5g"
e[["spark.driver.extraClassPath"]] <- "/opt/class_path" # nolint
e[["spark.driver.extraJavaOptions"]] <- "-XX:+UseCompressedOops -XX:+UseCompressedStrings"
e[["spark.driver.extraLibraryPath"]] <- "/usr/local/hadoop/lib" # nolint
e[["random"]] <- "skipthis"
ops2 <- getClientModeSparkSubmitOpts("sparkr-shell", e)
# nolint start
expect_equal(ops2, paste0("--driver-class-path \"/opt/class_path\" --driver-java-options \"",
"-XX:+UseCompressedOops -XX:+UseCompressedStrings\" --driver-library-path \"",
"/usr/local/hadoop/lib\" --driver-memory \"5g\" sparkr-shell"))
# nolint end
e[["spark.driver.extraClassPath"]] <- "/" # too short
ops3 <- getClientModeSparkSubmitOpts("--driver-memory 4g sparkr-shell2", e)
# nolint start
expect_equal(ops3, paste0("--driver-java-options \"-XX:+UseCompressedOops ",
"-XX:+UseCompressedStrings\" --driver-library-path \"/usr/local/hadoop/lib\"",
" --driver-memory 4g sparkr-shell2"))
# nolint end
})