Repository: spark Updated Branches: refs/heads/master 0ac2f1e71 -> f1330b1d9
[SPARK-19022][TESTS] Fix tests dependent on OS due to different newline characters ## What changes were proposed in this pull request? There are two tests failing on Windows due to the different newlines. ``` - StreamingQueryProgress - prettyJson *** FAILED *** (0 milliseconds) "{ "id" : "39788670-6722-48b7-a248-df6ba08722ac", "runId" : "422282f1-3b81-4b47-a15d-82dda7e69390", "name" : "myName", ... }" did not equal "{ "id" : "39788670-6722-48b7-a248-df6ba08722ac", "runId" : "422282f1-3b81-4b47-a15d-82dda7e69390", "name" : "myName", ... }" ... ``` ``` - StreamingQueryStatus - prettyJson *** FAILED *** (0 milliseconds) "{ "message" : "active", "isDataAvailable" : true, "isTriggerActive" : false }" did not equal "{ "message" : "active", "isDataAvailable" : true, "isTriggerActive" : false }" ... ``` The reason is, `pretty` in `org.json4s.pretty` writes OS-dependent newlines but the string defined in the tests are `\n`. This ends up with test failures. This PR proposes to compare these regardless of newline concerns. ## How was this patch tested? Manually tested via AppVeyor. **Before** https://ci.appveyor.com/project/spark-test/spark/build/417-newlines-fix-before **After** https://ci.appveyor.com/project/spark-test/spark/build/418-newlines-fix Author: hyukjinkwon <gurwls...@gmail.com> Closes #16433 from HyukjinKwon/tests-StreamingQueryStatusAndProgressSuite. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f1330b1d Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f1330b1d Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f1330b1d Branch: refs/heads/master Commit: f1330b1d9e7b1d5de611e59eecae1bf0b0616d81 Parents: 0ac2f1e Author: hyukjinkwon <gurwls...@gmail.com> Authored: Mon Jan 2 15:17:02 2017 +0000 Committer: Sean Owen <so...@cloudera.com> Committed: Mon Jan 2 15:17:02 2017 +0000 ---------------------------------------------------------------------- .../StreamingQueryStatusAndProgressSuite.scala | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/f1330b1d/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQueryStatusAndProgressSuite.scala ---------------------------------------------------------------------- diff --git a/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQueryStatusAndProgressSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQueryStatusAndProgressSuite.scala index 34bf398..2035db5 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQueryStatusAndProgressSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQueryStatusAndProgressSuite.scala @@ -30,10 +30,16 @@ import org.apache.spark.sql.streaming.StreamingQueryStatusAndProgressSuite._ class StreamingQueryStatusAndProgressSuite extends StreamTest { + implicit class EqualsIgnoreCRLF(source: String) { + def equalsIgnoreCRLF(target: String): Boolean = { + source.replaceAll("\r\n|\r|\n", System.lineSeparator) === + target.replaceAll("\r\n|\r|\n", System.lineSeparator) + } + } test("StreamingQueryProgress - prettyJson") { val json1 = testProgress1.prettyJson - assert(json1 === + assert(json1.equalsIgnoreCRLF( s""" |{ | "id" : "${testProgress1.id.toString}", @@ -66,12 +72,12 @@ class StreamingQueryStatusAndProgressSuite extends StreamTest { | "description" : "sink" | } |} - """.stripMargin.trim) + """.stripMargin.trim)) assert(compact(parse(json1)) === testProgress1.json) val json2 = testProgress2.prettyJson assert( - json2 === + json2.equalsIgnoreCRLF( s""" |{ | "id" : "${testProgress2.id.toString}", @@ -96,7 +102,7 @@ class StreamingQueryStatusAndProgressSuite extends StreamTest { | "description" : "sink" | } |} - """.stripMargin.trim) + """.stripMargin.trim)) assert(compact(parse(json2)) === testProgress2.json) } @@ -112,14 +118,14 @@ class StreamingQueryStatusAndProgressSuite extends StreamTest { test("StreamingQueryStatus - prettyJson") { val json = testStatus.prettyJson - assert(json === + assert(json.equalsIgnoreCRLF( """ |{ | "message" : "active", | "isDataAvailable" : true, | "isTriggerActive" : false |} - """.stripMargin.trim) + """.stripMargin.trim)) } test("StreamingQueryStatus - json") { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org