Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RRIO][Python] Add python grpc binding for mock API #29129

Merged
merged 8 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .test-infra/mock-apis/buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ plugins:
- name: java
out: src/main/java
- name: grpc-java
out: src/main/java
out: src/main/java
- plugin: buf.build/protocolbuffers/python:v24.4
out: src/main/python
- plugin: buf.build/grpc/python:v1.59.1
out: src/main/python
47 changes: 47 additions & 0 deletions .test-infra/mock-apis/src/main/python/proto/echo/v1/echo_pb2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: proto/echo/v1/echo.proto
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()




DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x18proto/echo/v1/echo.proto\x12\rproto.echo.v1\"7\n\x0b\x45\x63hoRequest\x12\x0e\n\x02id\x18\x01 \x01(\tR\x02id\x12\x18\n\x07payload\x18\x02 \x01(\x0cR\x07payload\"8\n\x0c\x45\x63hoResponse\x12\x0e\n\x02id\x18\x01 \x01(\tR\x02id\x12\x18\n\x07payload\x18\x02 \x01(\x0cR\x07payload2P\n\x0b\x45\x63hoService\x12\x41\n\x04\x45\x63ho\x12\x1a.proto.echo.v1.EchoRequest\x1a\x1b.proto.echo.v1.EchoResponse\"\x00\x42;\n*org.apache.beam.testinfra.mockapis.echo.v1Z\rproto/echo/v1b\x06proto3')

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'proto.echo.v1.echo_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
_globals['DESCRIPTOR']._options = None
_globals['DESCRIPTOR']._serialized_options = b'\n*org.apache.beam.testinfra.mockapis.echo.v1Z\rproto/echo/v1'
_globals['_ECHOREQUEST']._serialized_start=43
_globals['_ECHOREQUEST']._serialized_end=98
_globals['_ECHORESPONSE']._serialized_start=100
_globals['_ECHORESPONSE']._serialized_end=156
_globals['_ECHOSERVICE']._serialized_start=158
_globals['_ECHOSERVICE']._serialized_end=238
# @@protoc_insertion_point(module_scope)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

from proto.echo.v1 import echo_pb2 as proto_dot_echo_dot_v1_dot_echo__pb2


class EchoServiceStub(object):
"""EchoService simulates a mock API that echos a request.
"""

def __init__(self, channel):
"""Constructor.

Args:
channel: A grpc.Channel.
"""
self.Echo = channel.unary_unary(
'/proto.echo.v1.EchoService/Echo',
request_serializer=proto_dot_echo_dot_v1_dot_echo__pb2.EchoRequest.SerializeToString,
response_deserializer=proto_dot_echo_dot_v1_dot_echo__pb2.EchoResponse.FromString,
)


class EchoServiceServicer(object):
"""EchoService simulates a mock API that echos a request.
"""

def Echo(self, request, context):
"""Echo an EchoRequest payload in an EchoResponse.
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_EchoServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'Echo': grpc.unary_unary_rpc_method_handler(
servicer.Echo,
request_deserializer=proto_dot_echo_dot_v1_dot_echo__pb2.EchoRequest.FromString,
response_serializer=proto_dot_echo_dot_v1_dot_echo__pb2.EchoResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'proto.echo.v1.EchoService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))


# This class is part of an EXPERIMENTAL API.
class EchoService(object):
"""EchoService simulates a mock API that echos a request.
"""

@staticmethod
def Echo(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/proto.echo.v1.EchoService/Echo',
proto_dot_echo_dot_v1_dot_echo__pb2.EchoRequest.SerializeToString,
proto_dot_echo_dot_v1_dot_echo__pb2.EchoResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)