dianfu commented on a change in pull request #9655: [FLINK-14017][python] Support to start up Python worker in process mode. URL: https://github.com/apache/flink/pull/9655#discussion_r324575806
########## File path: flink-python/pyflink/fn_execution/tests/test_process_mode_boot.py ########## @@ -0,0 +1,129 @@ +################################################################################ +# 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. +################################################################################ +import glob +import os +import socket +import subprocess +import sys +import tempfile +import time + +import grpc +from apache_beam.portability.api.beam_artifact_api_pb2 import GetManifestResponse, ArtifactChunk +from apache_beam.portability.api.beam_artifact_api_pb2_grpc import ( + ArtifactRetrievalServiceServicer, add_ArtifactRetrievalServiceServicer_to_server) +from apache_beam.portability.api.beam_provision_api_pb2 import (ProvisionInfo, + GetProvisionInfoResponse) +from apache_beam.portability.api.beam_provision_api_pb2_grpc import ( + ProvisionServiceServicer, add_ProvisionServiceServicer_to_server) +from concurrent import futures +from google.protobuf import json_format + +from pyflink.fn_execution.tests.process_mode_test_data import (manifest, file_data, + test_provision_info_json) +from pyflink.testing.test_case_utils import PyFlinkTestCase + + +class PythonBootTests(PyFlinkTestCase): + + def check_installed_package(self, prefix_dir, package_names): + packages_dir = [path for path + in glob.glob(os.path.join(prefix_dir, "lib", "*", "site-packages", "*"))] + for package_name in package_names: + self.assertTrue( + any([os.path.basename(dir_name).startswith(package_name) + for dir_name in packages_dir]), + "%s not in the install packages list!" % package_name) + + def test_python_boot(self): + manifest_response = json_format.Parse(manifest, GetManifestResponse()) + artifact_chunks = dict() + for file_name in file_data: + artifact_chunks[file_name] = json_format.Parse(file_data[file_name], ArtifactChunk()) + provision_info = json_format.Parse(test_provision_info_json, ProvisionInfo()) + response = GetProvisionInfoResponse(info=provision_info) + + def get_unused_port(): + sock = socket.socket() + sock.bind(('', 0)) + port = sock.getsockname()[1] + sock.close() + return port + + class ArtifactService(ArtifactRetrievalServiceServicer): + def GetManifest(self, request, context): + return manifest_response + + def GetArtifact(self, request, context): + yield artifact_chunks[request.name] + + def start_test_artifact_server(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) + add_ArtifactRetrievalServiceServicer_to_server(ArtifactService(), server) + port = get_unused_port() + server.add_insecure_port('[::]:' + str(port)) + server.start() + return server, port + + class ProvisionService(ProvisionServiceServicer): + def GetProvisionInfo(self, request, context): + return response + + def start_test_provision_server(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) + add_ProvisionServiceServicer_to_server(ProvisionService(), server) + port = get_unused_port() + server.add_insecure_port('[::]:' + str(port)) + server.start() + return server, port + + artifact_server, artifact_port = start_test_artifact_server() Review comment: move the start the server logic to setup method? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
