本文整理匯總了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)