# Copyright 2023 Google LLC # # Licensed 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. """ The Python implementation of the `cloud-bigtable-clients-test` proxy server. https://github.com/googleapis/cloud-bigtable-clients-test This server is intended to be used to test the correctness of Bigtable clients across languages. Contributor Note: the proxy implementation is split across TestProxyClientHandler and TestProxyGrpcServer. This is due to the fact that generated protos and proto-plus objects cannot be used in the same process, so we had to make use of the multiprocessing module to allow them to work together. """ import multiprocessing import argparse import sys import os sys.path.append("handlers") def grpc_server_process(request_q, queue_pool, port=50055): """ Defines a process that hosts a grpc server proxies requests to a client_handler_process """ sys.path.append("protos") from concurrent import futures import grpc import test_proxy_pb2_grpc import grpc_handler # Start gRPC server server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) test_proxy_pb2_grpc.add_CloudBigtableV2TestProxyServicer_to_server( grpc_handler.TestProxyGrpcServer(request_q, queue_pool), server ) server.add_insecure_port("[::]:" + port) server.start() print("grpc_server_process started, listening on " + port) server.wait_for_termination() async def client_handler_process_async(request_q, queue_pool, client_type="async"): """ Defines a process that recives Bigtable requests from a grpc_server_process, and runs the request using a client library instance """ import base64 import re import asyncio import warnings import client_handler_data_async warnings.filterwarnings("ignore", category=RuntimeWarning, message=".*Bigtable emulator.*") def camel_to_snake(str): return re.sub(r"(?