2020from typing import List
2121
2222from pyflink .common import Types , Row , Time , Configuration , WatermarkStrategy
23- from pyflink .datastream import AsyncDataStream , AsyncFunction , ResultFuture , \
23+ from pyflink .datastream import AsyncDataStream , AsyncFunction , \
2424 StreamExecutionEnvironment , AsyncRetryStrategy
2525from pyflink .datastream .tests .test_util import DataStreamTestSinkFunction , \
2626 SecondColumnTimestampAssigner
@@ -54,12 +54,12 @@ def test_unordered_mode(self):
5454
5555 class MyAsyncFunction (AsyncFunction ):
5656
57- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
57+ async def async_invoke (self , value : Row ):
5858 await asyncio .sleep (2 )
59- result_future . complete ( [value [0 ] + value [1 ]])
59+ return [value [0 ] + value [1 ]]
6060
61- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
62- result_future . complete ( [value [0 ] + value [1 ]])
61+ def timeout (self , value : Row ):
62+ return [value [0 ] + value [1 ]]
6363
6464 ds = AsyncDataStream .unordered_wait (
6565 ds , MyAsyncFunction (), Time .seconds (5 ), 2 , Types .INT ())
@@ -78,12 +78,12 @@ def test_ordered_mode(self):
7878
7979 class MyAsyncFunction (AsyncFunction ):
8080
81- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
81+ async def async_invoke (self , value : Row ):
8282 await asyncio .sleep (random .randint (1 , 2 ))
83- result_future . complete ( [value [0 ] + value [1 ]])
83+ return [value [0 ] + value [1 ]]
8484
85- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
86- result_future . complete ( [value [0 ] + value [1 ]])
85+ def timeout (self , value : Row ):
86+ return [value [0 ] + value [1 ]]
8787
8888 ds = AsyncDataStream .ordered_wait (
8989 ds , MyAsyncFunction (), Time .seconds (5 ), 2 , Types .INT ())
@@ -110,12 +110,12 @@ def test_watermark(self):
110110
111111 class MyAsyncFunction (AsyncFunction ):
112112
113- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
113+ async def async_invoke (self , value : Row ):
114114 await asyncio .sleep (random .randint (1 , 3 ))
115- result_future . complete ( [value [0 ] + value [1 ]])
115+ return [value [0 ] + value [1 ]]
116116
117- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
118- result_future . complete ( [value [0 ] + value [1 ]])
117+ def timeout (self , value : Row ):
118+ return [value [0 ] + value [1 ]]
119119
120120 ds = AsyncDataStream .unordered_wait (
121121 ds , MyAsyncFunction (), Time .seconds (5 ), 2 , Types .INT ())
@@ -135,12 +135,12 @@ def test_complete_async_function_with_non_iterable_result(self):
135135
136136 class MyAsyncFunction (AsyncFunction ):
137137
138- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
138+ async def async_invoke (self , value : Row ):
139139 await asyncio .sleep (2 )
140- result_future . complete ( value [0 ] + value [1 ])
140+ return value [0 ] + value [1 ]
141141
142- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
143- result_future . complete ( value [0 ] + value [1 ])
142+ def timeout (self , value : Row ):
143+ return value [0 ] + value [1 ]
144144
145145 ds = AsyncDataStream .unordered_wait (
146146 ds , MyAsyncFunction (), Time .seconds (5 ), 2 , Types .INT ())
@@ -161,12 +161,12 @@ def test_complete_async_function_with_exception(self):
161161
162162 class MyAsyncFunction (AsyncFunction ):
163163
164- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
165- result_future . complete_exceptionally ( Exception ("encountered an exception" ) )
164+ async def async_invoke (self , value : Row ):
165+ raise Exception ("encountered an exception" )
166166
167- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
167+ def timeout (self , value : Row ):
168168 # raise the same exception to make sure test case is stable in all cases
169- result_future . complete_exceptionally ( Exception ("encountered an exception" ) )
169+ raise Exception ("encountered an exception" )
170170
171171 ds = AsyncDataStream .unordered_wait (
172172 ds , MyAsyncFunction (), Time .seconds (5 ), 2 , Types .INT ())
@@ -186,10 +186,10 @@ def test_raise_exception_in_async_invoke(self):
186186
187187 class MyAsyncFunction (AsyncFunction ):
188188
189- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
189+ async def async_invoke (self , value : Row ):
190190 raise Exception ("encountered an exception" )
191191
192- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
192+ def timeout (self , value : Row ):
193193 # raise the same exception to make sure test case is stable in all cases
194194 raise Exception ("encountered an exception" )
195195
@@ -211,11 +211,11 @@ def test_raise_exception_in_timeout(self):
211211
212212 class MyAsyncFunction (AsyncFunction ):
213213
214- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
214+ async def async_invoke (self , value : Row ):
215215 await asyncio .sleep (10 )
216- result_future . complete ( [value [0 ] + value [1 ]])
216+ return [value [0 ] + value [1 ]]
217217
218- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
218+ def timeout (self , value : Row ):
219219 raise Exception ("encountered an exception" )
220220
221221 ds = AsyncDataStream .unordered_wait (
@@ -236,12 +236,12 @@ def test_processing_timeout(self):
236236
237237 class MyAsyncFunction (AsyncFunction ):
238238
239- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
239+ async def async_invoke (self , value : Row ):
240240 await asyncio .sleep (10 )
241- result_future . complete ( [value [0 ] + value [1 ]])
241+ return [value [0 ] + value [1 ]]
242242
243- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
244- result_future . complete ( [value [0 ] - value [1 ]])
243+ def timeout (self , value : Row ):
244+ return [value [0 ] - value [1 ]]
245245
246246 ds = AsyncDataStream .unordered_wait (
247247 ds , MyAsyncFunction (), Time .seconds (1 ), 2 , Types .INT ())
@@ -264,19 +264,19 @@ def __init__(self):
264264 self .retries_1 = {}
265265 self .retries_2 = {}
266266
267- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
267+ async def async_invoke (self , value : Row ):
268268 await asyncio .sleep (1 )
269269 if value in self .retries_2 :
270- result_future . complete ( [value [0 ] + value [1 ]])
270+ return [value [0 ] + value [1 ]]
271271 elif value in self .retries_1 :
272272 self .retries_2 [value ] = True
273- result_future . complete ( [value [0 ] + value [1 ] + 1 ])
273+ return [value [0 ] + value [1 ] + 1 ]
274274 else :
275275 self .retries_1 [value ] = True
276- result_future . complete_exceptionally ( ValueError ("failed the first time" ) )
276+ raise ValueError ("failed the first time" )
277277
278- def timeout (self , value : Row , result_future : ResultFuture [ int ] ):
279- result_future . complete ( [value [0 ] + value [1 ]])
278+ def timeout (self , value : Row ):
279+ return [value [0 ] + value [1 ]]
280280
281281 def result_predicate (result : List [int ]):
282282 return result [0 ] % 2 == 1
@@ -312,9 +312,9 @@ def test_run_async_function_in_thread_mode(self):
312312
313313 class MyAsyncFunction (AsyncFunction ):
314314
315- async def async_invoke (self , value : Row , result_future : ResultFuture [ int ] ):
315+ async def async_invoke (self , value : Row ):
316316 await asyncio .sleep (2 )
317- result_future . complete ( [value [0 ] + value [1 ]])
317+ return [value [0 ] + value [1 ]]
318318
319319 try :
320320 AsyncDataStream .unordered_wait (
0 commit comments