本文整理汇总了Python中cassandra.cluster.ResponseFuture.add_callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python ResponseFuture.add_callbacks方法的具体用法?Python ResponseFuture.add_callbacks怎么用?Python ResponseFuture.add_callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.cluster.ResponseFuture
的用法示例。
在下文中一共展示了ResponseFuture.add_callbacks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_callbacks
# 需要导入模块: from cassandra.cluster import ResponseFuture [as 别名]
# 或者: from cassandra.cluster.ResponseFuture import add_callbacks [as 别名]
def test_add_callbacks(self):
session = self.make_session()
query = SimpleStatement("INSERT INFO foo (a, b) VALUES (1, 2)")
query.retry_policy = Mock()
query.retry_policy.on_unavailable.return_value = (RetryPolicy.RETHROW, None)
message = QueryMessage(query=query, consistency_level=ConsistencyLevel.ONE)
# test errback
rf = ResponseFuture(session, message, query)
rf.send_request()
rf.add_callbacks(
callback=self.assertEquals, callback_args=([{'col': 'val'}],),
errback=self.assertIsInstance, errback_args=(Exception,))
result = Mock(spec=UnavailableErrorMessage, info={})
rf._set_result(result)
self.assertRaises(Exception, rf.result)
# test callback
rf = ResponseFuture(session, message, query)
rf.send_request()
rf.add_callbacks(
callback=self.assertEquals, callback_args=([{'col': 'val'}],),
errback=self.assertIsInstance, errback_args=(Exception,))
response = Mock(spec=ResultMessage, kind=ResultMessage.KIND_ROWS, results=[{'col': 'val'}])
rf._set_result(response)
self.assertEqual(rf.result(), [{'col': 'val'}])
示例2: test_add_callbacks
# 需要导入模块: from cassandra.cluster import ResponseFuture [as 别名]
# 或者: from cassandra.cluster.ResponseFuture import add_callbacks [as 别名]
def test_add_callbacks(self):
session = self.make_session()
query = SimpleStatement("INSERT INFO foo (a, b) VALUES (1, 2)")
query.retry_policy = Mock()
query.retry_policy.on_unavailable.return_value = (RetryPolicy.RETHROW, None)
message = QueryMessage(query=query, consistency_level=ConsistencyLevel.ONE)
# test errback
rf = ResponseFuture(session, message, query, 1)
rf.send_request()
rf.add_callbacks(
callback=self.assertEqual, callback_args=([{'col': 'val'}],),
errback=self.assertIsInstance, errback_args=(Exception,))
result = Mock(spec=UnavailableErrorMessage, info={})
rf._set_result(result)
self.assertRaises(Exception, rf.result)
# test callback
rf = ResponseFuture(session, message, query, 1)
rf.send_request()
callback = Mock()
expected_result = [{'col': 'val'}]
arg = "positional"
kwargs = {'one': 1, 'two': 2}
rf.add_callbacks(
callback=callback, callback_args=(arg,), callback_kwargs=kwargs,
errback=self.assertIsInstance, errback_args=(Exception,))
rf._set_result(self.make_mock_response(expected_result))
self.assertEqual(rf.result(), expected_result)
callback.assert_called_once_with(expected_result, arg, **kwargs)