Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PApostol committed Oct 22, 2021
1 parent 1e879a3 commit 709befd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
pyspark
20 changes: 20 additions & 0 deletions tests/resources/pyspark_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from pyspark.sql import SparkSession
from random import random
from operator import add
import sys

spark = SparkSession.builder.appName('Calculate Pi').getOrCreate()

accuracy = int(sys.argv[1]) if len(sys.argv) > 1 else 50000

partitions = 2
n = accuracy * partitions

def f(_):
x = random() * 2 - 1
y = random() * 2 - 1
return 1 if x ** 2 + y ** 2 <= 1 else 0

count = spark.sparkContext.parallelize(range(1, n + 1), partitions).map(f).reduce(add)
print('Pi is about {0}'.format(4.0 * count / n))
spark.stop()
12 changes: 12 additions & 0 deletions tests/run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from spark_submit import SparkJob

print('---Running example on local mode---')
job = SparkJob('tests/resources/pyspark_example.py', main_file_args ='100000')

print('spark-submit command:\n' + job.submit_cmd)
job.submit()
print('\nJob running...\n')

print('Job output:\n{0}\n'.format(job.get_output()))
print('Job state: {0}\n'.format(job.get_state()))
print('Job return code: {0}\n'.format(job.get_code()))

0 comments on commit 709befd

Please sign in to comment.