Skip to content

Commit

Permalink
[SPARK-24535][SPARKR] fix tests on java check error
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

change to skip tests if
- couldn't determine java version

fix problem on windows

## How was this patch tested?

unit test, manual, win-builder

Author: Felix Cheung <felixcheung_m@hotmail.com>

Closes #21666 from felixcheung/rjavaskip.

(cherry picked from commit 141953f)
Signed-off-by: Felix Cheung <felixcheung@apache.org>
  • Loading branch information
felixcheung authored and Felix Cheung committed Jul 6, 2018
1 parent bc7ee75 commit e5cc5f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
24 changes: 15 additions & 9 deletions R/pkg/R/client.R
Expand Up @@ -71,15 +71,20 @@ checkJavaVersion <- function() {


# If java is missing from PATH, we get an error in Unix and a warning in Windows # If java is missing from PATH, we get an error in Unix and a warning in Windows
javaVersionOut <- tryCatch( javaVersionOut <- tryCatch(
launchScript(javaBin, "-version", wait = TRUE, stdout = TRUE, stderr = TRUE), if (is_windows()) {
error = function(e) { # See SPARK-24535
stop("Java version check failed. Please make sure Java is installed", system2(javaBin, "-version", wait = TRUE, stdout = TRUE, stderr = TRUE)
" and set JAVA_HOME to point to the installation directory.", e) } else {
}, launchScript(javaBin, "-version", wait = TRUE, stdout = TRUE, stderr = TRUE)
warning = function(w) { },
stop("Java version check failed. Please make sure Java is installed", error = function(e) {
" and set JAVA_HOME to point to the installation directory.", w) stop("Java version check failed. Please make sure Java is installed",
}) " and set JAVA_HOME to point to the installation directory.", e)
},
warning = function(w) {
stop("Java version check failed. Please make sure Java is installed",
" and set JAVA_HOME to point to the installation directory.", w)
})
javaVersionFilter <- Filter( javaVersionFilter <- Filter(
function(x) { function(x) {
grepl(" version", x) grepl(" version", x)
Expand All @@ -93,6 +98,7 @@ checkJavaVersion <- function() {
stop(paste("Java version", sparkJavaVersion, "is required for this package; found version:", stop(paste("Java version", sparkJavaVersion, "is required for this package; found version:",
javaVersionStr)) javaVersionStr))
} }
return(javaVersionNum)
} }


launchBackend <- function(args, sparkHome, jars, sparkSubmitOpts, packages) { launchBackend <- function(args, sparkHome, jars, sparkSubmitOpts, packages) {
Expand Down
2 changes: 1 addition & 1 deletion R/pkg/R/sparkR.R
Expand Up @@ -170,7 +170,7 @@ sparkR.sparkContext <- function(
submitOps <- getClientModeSparkSubmitOpts( submitOps <- getClientModeSparkSubmitOpts(
Sys.getenv("SPARKR_SUBMIT_ARGS", "sparkr-shell"), Sys.getenv("SPARKR_SUBMIT_ARGS", "sparkr-shell"),
sparkEnvirMap) sparkEnvirMap)
checkJavaVersion() invisible(checkJavaVersion())
launchBackend( launchBackend(
args = path, args = path,
sparkHome = sparkHome, sparkHome = sparkHome,
Expand Down
8 changes: 8 additions & 0 deletions R/pkg/inst/tests/testthat/test_basic.R
Expand Up @@ -18,6 +18,10 @@
context("basic tests for CRAN") context("basic tests for CRAN")


test_that("create DataFrame from list or data.frame", { test_that("create DataFrame from list or data.frame", {
tryCatch( checkJavaVersion(),
error = function(e) { skip("error on Java check") },
warning = function(e) { skip("warning on Java check") } )

sparkR.session(master = sparkRTestMaster, enableHiveSupport = FALSE, sparkR.session(master = sparkRTestMaster, enableHiveSupport = FALSE,
sparkConfig = sparkRTestConfig) sparkConfig = sparkRTestConfig)


Expand Down Expand Up @@ -50,6 +54,10 @@ test_that("create DataFrame from list or data.frame", {
}) })


test_that("spark.glm and predict", { test_that("spark.glm and predict", {
tryCatch( checkJavaVersion(),
error = function(e) { skip("error on Java check") },
warning = function(e) { skip("warning on Java check") } )

sparkR.session(master = sparkRTestMaster, enableHiveSupport = FALSE, sparkR.session(master = sparkRTestMaster, enableHiveSupport = FALSE,
sparkConfig = sparkRTestConfig) sparkConfig = sparkRTestConfig)


Expand Down

0 comments on commit e5cc5f6

Please sign in to comment.