本文整理汇总了Python中apache.aurora.common.transport.TRequestsTransport.close方法的典型用法代码示例。如果您正苦于以下问题:Python TRequestsTransport.close方法的具体用法?Python TRequestsTransport.close怎么用?Python TRequestsTransport.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apache.aurora.common.transport.TRequestsTransport
的用法示例。
在下文中一共展示了TRequestsTransport.close方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_request_transport_integration
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_request_transport_integration():
handler = ReadOnlySchedulerHandler()
processor = ReadOnlyScheduler.Processor(handler)
pfactory = TJSONProtocol.TJSONProtocolFactory()
server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
server_thread = Thread(target=server.serve)
server_thread.start()
_, server_port = server.httpd.socket.getsockname()
response = None
try:
transport = TRequestsTransport('http://localhost:%d' % server_port)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
response = client.getRoleSummary()
finally:
server.httpd.shutdown()
assert response is not None
assert response.responseCode == ResponseCode.OK
assert response.serverInfo.clusterName == 'west'
assert response.serverInfo.thriftAPIVersion == 3
transport.close()
示例2: test_request_any_other_exception
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_request_any_other_exception():
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post = Mock(side_effect=request_exceptions.ConnectionError())
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException):
client.getRoleSummary()
transport.close()
示例3: test_request_transport_timeout
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_request_transport_timeout():
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post = Mock(side_effect=request_exceptions.Timeout())
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException) as execinfo:
client.getRoleSummary()
assert execinfo.value.message == 'Timed out talking to http://localhost:12345'
transport.close()
示例4: test_raises_auth_error
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_raises_auth_error():
response = requests.Response()
response.status_code = 401
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post.return_value = response
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TRequestsTransport.AuthError):
client.getRoleSummary()
transport.close()
示例5: test_request_any_other_exception
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_request_any_other_exception():
session = mock.MagicMock(spec=requests.Session)
session.headers = {}
session.post = mock.Mock(side_effect=request_exceptions.ConnectionError())
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
try:
client.getRoleSummary()
assert False, 'getRoleSummary should not succeed'
except TTransport.TTransportException:
pass
except Exception as e:
assert False, 'Only expected TTransportException, got %s' % e
transport.close()
示例6: test_raise_for_status_causes_exception
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_raise_for_status_causes_exception():
response = requests.Response()
response.status_code = 503
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post.return_value = response
transport = TRequestsTransport('http://localhost:12345', session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException) as excinfo:
client.getRoleSummary()
assert excinfo.value.type == TTransport.TTransportException.UNKNOWN
assert excinfo.value.message.startswith('Unknown error talking to http://localhost:12345')
transport.close()
示例7: test_auth_type_valid
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_auth_type_valid():
response = requests.Response()
response.status_code = 500
session = create_autospec(spec=requests.Session, instance=True)
session.headers = {}
session.post.return_value = response
auth = requests.auth.AuthBase()
transport = TRequestsTransport('http://localhost:1', auth=auth, session_factory=lambda: session)
protocol = TJSONProtocol.TJSONProtocol(transport)
client = ReadOnlyScheduler.Client(protocol)
with pytest.raises(TTransport.TTransportException):
client.getRoleSummary()
transport.close()
session.post.mock_calls = (call(ANY, data=ANY, timeout=ANY, auth=auth))
示例8: test_requests_transport_session_reuse
# 需要导入模块: from apache.aurora.common.transport import TRequestsTransport [as 别名]
# 或者: from apache.aurora.common.transport.TRequestsTransport import close [as 别名]
def test_requests_transport_session_reuse():
handler = ReadOnlySchedulerHandler()
processor = ReadOnlyScheduler.Processor(handler)
pfactory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory()
server = THttpServer.THttpServer(processor, ('localhost', 0), pfactory)
server_thread = Thread(target=server.serve)
server_thread.start()
_, server_port = server.httpd.socket.getsockname()
try:
transport = TRequestsTransport('http://localhost:%d' % server_port)
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
client = ReadOnlyScheduler.Client(protocol)
client.getRoleSummary()
old_session = transport._session
client.getRoleSummary()
finally:
server.httpd.shutdown()
assert old_session == transport._session
transport.close()