コード例 #1
0
 async def _test_unary_stream(request, context):
     assert _REQUEST == request
     assert _common.seen_metadata(_INITIAL_METADATA_FROM_CLIENT_TO_SERVER,
                                  context.invocation_metadata())
     await context.send_initial_metadata(
         _INITIAL_METADATA_FROM_SERVER_TO_CLIENT)
     yield _RESPONSE
     context.set_trailing_metadata(_TRAILING_METADATA)
コード例 #2
0
    async def _test_stream_unary(request_iterator, context):
        assert _common.seen_metadata(_INITIAL_METADATA_FROM_CLIENT_TO_SERVER,
                                     context.invocation_metadata())
        await context.send_initial_metadata(
            _INITIAL_METADATA_FROM_SERVER_TO_CLIENT)

        async for request in request_iterator:
            assert _REQUEST == request

        context.set_trailing_metadata(_TRAILING_METADATA)
        return _RESPONSE
コード例 #3
0
    async def test_stream_stream(self):
        multicallable = self._client.stream_stream(_TEST_STREAM_STREAM)
        call = multicallable(metadata=_INITIAL_METADATA_FROM_CLIENT_TO_SERVER)
        await call.write(_REQUEST)
        await call.done_writing()

        self.assertTrue(
            _common.seen_metadata(_INITIAL_METADATA_FROM_SERVER_TO_CLIENT,
                                  await call.initial_metadata()))
        self.assertSequenceEqual([_RESPONSE],
                                 [request async for request in call])
        self.assertEqual(_TRAILING_METADATA, await call.trailing_metadata())
        self.assertEqual(grpc.StatusCode.OK, await call.code())
コード例 #4
0
ファイル: compatibility_test.py プロジェクト: yishuT/grpc
    async def test_sync_unary_unary_metadata(self):
        metadata = (('unique', 'key-42'),)

        @grpc.unary_unary_rpc_method_handler
        def metadata_unary_unary(request: bytes, context: grpc.ServicerContext):
            context.send_initial_metadata(metadata)
            return request

        self._adhoc_handlers.set_adhoc_handler(metadata_unary_unary)
        call = self._async_channel.unary_unary(_common.ADHOC_METHOD)(_REQUEST)
        self.assertTrue(
            _common.seen_metadata(aio.Metadata(*metadata), await
                                  call.initial_metadata()))
コード例 #5
0
 async def _test_client_to_server(request, context):
     assert _REQUEST == request
     assert _common.seen_metadata(_INITIAL_METADATA_FROM_CLIENT_TO_SERVER,
                                  context.invocation_metadata())
     return _RESPONSE
コード例 #6
0
 def service(self, handler_call_details):
     assert _common.seen_metadata(_INITIAL_METADATA_FOR_GENERIC_HANDLER,
                                  handler_call_details.invocation_metadata)
     return grpc.unary_unary_rpc_method_handler(self._method)