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


Python TRequestsTransport.close方法代码示例

本文整理汇总了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()
开发者ID:kevints,项目名称:aurora,代码行数:27,代码来源:test_transport.py

示例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()
开发者ID:KancerEzeroglu,项目名称:aurora,代码行数:14,代码来源:test_transport.py

示例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()
开发者ID:KancerEzeroglu,项目名称:aurora,代码行数:16,代码来源:test_transport.py

示例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()
开发者ID:easyfmxu,项目名称:aurora,代码行数:18,代码来源:test_transport.py

示例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()
开发者ID:kevints,项目名称:aurora,代码行数:19,代码来源:test_transport.py

示例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()
开发者ID:easyfmxu,项目名称:aurora,代码行数:21,代码来源:test_transport.py

示例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))
开发者ID:easyfmxu,项目名称:aurora,代码行数:21,代码来源:test_transport.py

示例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()
开发者ID:apache,项目名称:aurora,代码行数:24,代码来源:test_transport.py


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