@@ -251,3 +251,203 @@ async def wait(fut):
251251
252252 await reader0 .close ()
253253 await reader1 .close ()
254+
255+
256+ @pytest .mark .asyncio
257+ class TestTopicNoConsumerReaderAsyncIO :
258+ async def test_reader_with_no_partition_ids_raises (self , driver , topic_with_messages ):
259+ with pytest .raises (ydb .Error ):
260+ driver .topic_client .reader (
261+ topic_with_messages ,
262+ consumer = None ,
263+ )
264+
265+ async def test_reader_with_default_lambda (self , driver , topic_with_messages ):
266+ reader = driver .topic_client .reader (
267+ topic_with_messages ,
268+ consumer = None ,
269+ partition_ids = [0 ],
270+ )
271+ msg = await reader .receive_message ()
272+
273+ assert msg .seqno == 1
274+
275+ await reader .close ()
276+
277+ async def test_reader_with_sync_lambda (self , driver , topic_with_messages ):
278+ def sync_lambda (partition_id : int ):
279+ assert partition_id == 0
280+ return 1
281+
282+ reader = driver .topic_client .reader (
283+ topic_with_messages ,
284+ consumer = None ,
285+ partition_ids = [0 ],
286+ get_start_offset_lambda = sync_lambda ,
287+ )
288+ msg = await reader .receive_message ()
289+
290+ assert msg .seqno == 2
291+
292+ await reader .close ()
293+
294+ async def test_reader_with_async_lambda (self , driver , topic_with_messages ):
295+ async def async_lambda (partition_id : int ) -> int :
296+ assert partition_id == 0
297+ return 1
298+
299+ reader = driver .topic_client .reader (
300+ topic_with_messages ,
301+ consumer = None ,
302+ partition_ids = [0 ],
303+ get_start_offset_lambda = async_lambda ,
304+ )
305+ msg = await reader .receive_message ()
306+
307+ assert msg .seqno == 2
308+
309+ await reader .close ()
310+
311+ async def test_commit_not_allowed (self , driver , topic_with_messages ):
312+ reader = driver .topic_client .reader (
313+ topic_with_messages ,
314+ consumer = None ,
315+ partition_ids = [0 ],
316+ )
317+ batch = await reader .receive_batch ()
318+
319+ with pytest .raises (ydb .Error ):
320+ reader .commit (batch )
321+
322+ with pytest .raises (ydb .Error ):
323+ await reader .commit_with_ack (batch )
324+
325+ await reader .close ()
326+
327+ async def test_offsets_updated_after_reconnect (self , driver , topic_with_messages ):
328+ current_offset = 0
329+
330+ def get_start_offset_lambda (partition_id : int ) -> int :
331+ nonlocal current_offset
332+ return current_offset
333+
334+ reader = driver .topic_client .reader (
335+ topic_with_messages ,
336+ consumer = None ,
337+ partition_ids = [0 ],
338+ get_start_offset_lambda = get_start_offset_lambda ,
339+ )
340+ msg = await reader .receive_message ()
341+
342+ assert msg .seqno == current_offset + 1
343+
344+ current_offset += 2
345+ reader ._reconnector ._stream_reader ._set_first_error (ydb .Unavailable ("some retriable error" ))
346+
347+ await asyncio .sleep (0 )
348+
349+ msg = await reader .receive_message ()
350+
351+ assert msg .seqno == current_offset + 1
352+
353+ await reader .close ()
354+
355+
356+ class TestTopicReaderWithoutConsumer :
357+ def test_reader_with_no_partition_ids_raises (self , driver_sync , topic_with_messages ):
358+ with pytest .raises (ydb .Error ):
359+ driver_sync .topic_client .reader (
360+ topic_with_messages ,
361+ consumer = None ,
362+ )
363+
364+ def test_reader_with_default_lambda (self , driver_sync , topic_with_messages ):
365+ reader = driver_sync .topic_client .reader (
366+ topic_with_messages ,
367+ consumer = None ,
368+ partition_ids = [0 ],
369+ )
370+ msg = reader .receive_message ()
371+
372+ assert msg .seqno == 1
373+
374+ reader .close ()
375+
376+ def test_reader_with_sync_lambda (self , driver_sync , topic_with_messages ):
377+ def sync_lambda (partition_id : int ):
378+ assert partition_id == 0
379+ return 1
380+
381+ reader = driver_sync .topic_client .reader (
382+ topic_with_messages ,
383+ consumer = None ,
384+ partition_ids = [0 ],
385+ get_start_offset_lambda = sync_lambda ,
386+ )
387+ msg = reader .receive_message ()
388+
389+ assert msg .seqno == 2
390+
391+ reader .close ()
392+
393+ def test_reader_with_async_lambda (self , driver_sync , topic_with_messages ):
394+ async def async_lambda (partition_id : int ) -> int :
395+ assert partition_id == 0
396+ return 1
397+
398+ reader = driver_sync .topic_client .reader (
399+ topic_with_messages ,
400+ consumer = None ,
401+ partition_ids = [0 ],
402+ get_start_offset_lambda = async_lambda ,
403+ )
404+ msg = reader .receive_message ()
405+
406+ assert msg .seqno == 2
407+
408+ reader .close ()
409+
410+ def test_commit_not_allowed (self , driver_sync , topic_with_messages ):
411+ reader = driver_sync .topic_client .reader (
412+ topic_with_messages ,
413+ consumer = None ,
414+ partition_ids = [0 ],
415+ )
416+ batch = reader .receive_batch ()
417+
418+ with pytest .raises (ydb .Error ):
419+ reader .commit (batch )
420+
421+ with pytest .raises (ydb .Error ):
422+ reader .commit_with_ack (batch )
423+
424+ with pytest .raises (ydb .Error ):
425+ reader .async_commit_with_ack (batch )
426+
427+ reader .close ()
428+
429+ def test_offsets_updated_after_reconnect (self , driver_sync , topic_with_messages ):
430+ current_offset = 0
431+
432+ def get_start_offset_lambda (partition_id : int ) -> int :
433+ nonlocal current_offset
434+ return current_offset
435+
436+ reader = driver_sync .topic_client .reader (
437+ topic_with_messages ,
438+ consumer = None ,
439+ partition_ids = [0 ],
440+ get_start_offset_lambda = get_start_offset_lambda ,
441+ )
442+ msg = reader .receive_message ()
443+
444+ assert msg .seqno == current_offset + 1
445+
446+ current_offset += 2
447+ reader ._async_reader ._reconnector ._stream_reader ._set_first_error (ydb .Unavailable ("some retriable error" ))
448+
449+ msg = reader .receive_message ()
450+
451+ assert msg .seqno == current_offset + 1
452+
453+ reader .close ()
0 commit comments