Skip to content

Commit 141953f

Browse files
felixcheungFelix Cheung
authored andcommitted
[SPARK-24535][SPARKR] fix tests on java check error
## 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 <[email protected]> Closes #21666 from felixcheung/rjavaskip.
1 parent bf67f70 commit 141953f

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

R/pkg/R/client.R

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,20 @@ checkJavaVersion <- function() {
7171

7272
# If java is missing from PATH, we get an error in Unix and a warning in Windows
7373
javaVersionOut <- tryCatch(
74-
launchScript(javaBin, "-version", wait = TRUE, stdout = TRUE, stderr = TRUE),
75-
error = function(e) {
76-
stop("Java version check failed. Please make sure Java is installed",
77-
" and set JAVA_HOME to point to the installation directory.", e)
78-
},
79-
warning = function(w) {
80-
stop("Java version check failed. Please make sure Java is installed",
81-
" and set JAVA_HOME to point to the installation directory.", w)
82-
})
74+
if (is_windows()) {
75+
# See SPARK-24535
76+
system2(javaBin, "-version", wait = TRUE, stdout = TRUE, stderr = TRUE)
77+
} else {
78+
launchScript(javaBin, "-version", wait = TRUE, stdout = TRUE, stderr = TRUE)
79+
},
80+
error = function(e) {
81+
stop("Java version check failed. Please make sure Java is installed",
82+
" and set JAVA_HOME to point to the installation directory.", e)
83+
},
84+
warning = function(w) {
85+
stop("Java version check failed. Please make sure Java is installed",
86+
" and set JAVA_HOME to point to the installation directory.", w)
87+
})
8388
javaVersionFilter <- Filter(
8489
function(x) {
8590
grepl(" version", x)
@@ -93,6 +98,7 @@ checkJavaVersion <- function() {
9398
stop(paste("Java version", sparkJavaVersion, "is required for this package; found version:",
9499
javaVersionStr))
95100
}
101+
return(javaVersionNum)
96102
}
97103

98104
launchBackend <- function(args, sparkHome, jars, sparkSubmitOpts, packages) {

R/pkg/R/sparkR.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ sparkR.sparkContext <- function(
167167
submitOps <- getClientModeSparkSubmitOpts(
168168
Sys.getenv("SPARKR_SUBMIT_ARGS", "sparkr-shell"),
169169
sparkEnvirMap)
170-
checkJavaVersion()
170+
invisible(checkJavaVersion())
171171
launchBackend(
172172
args = path,
173173
sparkHome = sparkHome,

R/pkg/inst/tests/testthat/test_basic.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
context("basic tests for CRAN")
1919

2020
test_that("create DataFrame from list or data.frame", {
21+
tryCatch( checkJavaVersion(),
22+
error = function(e) { skip("error on Java check") },
23+
warning = function(e) { skip("warning on Java check") } )
24+
2125
sparkR.session(master = sparkRTestMaster, enableHiveSupport = FALSE,
2226
sparkConfig = sparkRTestConfig)
2327

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

5256
test_that("spark.glm and predict", {
57+
tryCatch( checkJavaVersion(),
58+
error = function(e) { skip("error on Java check") },
59+
warning = function(e) { skip("warning on Java check") } )
60+
5361
sparkR.session(master = sparkRTestMaster, enableHiveSupport = FALSE,
5462
sparkConfig = sparkRTestConfig)
5563

0 commit comments

Comments
 (0)