本文整理汇总了Python中aiokafka.producer.AIOKafkaProducer.abort_transaction方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaProducer.abort_transaction方法的具体用法?Python AIOKafkaProducer.abort_transaction怎么用?Python AIOKafkaProducer.abort_transaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.producer.AIOKafkaProducer
的用法示例。
在下文中一共展示了AIOKafkaProducer.abort_transaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_producer_transactional_cancel_txn_methods
# 需要导入模块: from aiokafka.producer import AIOKafkaProducer [as 别名]
# 或者: from aiokafka.producer.AIOKafkaProducer import abort_transaction [as 别名]
async def test_producer_transactional_cancel_txn_methods(self):
producer = AIOKafkaProducer(
loop=self.loop, bootstrap_servers=self.hosts,
transactional_id="sobaka_producer", client_id="p1")
txn_manager = producer._txn_manager
self.assertEqual(txn_manager.state, TransactionState.UNINITIALIZED)
await producer.start()
self.add_cleanup(producer.stop)
self.assertEqual(txn_manager.state, TransactionState.READY)
async def cancel(task):
# Coroutines will not be started until we yield at least 1ce
await asyncio.sleep(0)
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
# test cancel begin_transaction.
task = ensure_future(producer.begin_transaction())
await cancel(task)
self.assertEqual(txn_manager.state, TransactionState.READY)
# test cancel commit_transaction. Commit should not be cancelled.
await producer.begin_transaction()
self.assertEqual(txn_manager.state, TransactionState.IN_TRANSACTION)
task = ensure_future(producer.commit_transaction())
await cancel(task)
self.assertEqual(
txn_manager.state, TransactionState.COMMITTING_TRANSACTION)
await asyncio.sleep(0.1)
self.assertEqual(txn_manager.state, TransactionState.READY)
# test cancel abort_transaction. Abort should also not be cancelled.
await producer.begin_transaction()
self.assertEqual(txn_manager.state, TransactionState.IN_TRANSACTION)
task = ensure_future(producer.abort_transaction())
await cancel(task)
self.assertEqual(
txn_manager.state, TransactionState.ABORTING_TRANSACTION)
await asyncio.sleep(0.1)
self.assertEqual(txn_manager.state, TransactionState.READY)