当前位置: 首页>>代码示例>>Python>>正文


Python ResponseFuture._query_retries方法代码示例

本文整理汇总了Python中cassandra.cluster.ResponseFuture._query_retries方法的典型用法代码示例。如果您正苦于以下问题:Python ResponseFuture._query_retries方法的具体用法?Python ResponseFuture._query_retries怎么用?Python ResponseFuture._query_retries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cassandra.cluster.ResponseFuture的用法示例。


在下文中一共展示了ResponseFuture._query_retries方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_unavailable_error_message

# 需要导入模块: from cassandra.cluster import ResponseFuture [as 别名]
# 或者: from cassandra.cluster.ResponseFuture import _query_retries [as 别名]
    def test_unavailable_error_message(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)

        rf = ResponseFuture(session, message, query, 1)
        rf._query_retries = 1
        rf.send_request()

        result = Mock(spec=UnavailableErrorMessage, info={"required_replicas":2, "alive_replicas": 1, "consistency": 1})
        rf._set_result(None, None, None, result)
        self.assertRaises(Exception, rf.result)
开发者ID:joaquincasares,项目名称:python-driver,代码行数:16,代码来源:test_response_future.py

示例2: test_errback

# 需要导入模块: from cassandra.cluster import ResponseFuture [as 别名]
# 或者: from cassandra.cluster.ResponseFuture import _query_retries [as 别名]
    def test_errback(self):
        session = self.make_session()
        pool = session._pools.get.return_value
        connection = Mock(spec=Connection)
        pool.borrow_connection.return_value = (connection, 1)

        query = SimpleStatement("INSERT INFO foo (a, b) VALUES (1, 2)")
        message = QueryMessage(query=query, consistency_level=ConsistencyLevel.ONE)

        rf = ResponseFuture(session, message, query, 1)
        rf._query_retries = 1
        rf.send_request()

        rf.add_errback(self.assertIsInstance, Exception)

        result = Mock(spec=UnavailableErrorMessage, info={"required_replicas":2, "alive_replicas": 1, "consistency": 1})
        result.to_exception.return_value = Exception()

        rf._set_result(None, None, None, result)
        self.assertRaises(Exception, rf.result)

        # this should get called immediately now that the error is set
        rf.add_errback(self.assertIsInstance, Exception)
开发者ID:joaquincasares,项目名称:python-driver,代码行数:25,代码来源:test_response_future.py

示例3: test_add_callbacks

# 需要导入模块: from cassandra.cluster import ResponseFuture [as 别名]
# 或者: from cassandra.cluster.ResponseFuture import _query_retries [as 别名]
    def test_add_callbacks(self):
        session = self.make_session()
        query = SimpleStatement("INSERT INFO foo (a, b) VALUES (1, 2)")
        message = QueryMessage(query=query, consistency_level=ConsistencyLevel.ONE)

        # test errback
        rf = ResponseFuture(session, message, query, 1)
        rf._query_retries = 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={"required_replicas":2, "alive_replicas": 1, "consistency": 1})
        result.to_exception.return_value = Exception()
        rf._set_result(None, None, None, 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(None, None, None, self.make_mock_response(expected_result))
        self.assertEqual(rf.result(), expected_result)

        callback.assert_called_once_with(expected_result, arg, **kwargs)
开发者ID:joaquincasares,项目名称:python-driver,代码行数:38,代码来源:test_response_future.py


注:本文中的cassandra.cluster.ResponseFuture._query_retries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。