37
37
SPARK_HOME = os .environ ["SPARK_HOME" ]
38
38
39
39
40
- class StreamOutput :
41
- """
42
- a class to store the output from stream
43
- """
44
- result = list ()
45
-
46
-
47
40
class PySparkStreamingTestCase (unittest .TestCase ):
48
41
def setUp (self ):
49
42
class_name = self .__class__ .__name__
@@ -115,7 +108,8 @@ def test_func(dstream):
115
108
116
109
def test_count (self ):
117
110
"""Basic operation test for DStream.count"""
118
- test_input = [[], [1 ], range (1 , 3 ), range (1 , 4 ), range (1 , 5 )]
111
+ #test_input = [[], [1], range(1, 3), range(1, 4), range(1, 5)]
112
+ test_input = [range (1 , 5 ), range (1 ,10 ), range (1 ,20 )]
119
113
120
114
def test_func (dstream ):
121
115
print "count"
@@ -137,33 +131,39 @@ def test_func(dstream):
137
131
138
132
def test_reduceByKey (self ):
139
133
"""Basic operation test for DStream.reduceByKey"""
140
- test_input = [["a" , "a" , "b" ], ["" , "" ], []]
134
+ #test_input = [["a", "a", "b"], ["", ""], []]
135
+ test_input = [["a" , "a" , "b" , "b" ], ["" , "" , "" , "" ], []]
141
136
142
137
def test_func (dstream ):
143
138
print "reduceByKey"
144
139
dstream .map (lambda x : (x , 1 )).pyprint ()
145
140
return dstream .map (lambda x : (x , 1 )).reduceByKey (operator .add )
146
- expected_output = [[("a" , 2 ), ("b" , 1 )], [("" , 2 )], []]
141
+ #expected_output = [[("a", 2), ("b", 1)], [("", 2)], []]
142
+ expected_output = [[("a" , 2 ), ("b" , 2 )], [("" , 4 )], []]
147
143
output = self ._run_stream (test_input , test_func , expected_output )
148
144
self .assertEqual (expected_output , output )
149
145
150
146
def test_mapValues (self ):
151
147
"""Basic operation test for DStream.mapValues"""
152
- test_input = [["a" , "a" , "b" ], ["" , "" ], []]
148
+ #test_input = [["a", "a", "b"], ["", ""], []]
149
+ test_input = [["a" , "a" , "b" , "b" ], ["" , "" , "" , "" ], []]
153
150
154
151
def test_func (dstream ):
155
152
return dstream .map (lambda x : (x , 1 )).reduceByKey (operator .add ).mapValues (lambda x : x + 10 )
156
- expected_output = [[("a" , 12 ), ("b" , 11 )], [("" , 12 )], []]
153
+ #expected_output = [[("a", 12), ("b", 11)], [("", 12)], []]
154
+ expected_output = [[("a" , 12 ), ("b" , 12 )], [("" , 14 )], []]
157
155
output = self ._run_stream (test_input , test_func , expected_output )
158
156
self .assertEqual (expected_output , output )
159
157
160
158
def test_flatMapValues (self ):
161
159
"""Basic operation test for DStream.flatMapValues"""
162
- test_input = [["a" , "a" , "b" ], ["" , "" ], []]
160
+ #test_input = [["a", "a", "b"], ["", ""], []]
161
+ test_input = [["a" , "a" , "b" , "b" ], ["" , "" , "" ,"" ], []]
163
162
164
163
def test_func (dstream ):
165
164
return dstream .map (lambda x : (x , 1 )).reduceByKey (operator .add ).flatMapValues (lambda x : (x , x + 10 ))
166
- expected_output = [[("a" , 2 ), ("a" , 12 ), ("b" , 1 ), ("b" , 11 )], [("" , 2 ), ("" , 12 )], []]
165
+ #expected_output = [[("a", 2), ("a", 12), ("b", 1), ("b", 11)], [("", 2), ("", 12)], []]
166
+ expected_output = [[("a" , 2 ), ("a" , 12 ), ("b" , 2 ), ("b" , 12 )], [("" , 4 ), ("" , 14 )], []]
167
167
output = self ._run_stream (test_input , test_func , expected_output )
168
168
self .assertEqual (expected_output , output )
169
169
0 commit comments