-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement updateStateByKey() * rewrite streaming test cases without StreamingTestCase class
- Loading branch information
1 parent
347c633
commit 4595a7c
Showing
6 changed files
with
222 additions
and
118 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,53 +1,73 @@ | ||
from .streaming_test_case import StreamingTestCase | ||
import pysparkling | ||
import tornado.testing | ||
|
||
|
||
class TextFile(StreamingTestCase): | ||
class TextFile(tornado.testing.AsyncTestCase): | ||
|
||
def test_connect(self): | ||
self.result = 0 | ||
self.expect = 22 | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
result = [] | ||
( | ||
self.stream_c.textFileStream('LICENS*', process_all=True) | ||
ssc.textFileStream('LICENS*', process_all=True) | ||
.count() | ||
.foreachRDD(lambda rdd: self.incr_result(rdd.collect()[0])) | ||
.foreachRDD(lambda rdd: result.append(rdd.collect()[0])) | ||
) | ||
|
||
ssc.start() | ||
ssc.awaitTermination(timeout=0.3) | ||
self.assertEqual(sum(result), 22) | ||
|
||
def test_save(self): | ||
self.result = 0 | ||
self.expect = 0 | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
( | ||
self.stream_c.textFileStream('LICENS*') | ||
ssc.textFileStream('LICENS*') | ||
.count() | ||
.saveAsTextFiles('tests/textout/') | ||
) | ||
|
||
def test_save_gz(self): | ||
self.result = 0 | ||
self.expect = 0 | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
( | ||
self.stream_c.textFileStream('LICENS*') | ||
ssc.textFileStream('LICENS*') | ||
.count() | ||
.saveAsTextFiles('tests/textout/', suffix='.gz') | ||
) | ||
|
||
|
||
class BinaryFile(StreamingTestCase): | ||
class BinaryFile(tornado.testing.AsyncTestCase): | ||
|
||
def test_read_file(self): | ||
self.result = 0 | ||
self.expect = 1 | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
result = [] | ||
( | ||
self.stream_c.fileBinaryStream('LICENS*', process_all=True) | ||
ssc.fileBinaryStream('LICENS*', process_all=True) | ||
.count() | ||
.foreachRDD(lambda rdd: self.incr_result(rdd.collect()[0])) | ||
.foreachRDD(lambda rdd: result.append(rdd.collect()[0])) | ||
) | ||
|
||
ssc.start() | ||
ssc.awaitTermination(timeout=0.3) | ||
self.assertEqual(sum(result), 1) | ||
|
||
def test_read_chunks(self): | ||
self.result = 0 | ||
self.expect = 28 | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
result = [] | ||
( | ||
self.stream_c.fileBinaryStream('LICENS*', recordLength=40, | ||
process_all=True) | ||
ssc.fileBinaryStream('LICENS*', recordLength=40, process_all=True) | ||
.count() | ||
.foreachRDD(lambda rdd: self.incr_result(rdd.collect()[0])) | ||
.foreachRDD(lambda rdd: result.append(rdd.collect()[0])) | ||
) | ||
|
||
ssc.start() | ||
ssc.awaitTermination(timeout=0.3) | ||
self.assertEqual(sum(result), 28) |
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 |
---|---|---|
@@ -1,34 +1,54 @@ | ||
from __future__ import print_function | ||
|
||
from .streaming_test_case import StreamingTestCase | ||
import pysparkling | ||
import tornado.testing | ||
|
||
|
||
class TestCount(StreamingTestCase): | ||
class TestCount(tornado.testing.AsyncTestCase): | ||
|
||
def test_count(self): | ||
self.result = 0 | ||
self.expect = 23 | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
result = [] | ||
( | ||
self.stream_c.queueStream([range(20), ['a', 'b'], ['c']]) | ||
ssc.queueStream([range(20), ['a', 'b'], ['c']]) | ||
.count() | ||
.foreachRDD(lambda rdd: self.incr_result(rdd.collect()[0])) | ||
.foreachRDD(lambda rdd: result.append(rdd.collect()[0])) | ||
) | ||
|
||
ssc.start() | ||
ssc.awaitTermination(timeout=0.3) | ||
self.assertEqual(sum(result), 23) | ||
|
||
def test_groupByKey(self): | ||
self.result = [] | ||
self.expect = [[('a', [2, 5]), ('b', [8])], [('a', [2]), ('b', [3])]] | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
result = [] | ||
( | ||
self.stream_c.queueStream([[('a', 5), ('b', 8), ('a', 2)], | ||
[('a', 2), ('b', 3)]]) | ||
ssc.queueStream([[('a', 5), ('b', 8), ('a', 2)], | ||
[('a', 2), ('b', 3)]]) | ||
.groupByKey().mapPartitions(sorted).mapValues(sorted) | ||
.foreachRDD(lambda rdd: self.append_result(rdd.collect())) | ||
.foreachRDD(lambda rdd: result.append(rdd.collect())) | ||
) | ||
|
||
ssc.start() | ||
ssc.awaitTermination(timeout=0.25) | ||
self.assertEqual( | ||
result, [[('a', [2, 5]), ('b', [8])], [('a', [2]), ('b', [3])]]) | ||
|
||
def test_mapValues(self): | ||
self.result = [] | ||
self.expect = [[('a', [2, 5, 8]), ('b', [3, 6, 8])]] | ||
sc = pysparkling.Context() | ||
ssc = pysparkling.streaming.StreamingContext(sc, 0.1) | ||
|
||
result = [] | ||
( | ||
self.stream_c.queueStream([[('a', [5, 8, 2]), ('b', [6, 3, 8])]]) | ||
ssc.queueStream([[('a', [5, 8, 2]), ('b', [6, 3, 8])]]) | ||
.mapValues(sorted) | ||
.foreachRDD(lambda rdd: self.append_result(rdd.collect())) | ||
.foreachRDD(lambda rdd: result.append(rdd.collect())) | ||
) | ||
|
||
ssc.start() | ||
ssc.awaitTermination(timeout=0.15) | ||
self.assertEqual(result, [[('a', [2, 5, 8]), ('b', [3, 6, 8])]]) |
Oops, something went wrong.