25
25
import time
26
26
import unittest
27
27
28
+ from parameterized import parameterized
29
+
28
30
import apache_beam as beam
29
31
from apache_beam .io .restriction_trackers import OffsetRange
30
32
from apache_beam .testing .test_pipeline import TestPipeline
@@ -159,6 +161,53 @@ def test_processing_time(self):
159
161
expected = [0 , 2 , 4 ]
160
162
assert_that (ret , equal_to (expected , lambda x , y : abs (x - y ) < threshold ))
161
163
164
+ @parameterized .expand ([0.5 , 1 , 2 , 10 ])
165
+ def test_stop_over_by_epsilon (self , interval ):
166
+ with TestPipeline () as p :
167
+ ret = (
168
+ p | PeriodicImpulse (
169
+ start_timestamp = Timestamp (seconds = 1 ),
170
+ stop_timestamp = Timestamp (seconds = 1 , micros = 1 ),
171
+ data = [1 , 2 ],
172
+ fire_interval = interval )
173
+ | beam .WindowInto (FixedWindows (interval ))
174
+ | beam .WithKeys (0 )
175
+ | beam .GroupByKey ())
176
+ expected = [
177
+ (0 , [1 ]),
178
+ ]
179
+ assert_that (ret , equal_to (expected ))
180
+
181
+ @parameterized .expand ([1 , 2 ])
182
+ def test_stop_over_by_interval (self , interval ):
183
+ with TestPipeline () as p :
184
+ ret = (
185
+ p | PeriodicImpulse (
186
+ start_timestamp = Timestamp (seconds = 1 ),
187
+ stop_timestamp = Timestamp (seconds = 1 + interval ),
188
+ data = [1 , 2 ],
189
+ fire_interval = interval )
190
+ | beam .WindowInto (FixedWindows (interval ))
191
+ | beam .WithKeys (0 )
192
+ | beam .GroupByKey ())
193
+ expected = [(0 , [1 ])]
194
+ assert_that (ret , equal_to (expected ))
195
+
196
+ @parameterized .expand ([1 , 2 ])
197
+ def test_stop_over_by_interval_and_epsilon (self , interval ):
198
+ with TestPipeline () as p :
199
+ ret = (
200
+ p | PeriodicImpulse (
201
+ start_timestamp = Timestamp (seconds = 1 ),
202
+ stop_timestamp = Timestamp (seconds = 1 + interval , micros = 1 ),
203
+ data = [1 , 2 ],
204
+ fire_interval = interval )
205
+ | beam .WindowInto (FixedWindows (interval ))
206
+ | beam .WithKeys (0 )
207
+ | beam .GroupByKey ())
208
+ expected = [(0 , [1 ]), (0 , [2 ])]
209
+ assert_that (ret , equal_to (expected ))
210
+
162
211
def test_interval (self ):
163
212
with TestPipeline () as p :
164
213
ret = (
@@ -176,7 +225,7 @@ def test_repeat(self):
176
225
ret = (
177
226
p | PeriodicImpulse (
178
227
start_timestamp = now ,
179
- stop_timestamp = now + 3.0 ,
228
+ stop_timestamp = now + 2.6 ,
180
229
data = [1 , 2 , 3 , 4 ],
181
230
fire_interval = 0.5 )
182
231
| beam .WindowInto (FixedWindows (0.5 ))
@@ -212,7 +261,7 @@ def test_not_enough_timestamped_value(self):
212
261
213
262
def test_fuzzy_interval (self ):
214
263
seed = int (time .time () * 1000 )
215
- times = 25
264
+ times = 30
216
265
logging .warning ("random seed=%d" , seed )
217
266
random .seed (seed )
218
267
for _ in range (times ):
0 commit comments