本文整理汇总了Python中tchannel.TChannel.raw方法的典型用法代码示例。如果您正苦于以下问题:Python TChannel.raw方法的具体用法?Python TChannel.raw怎么用?Python TChannel.raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tchannel.TChannel
的用法示例。
在下文中一共展示了TChannel.raw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_writer_multiplexing
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_writer_multiplexing():
server = TChannel('server')
server.listen()
received = {'chunked': False, 'singleframe': False}
@server.raw.register('chunked')
def chunked(request):
received['chunked'] = True
return b'chunked'
@server.raw.register('singleframe')
def singleframe(request):
received['singleframe'] = True
return b'singleframe'
client = TChannel('client')
chunked_future = client.raw(
'server', 'chunked',
bytes([0x00] * 1024 * 1024), # 1 MB = 16 frames
hostport=server.hostport,
timeout=0.5,
)
yield client.raw(
'server', 'singleframe', b'\x00', # single frame
hostport=server.hostport,
)
assert received['singleframe']
assert not received['chunked']
yield chunked_future
assert received['chunked']
示例2: test_connection_close
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_connection_close(mock_server):
tchannel = TChannel(name="test")
# use a bad call to finish the hand shake and build the connection.
with pytest.raises(BadRequestError):
yield tchannel.raw(service="test-service", hostport=mock_server.hostport, endpoint="testg")
# close the server and close the connection.
mock_server.tchannel._dep_tchannel.close()
with pytest.raises(NetworkError):
yield tchannel.raw(service="test-service", hostport=mock_server.hostport, endpoint="testg")
示例3: test_timeout_during_handshake_is_retried
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_timeout_during_handshake_is_retried(timeout_server):
tchannel = TChannel(name='client', known_peers=[timeout_server])
# We want the client to look for other peers if an INIT times out rather
# than raising a timeout error so we expect a NoAvailablePeerError here.
with patch.object(connection, 'DEFAULT_INIT_TIMEOUT_SECS', 0.1):
with pytest.raises(errors.NoAvailablePeerError):
yield tchannel.raw(service='server', endpoint='endpoint')
示例4: test_timeout_should_raise_timeout_error
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_timeout_should_raise_timeout_error():
# Given this test server:
server = TChannel(name='server')
@server.register(scheme=schemes.RAW)
@gen.coroutine
def endpoint(request):
yield gen.sleep(0.05)
raise gen.Return('hello')
server.listen()
# Make a call:
tchannel = TChannel(name='client')
# timeout is less than server, should timeout
with pytest.raises(TimeoutError):
yield tchannel.call(
scheme=schemes.RAW,
service='server',
arg1='endpoint',
hostport=server.hostport,
timeout=0.02,
)
# timeout is more than server, should not timeout
yield tchannel.raw(
service='server',
endpoint='endpoint',
hostport=server.hostport,
timeout=0.1,
)
示例5: test_local_timeout_unconsumed_message
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_local_timeout_unconsumed_message():
"""Verify that if the client has a local timeout and the server eventually
sends the message, the client does not log an "Unconsumed message"
warning.
"""
server = TChannel('server')
@server.raw.register('hello')
@gen.coroutine
def hello(request):
yield gen.sleep(0.07)
raise gen.Return('eventual response')
server.listen()
client = TChannel('client')
with pytest.raises(TimeoutError):
yield client.raw(
'server', 'hello', 'world',
timeout=0.05, hostport=server.hostport,
# The server will take 70 milliseconds but we allow at most 50.
)
# Wait for the server to send the late response and make sure it doesn't
# log a warning.
with mock.patch.object(connection.log, 'warn') as mock_warn: # :(
yield gen.sleep(0.03)
assert mock_warn.call_count == 0
示例6: test_client_connection_change_callback
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_client_connection_change_callback():
server = TChannel('server')
server.listen()
@server.raw.register
def hello(request):
return 'hi'
client = TChannel('client')
count = [0]
def test_cb(peer):
count[0] += 1
client._dep_tchannel.peers.get(
server.hostport)._on_conn_change_cb = test_cb
yield client.raw(
hostport=server.hostport,
body='work',
endpoint='hello',
service='server'
)
# 1: connection built, 1: sending request, 1: finish sending request
assert count[0] == 3
示例7: test_no_infinite_trace_submit
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_no_infinite_trace_submit():
"""Zipkin submissions must not trace themselves."""
def submit(request):
return TResponse(True)
zipkin_server = TChannel('zipkin')
zipkin_server.thrift.register(TCollector, handler=submit)
zipkin_server.listen()
class TestTraceHook(EventHook):
def __init__(self):
self.tracings = []
def before_send_request(self, request):
# if request.service == 'tcollector':
self.tracings.append(request.tracing)
server = TChannel('server', known_peers=[zipkin_server.hostport])
server.hooks.register(ZipkinTraceHook(tchannel=server, sample_rate=1))
test_trace_hook = TestTraceHook()
server.hooks.register(test_trace_hook)
server.thrift.register(TCollector, handler=submit)
@server.raw.register
@tornado.gen.coroutine
def hello(request):
if request.body == 'body':
yield server.raw(
service='server',
endpoint='hello',
body='boy',
hostport=server.hostport,
trace=True,
)
raise tornado.gen.Return('hello')
server.listen()
client = TChannel('client')
client.thrift.register(TCollector, handler=submit)
yield client.raw(
service='server',
endpoint='hello',
hostport=server.hostport,
body='body',
trace=True,
)
# Continue yielding to the IO loop to allow our zipkin traces to be
# handled.
for _ in xrange(100):
yield tornado.gen.moment
# One trace for 'hello' and then 3 submissions to tcollector (1 time as
# client, 2 times as server)
assert len(test_trace_hook.tracings) == 4, test_trace_hook.tracings
示例8: test_endpoint_not_found
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_endpoint_not_found(mock_server):
tchannel = TChannel(name='test')
with pytest.raises(BadRequestError):
yield tchannel.raw(
service='test-server',
endpoint='fooo',
hostport=mock_server.hostport,
)
示例9: test_pending_outgoing
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_pending_outgoing():
server = TChannel('server')
server.listen()
@server.raw.register
def hello(request):
assert server._dep_tchannel.peers.peers[0].total_outbound_pendings == 1
return 'hi'
client = TChannel('client')
yield client.raw(
hostport=server.hostport,
body='work',
endpoint='hello',
service='server'
)
client_peer = client._dep_tchannel.peers.peers[0]
server_peer = server._dep_tchannel.peers.peers[0]
assert client_peer.total_outbound_pendings == 0
assert server_peer.total_outbound_pendings == 0
class FakeMessageFactory(MessageFactory):
def build_raw_message(self, context, args, is_completed=True):
assert client_peer.total_outbound_pendings == 1
return super(FakeMessageFactory, self).build_raw_message(
context, args, is_completed,
)
client_conn = client_peer.connections[0]
client_conn.request_message_factory = FakeMessageFactory(
client_conn.remote_host,
client_conn.remote_host_port,
)
yield client.raw(
hostport=server.hostport,
body='work',
endpoint='hello',
service='server'
)
assert client_peer.total_outbound_pendings == 0
assert server_peer.total_outbound_pendings == 0
示例10: test_routing_delegate_is_propagated_raw
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_routing_delegate_is_propagated_raw():
server = TChannel('server')
server.listen()
@server.raw.register('foo')
def handler(request):
assert request.transport.routing_delegate == 'delegate'
return b'success'
client = TChannel('client', known_peers=[server.hostport])
res = yield client.raw('service', 'foo', b'', routing_delegate='delegate')
assert res.body == b'success'
示例11: test_per_request_caller_name_raw
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_per_request_caller_name_raw():
server = TChannel('server')
server.listen()
@server.raw.register('foo')
def handler(request):
assert request.transport.caller_name == 'bar'
return b'success'
client = TChannel('client', known_peers=[server.hostport])
res = yield client.raw('service', 'foo', b'', caller_name='bar')
assert res.body == b'success'
示例12: test_endpoint_not_found
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_endpoint_not_found():
server = TChannel(name='server')
server.listen()
tchannel = TChannel(name='client')
with pytest.raises(errors.BadRequestError):
yield tchannel.raw(
service='server',
hostport=server.hostport,
endpoint='foo',
)
示例13: test_endpoint_not_found_with_raw_request
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_endpoint_not_found_with_raw_request():
server = TChannel(name='server')
server.listen()
tchannel = TChannel(name='client')
with pytest.raises(errors.BadRequestError) as e:
yield tchannel.raw(
service='server',
hostport=server.hostport,
endpoint='foo',
)
assert "Endpoint 'foo' is not defined" in e.value
示例14: test_tchannel_call_request_fragment
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_tchannel_call_request_fragment(mock_server, arg2, arg3):
endpoint = b"tchannelpeertest"
mock_server.expect_call(endpoint).and_write(headers=endpoint, body=arg3)
tchannel = TChannel(name="test")
response = yield tchannel.raw(
service="test-service", hostport=mock_server.hostport, endpoint=endpoint, headers=arg2, body=arg3
)
assert response.headers == endpoint
assert response.body == arg3
assert response.transport.scheme == "raw"
示例15: test_span_to_trace
# 需要导入模块: from tchannel import TChannel [as 别名]
# 或者: from tchannel.TChannel import raw [as 别名]
def test_span_to_trace(tracer, mock_server):
"""
In this test we verify that if the tracer implementation supports the
notions of trace_id, span_id, parent_id (similar to Zipkin) then we can
pass those IDs not just via the headers (primary OpenTracing propagation
mechanism), but also via TChannel's built-in tracing slot in the frame.
:param tracer: injected BasicTracer mixin
:param mock_server: injected TChannel mock server
"""
def span_to_trace(span):
return {
'trace_id': span.context.trace_id,
'span_id': span.context.span_id,
'parent_span_id': span.context.parent_id,
}
context_provider = OpenTracingRequestContextProvider()
hook = OpenTracingHook(tracer=tracer, context_provider=context_provider,
span_to_trace_fn=span_to_trace)
@mock_server.tchannel.raw.register('endpoint1')
@tornado.gen.coroutine
def handler1(request):
ctx = mock_server.tchannel.context_provider.get_current_context()
if hasattr(ctx, 'parent_tracing'):
res = ctx.parent_tracing.trace_id
else:
res = 'unknown'
raise tornado.gen.Return(Response('%s' % res))
tchannel = TChannel(name='test', context_provider=context_provider)
tchannel.hooks.register(hook)
with mock.patch('opentracing.tracer', tracer):
assert opentracing.tracer == tracer # sanity check that patch worked
span = tracer.start_span('root')
with span: # use span as context manager so that it's always finished
wrapper = SpanWrapper(span=span)
with context_provider.request_context(wrapper):
response_future = tchannel.raw(
service='test-client',
hostport=mock_server.hostport,
endpoint='endpoint1',
headers=mock_server.hostport,
trace=False,
)
response = yield response_future
assert span.context.trace_id == long(response.body)