-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add e2e tests for Spark Scala (#6788)
* add tests for Spark Scala * clean notebook output
- Loading branch information
1 parent
f4656b0
commit 60071b0
Showing
6 changed files
with
185 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%%classpath add mvn\n", | ||
"org.apache.spark spark-sql_2.11 2.2.1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import org.apache.spark.sql.SparkSession\n", | ||
"\n", | ||
"val spark = SparkSession.builder()\n", | ||
" .appName(\"Simple Application\")\n", | ||
" .master(\"local[4]\")\n", | ||
" .config(\"spark.ui.enabled\", \"false\")\n", | ||
" .getOrCreate()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"val NUM_SAMPLES = 10000000\n", | ||
"\n", | ||
"val count = spark.sparkContext.parallelize(1 to NUM_SAMPLES).map{i =>\n", | ||
" val x = Math.random()\n", | ||
" val y = Math.random()\n", | ||
" if (x*x + y*y < 1) 1 else 0\n", | ||
"}.reduce(_ + _)\n", | ||
"\n", | ||
"println(\"Pi is roughly \" + 4.0 * count / NUM_SAMPLES)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"spark.stop()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Scala", | ||
"language": "scala", | ||
"name": "scala" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "text/x-scala", | ||
"file_extension": ".scala", | ||
"mimetype": "", | ||
"name": "Scala", | ||
"nbconverter_exporter": "", | ||
"version": "2.11.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
var BeakerXPageObject = require('../beakerx.po.js'); | ||
var beakerxPO; | ||
|
||
describe('Scala notebook', function () { | ||
|
||
beforeAll(function () { | ||
beakerxPO = new BeakerXPageObject(); | ||
beakerxPO.runNotebookByUrl('/notebooks/test/notebooks/scala/SparkScalaTest.ipynb'); | ||
}); | ||
|
||
afterAll(function () { | ||
beakerxPO.closeAndHaltNotebook(); | ||
}); | ||
|
||
var cellIndex; | ||
|
||
describe('Add Spark jars. ', function () { | ||
it('Should add Spark jars', function () { | ||
cellIndex = 0; | ||
beakerxPO.runCodeCellByIndex(cellIndex); | ||
beakerxPO.waitAndCheckCellOutputStdoutText(cellIndex, /spark-sql/); | ||
beakerxPO.waitAndCheckCellOutputStdoutText(cellIndex, /spark-core/); | ||
}); | ||
}); | ||
|
||
describe('Spark session. ', function () { | ||
it('Spark should start session', function () { | ||
cellIndex +=1; | ||
beakerxPO.runCodeCellByIndex(cellIndex); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, /Running Spark/); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, /Successfully started service .sparkDriver./); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, | ||
/Successfully started service .org\.apache\.spark\.network\.netty\.NettyBlockTransferService./); | ||
beakerxPO.waitAndCheckCellOutputResultText(cellIndex, /org.apache.spark.sql.SparkSession/); | ||
}); | ||
}); | ||
|
||
describe('Spark job. ', function () { | ||
it('Spark should calculate PI', function () { | ||
cellIndex +=1; | ||
beakerxPO.runCodeCellByIndex(cellIndex); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, /Starting job/); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, /Job \d* finished/); | ||
beakerxPO.waitAndCheckCellOutputStdoutText(cellIndex, /Pi is roughly \d.\d*/) | ||
|
||
}); | ||
}); | ||
|
||
describe('Spark stop. ', function () { | ||
it('Spark should be stopped', function () { | ||
cellIndex +=1; | ||
beakerxPO.runCodeCellByIndex(cellIndex); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, /MemoryStore cleared/); | ||
beakerxPO.waitAndCheckCellOutputStderrText(cellIndex, /Successfully stopped SparkContext/); | ||
}); | ||
}); | ||
|
||
}); |