forked from apache/zeppelin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selenium test spark, pyspark and sparkSql
### What is this PR for? Test functionality of spark, pyspark, sparksql ### What type of PR is it? Improvement ### Todos * [x] - Selenium for spark * [x] - Selenium for pyspark * [x] - Selenium for sparksql * [x] - refactor with apache#619 ### Is there a relevant Jira issue? ZEPPELIN-587 ### How should this be tested? On macOS PATH=~/Applications/Firefox.app/Contents/MacOS/:$PATH CI="" \ mvn -Dtest=org.apache.zeppelin.integration.TestSparkParagraph -Denforcer.skip=true \ test -pl zeppelin-server Author: Prabhjyot Singh <[email protected]> Closes apache#654 from prabhjyotsingh/ZEPPELIN-587 and squashes the following commits: 8f24695 [Prabhjyot Singh] use handleException in all other test cases remove test for spark 1.1.1 more meaningful log message 28dfc55 [Prabhjyot Singh] thorwong exception similar to apache#709 21bcc45 [Prabhjyot Singh] Merge remote-tracking branch 'origin/master' into ZEPPELIN-587 b05b81b [Prabhjyot Singh] have SHIFT_ENTER enum 9a206f4 [Prabhjyot Singh] add missing endToEndTestEnabled check for testSparkInterpreterDependencyLoading ab03287 [Prabhjyot Singh] have static import of AbstractZeppelinIT.HelperKeys.*, and rg.openqa.selenium.Keys.* 5187a16 [Prabhjyot Singh] check if spark version is less than 1.3 then don't append ".toDF()" 6927f7e [Prabhjyot Singh] CI FIX 9236e3c [Prabhjyot Singh] implemeting @bzz review comments 2c28758 [Prabhjyot Singh] missed refactor with apache#619 d49344f [Prabhjyot Singh] selenium test spark, pyspark and sparkSql
- Loading branch information
1 parent
831f426
commit 9b72c89
Showing
4 changed files
with
276 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
228 changes: 228 additions & 0 deletions
228
zeppelin-server/src/test/java/org/apache/zeppelin/integration/SparkParagraphIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
/* | ||
* 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.zeppelin.integration; | ||
|
||
|
||
import org.apache.zeppelin.AbstractZeppelinIT; | ||
import org.apache.zeppelin.WebDriverManager; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ErrorCollector; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.TimeoutException; | ||
import org.openqa.selenium.WebElement; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.apache.zeppelin.AbstractZeppelinIT.HelperKeys.*; | ||
import static org.openqa.selenium.Keys.*; | ||
|
||
public class SparkParagraphIT extends AbstractZeppelinIT { | ||
private static final Logger LOG = LoggerFactory.getLogger(SparkParagraphIT.class); | ||
|
||
|
||
@Rule | ||
public ErrorCollector collector = new ErrorCollector(); | ||
|
||
@Before | ||
public void startUp() { | ||
if (!endToEndTestEnabled()) { | ||
return; | ||
} | ||
driver = WebDriverManager.getWebDriver(); | ||
createNewNote(); | ||
waitForParagraph(1, "READY"); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
if (!endToEndTestEnabled()) { | ||
return; | ||
} | ||
deleteTestNotebook(driver); | ||
driver.quit(); | ||
} | ||
|
||
@Test | ||
public void testSpark() throws Exception { | ||
if (!endToEndTestEnabled()) { | ||
return; | ||
} | ||
try { | ||
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea")); | ||
paragraph1Editor.sendKeys("sc.version"); | ||
paragraph1Editor.sendKeys(SHIFT_ENTER); | ||
|
||
waitForParagraph(1, "FINISHED"); | ||
WebElement paragraph1Result = driver.findElement(By.xpath( | ||
getParagraphXPath(1) + "//div[@class=\"tableDisplay\"]")); | ||
Float sparkVersion = Float.parseFloat(paragraph1Result.getText().split("= ")[1].substring(0, 3)); | ||
|
||
WebElement paragraph2Editor = driver.findElement(By.xpath(getParagraphXPath(2) + "//textarea")); | ||
|
||
|
||
/* | ||
equivalent of | ||
import org.apache.commons.io.IOUtils | ||
import java.net.URL | ||
import java.nio.charset.Charset | ||
val bankText = sc.parallelize(IOUtils.toString(new URL("https://s3.amazonaws.com/apache-zeppelin/tutorial/bank/bank.csv"),Charset.forName("utf8")).split("\n")) | ||
case class Bank(age: Integer, job: String, marital: String, education: String, balance: Integer) | ||
val bank = bankText.map(s => s.split(";")).filter(s => s(0) != "\"age\"").map(s => Bank(s(0).toInt,s(1).replaceAll("\"", ""),s(2).replaceAll("\"", ""),s(3).replaceAll("\"", ""),s(5).replaceAll("\"", "").toInt)).toDF() | ||
bank.registerTempTable("bank") | ||
*/ | ||
paragraph2Editor.sendKeys("import org.apache.commons.io.IOUtils" + | ||
ENTER + | ||
|
||
"import java.net.URL" + | ||
ENTER + | ||
|
||
"import java.nio.charset.Charset" + | ||
ENTER + | ||
|
||
"val bankText = sc.parallelize" + OPEN_PARENTHESIS + | ||
"IOUtils.toString" + OPEN_PARENTHESIS + "new URL" + OPEN_PARENTHESIS | ||
+ "\"https://s3.amazonaws.com/apache" + SUBTRACT + "zeppelin/tutorial/bank/bank." + | ||
"csv\"),Charset.forName" + OPEN_PARENTHESIS + "\"utf8\"))" + | ||
".split" + OPEN_PARENTHESIS + "\"\\n\"))" + | ||
ENTER + | ||
|
||
"case class Bank" + OPEN_PARENTHESIS + | ||
"age: Integer, job: String, marital: String, education: String, balance: Integer)" + | ||
ENTER + | ||
ENTER + | ||
|
||
"val bank = bankText.map" + OPEN_PARENTHESIS + "s => s.split" + | ||
OPEN_PARENTHESIS + "\";\")).filter" + OPEN_PARENTHESIS + | ||
"s => s" + OPEN_PARENTHESIS + "0) " + EXCLAMATION + | ||
"= \"\\\"age\\\"\").map" + OPEN_PARENTHESIS + | ||
"s => Bank" + OPEN_PARENTHESIS + "s" + OPEN_PARENTHESIS + | ||
"0).toInt,s" + OPEN_PARENTHESIS + "1).replaceAll" + | ||
OPEN_PARENTHESIS + "\"\\\"\", \"\")," + | ||
"s" + OPEN_PARENTHESIS + "2).replaceAll" + | ||
OPEN_PARENTHESIS + "\"\\\"\", \"\")," + | ||
"s" + OPEN_PARENTHESIS + "3).replaceAll" + | ||
OPEN_PARENTHESIS + "\"\\\"\", \"\")," + | ||
"s" + OPEN_PARENTHESIS + "5).replaceAll" + | ||
OPEN_PARENTHESIS + "\"\\\"\", \"\").toInt" + ")" + | ||
")" + (sparkVersion < 1.3f ? "" : ".toDF" + OPEN_PARENTHESIS + ")") + | ||
ENTER + | ||
|
||
"bank.registerTempTable" + OPEN_PARENTHESIS + "\"bank\")" | ||
); | ||
paragraph2Editor.sendKeys("" + END + BACK_SPACE + BACK_SPACE + | ||
BACK_SPACE + BACK_SPACE + BACK_SPACE + BACK_SPACE + | ||
BACK_SPACE + BACK_SPACE + BACK_SPACE + BACK_SPACE + BACK_SPACE); | ||
|
||
paragraph2Editor.sendKeys(SHIFT_ENTER); | ||
|
||
try { | ||
waitForParagraph(2, "FINISHED"); | ||
} catch (TimeoutException e) { | ||
waitForParagraph(2, "ERROR"); | ||
collector.checkThat("2nd Paragraph from SparkParagraphIT of testSpark status:", | ||
"ERROR", CoreMatchers.equalTo("FINISHED") | ||
); | ||
} | ||
|
||
WebElement paragraph2Result = driver.findElement(By.xpath( | ||
getParagraphXPath(2) + "//div[@class=\"tableDisplay\"]")); | ||
|
||
collector.checkThat("2nd Paragraph from SparkParagraphIT of testSpark result: ", | ||
paragraph2Result.getText().toString(), CoreMatchers.containsString( | ||
"import org.apache.commons.io.IOUtils" | ||
) | ||
); | ||
|
||
} catch (Exception e) { | ||
handleException("Exception in SparkParagraphIT while testSpark", e); | ||
} | ||
} | ||
|
||
@Test | ||
public void testPySpark() throws Exception { | ||
if (!endToEndTestEnabled()) { | ||
return; | ||
} | ||
try { | ||
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea")); | ||
|
||
paragraph1Editor.sendKeys(PERCENTAGE + "pyspark" + ENTER + | ||
"for x in range" + OPEN_PARENTHESIS + "0, 3):" + ENTER + | ||
" print \"test loop " + PERCENTAGE + "d\" " + | ||
PERCENTAGE + " " + OPEN_PARENTHESIS + "x)" + ENTER); | ||
|
||
paragraph1Editor.sendKeys(SHIFT_ENTER); | ||
|
||
try { | ||
waitForParagraph(1, "FINISHED"); | ||
} catch (TimeoutException e) { | ||
waitForParagraph(1, "ERROR"); | ||
collector.checkThat("Paragraph from SparkParagraphIT of testPySpark status: ", | ||
"ERROR", CoreMatchers.equalTo("FINISHED") | ||
); | ||
} | ||
|
||
WebElement paragraph1Result = driver.findElement(By.xpath( | ||
getParagraphXPath(1) + "//div[@class=\"tableDisplay\"]")); | ||
collector.checkThat("Paragraph from SparkParagraphIT of testPySpark result: ", | ||
paragraph1Result.getText().toString(), CoreMatchers.equalTo("test loop 0\ntest loop 1\ntest loop 2") | ||
); | ||
|
||
} catch (Exception e) { | ||
handleException("Exception in SparkParagraphIT while testPySpark", e); | ||
} | ||
} | ||
|
||
@Test | ||
public void testSqlSpark() throws Exception { | ||
if (!endToEndTestEnabled()) { | ||
return; | ||
} | ||
try { | ||
WebElement paragraph1Editor = driver.findElement(By.xpath(getParagraphXPath(1) + "//textarea")); | ||
|
||
paragraph1Editor.sendKeys(PERCENTAGE + "sql" + ENTER + | ||
"select * from bank limit 1"); | ||
|
||
paragraph1Editor.sendKeys(SHIFT_ENTER); | ||
|
||
try { | ||
waitForParagraph(1, "FINISHED"); | ||
} catch (TimeoutException e) { | ||
waitForParagraph(1, "ERROR"); | ||
collector.checkThat("Paragraph from SparkParagraphIT of testSqlSpark status: ", | ||
"ERROR", CoreMatchers.equalTo("FINISHED") | ||
); | ||
} | ||
|
||
WebElement paragraph1Result = driver.findElement(By.xpath( | ||
getParagraphXPath(1) + "//div[@class=\"tableDisplay\"]")); | ||
collector.checkThat("Paragraph from SparkParagraphIT of testSqlSpark result: ", | ||
paragraph1Result.getText().toString(), CoreMatchers.equalTo("age job marital education balance\n" + | ||
"30 unemployed married primary 1,787") | ||
); | ||
} catch (Exception e) { | ||
handleException("Exception in SparkParagraphIT while testSqlSpark", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters