3737SPARK_HOME = os .environ ["SPARK_HOME" ]
3838
3939
40- class StreamOutput :
41- """
42- a class to store the output from stream
43- """
44- result = list ()
45-
46-
4740class PySparkStreamingTestCase (unittest .TestCase ):
4841 def setUp (self ):
4942 class_name = self .__class__ .__name__
@@ -115,7 +108,8 @@ def test_func(dstream):
115108
116109 def test_count (self ):
117110 """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 )]
119113
120114 def test_func (dstream ):
121115 print "count"
@@ -137,33 +131,39 @@ def test_func(dstream):
137131
138132 def test_reduceByKey (self ):
139133 """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" ], ["" , "" , "" , "" ], []]
141136
142137 def test_func (dstream ):
143138 print "reduceByKey"
144139 dstream .map (lambda x : (x , 1 )).pyprint ()
145140 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 )], []]
147143 output = self ._run_stream (test_input , test_func , expected_output )
148144 self .assertEqual (expected_output , output )
149145
150146 def test_mapValues (self ):
151147 """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" ], ["" , "" , "" , "" ], []]
153150
154151 def test_func (dstream ):
155152 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 )], []]
157155 output = self ._run_stream (test_input , test_func , expected_output )
158156 self .assertEqual (expected_output , output )
159157
160158 def test_flatMapValues (self ):
161159 """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" ], ["" , "" , "" ,"" ], []]
163162
164163 def test_func (dstream ):
165164 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 )], []]
167167 output = self ._run_stream (test_input , test_func , expected_output )
168168 self .assertEqual (expected_output , output )
169169
0 commit comments