[
https://issues.apache.org/jira/browse/DISPATCH-1870?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17272830#comment-17272830
]
ASF GitHub Bot commented on DISPATCH-1870:
------------------------------------------
fgiorgetti commented on a change in pull request #944:
URL: https://github.com/apache/qpid-dispatch/pull/944#discussion_r565277204
##########
File path: tests/system_tests_grpc.py
##########
@@ -0,0 +1,215 @@
+#
+# 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 os, sys
+from time import sleep, ctime
+import system_test
+from system_test import TestCase, Qdrouterd, QdManager, Process, SkipIfNeeded,
TIMEOUT
+from subprocess import PIPE
+try:
+ import grpc
+ import friendship_server as fs
+ from friendship_pb2_grpc import FriendshipStub
+ from friendship_pb2 import Person, FriendshipRequest, PersonEmail
+except ImportError:
+ pass
+
+
+def skip_test():
+ """
+ If grpc cannot be imported, test must be skipped
+ :return:
+ """
+ try:
+ import grpc
+ import friendship_server as fs
+ from friendship_pb2_grpc import FriendshipStub
+ from friendship_pb2 import Person, FriendshipRequest, PersonEmail
+ return False
+ except ImportError:
+ return True
+
+
+class GrpcTestBase(TestCase):
+
+ """
+ Data for the grpc service
+ """
+ NAME_EMAIL = {
+ "One": "[email protected]",
+ "Two": "[email protected]",
+ "Three": "[email protected]",
+ "Four": "[email protected]",
+ "Five": "[email protected]",
+ }
+
+ """
+ List of how friendships will be defined at the grpc service
+ 1 = 2; 3; 4
+ 2 = 1; 3; 5
+ 3 = 1; 2; 4
+ 4 = 1; 3; 5
+ 5 = 2; 4
+ """
+ FRIENDS = {
+ "[email protected]": ["[email protected]", "[email protected]",
"[email protected]"],
+ "[email protected]": ["[email protected]", "[email protected]"],
+ "[email protected]": ["[email protected]"],
+ "[email protected]": ["[email protected]"],
+ }
+ EXP_FRIENDS = {
+ "[email protected]": ["[email protected]", "[email protected]",
"[email protected]"],
+ "[email protected]": ["[email protected]", "[email protected]",
"[email protected]"],
+ "[email protected]": ["[email protected]", "[email protected]",
"[email protected]"],
+ "[email protected]": ["[email protected]", "[email protected]",
"[email protected]"],
+ "[email protected]": ["[email protected]", "[email protected]"]
+ }
+
+ """
+ List of common friends to request for and the expected
+ result to be returned by the service
+ """
+ COMMON_FRIENDS_ITER = [
+ ["[email protected]", "[email protected]"],
+ ["[email protected]", "[email protected]"],
+ ]
+ COMMON_FRIENDS_EXP = [
+ ["[email protected]", "[email protected]"],
+ ["[email protected]", "[email protected]", "[email protected]"],
+ ]
+
+ @classmethod
+ def setUpClass(cls):
+ super(GrpcTestBase, cls).setUpClass()
+ if skip_test():
+ return
+
+ # Define a random port for the gRPC server to bind
+ cls.grpc_server_port = str(cls.tester.get_port())
+
+ # Run the gRPC server (see friendship.proto for more info)
+ cls.grpc_server = fs.serve(cls.grpc_server_port)
+
+ # Prepare router to communicate with the gRPC server
+ cls.connector_props = {
+ 'port': cls.grpc_server_port,
+ 'address': 'examples',
+ 'host': '127.0.0.1',
+ 'protocolVersion': 'HTTP2',
+ 'name': 'grpc-server'
+ }
+ cls.router_http_port = cls.tester.get_port()
+ config = Qdrouterd.Config([
+ ('router', {'mode': 'standalone', 'id': 'QDR'}),
+ ('listener', {'port': cls.tester.get_port(), 'role': 'normal',
'host': '0.0.0.0'}),
+
+ ('httpListener', {'port': cls.router_http_port, 'address':
'examples',
+ 'host': '127.0.0.1', 'protocolVersion':
'HTTP2'}),
+ ('httpConnector', cls.connector_props)
+ ])
+ cls.router_qdr = cls.tester.qdrouterd("grpc-test-router", config,
wait=True)
+
+ # If you wanna try it without the router, set the grpc_channel
directly to the grpc_server_port
+ cls.grpc_channel = grpc.insecure_channel('127.0.0.1:%s' %
cls.router_http_port)
+ cls.grpc_stub = FriendshipStub(cls.grpc_channel)
+
+ @classmethod
+ def tearDownClass(cls):
+ super(GrpcTestBase, cls).tearDownClass()
+ if skip_test():
+ return
+ cls.grpc_server.stop(TIMEOUT)
+
+ @classmethod
+ def create_person(cls, name, email):
+ p = Person()
+ p.name = name
+ p.email = email
+ res = cls.grpc_stub.Create(p)
+ assert res.success
+ assert res.message == ""
+ return p
+
+ @classmethod
+ def friendship_generator(cls):
+ for key in cls.FRIENDS:
+ for friend in cls.FRIENDS[key]:
+ fr = FriendshipRequest()
+ fr.email1 = key
+ fr.email2 = friend
+ yield fr
+
+ @classmethod
+ def common_friends_list(cls, friends):
+ for friend in friends:
+ pe = PersonEmail()
+ pe.email = friend
+ yield pe
+
+ @SkipIfNeeded(skip_test(), "grpcio is needed to run grpc tests")
Review comment:
Maybe we can come up later (in an upcoming PR), with a definite solution
to replace SkipIfNeeded,
since it was created exactly because of the lack of skipping tests with
Python 2.6.
----------------------------------------------------------------
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]
> Add new system test to validate gRPC through HTTP2 adaptors
> -----------------------------------------------------------
>
> Key: DISPATCH-1870
> URL: https://issues.apache.org/jira/browse/DISPATCH-1870
> Project: Qpid Dispatch
> Issue Type: Test
> Components: Tests
> Reporter: Fernando Giorgetti
> Assignee: Fernando Giorgetti
> Priority: Major
>
> Implement a new system test to validate gRPC through the router HTTP2
> adaptors.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]