]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/dev/archery/archery/integration/tester_go.py
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / dev / archery / archery / integration / tester_go.py
CommitLineData
1d09f67e
TL
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18import contextlib
19import os
20import subprocess
21
22from .tester import Tester
23from .util import run_cmd, log
24
25
26class GoTester(Tester):
27 PRODUCER = True
28 CONSUMER = True
29 FLIGHT_SERVER = True
30 FLIGHT_CLIENT = True
31
32 # FIXME(sbinet): revisit for Go modules
33 HOME = os.getenv('HOME', '~')
34 GOPATH = os.getenv('GOPATH', os.path.join(HOME, 'go'))
35 GOBIN = os.environ.get('GOBIN', os.path.join(GOPATH, 'bin'))
36
37 GO_INTEGRATION_EXE = os.path.join(GOBIN, 'arrow-json-integration-test')
38 STREAM_TO_FILE = os.path.join(GOBIN, 'arrow-stream-to-file')
39 FILE_TO_STREAM = os.path.join(GOBIN, 'arrow-file-to-stream')
40
41 FLIGHT_SERVER_CMD = [
42 os.path.join(GOBIN, 'arrow-flight-integration-server')]
43 FLIGHT_CLIENT_CMD = [
44 os.path.join(GOBIN, 'arrow-flight-integration-client'),
45 '-host', 'localhost']
46
47 name = 'Go'
48
49 def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):
50 cmd = [self.GO_INTEGRATION_EXE]
51
52 if arrow_path is not None:
53 cmd.extend(['-arrow', arrow_path])
54
55 if json_path is not None:
56 cmd.extend(['-json', json_path])
57
58 cmd.extend(['-mode', command])
59
60 if self.debug:
61 log(' '.join(cmd))
62
63 run_cmd(cmd)
64
65 def validate(self, json_path, arrow_path):
66 return self._run(arrow_path, json_path, 'VALIDATE')
67
68 def json_to_file(self, json_path, arrow_path):
69 return self._run(arrow_path, json_path, 'JSON_TO_ARROW')
70
71 def stream_to_file(self, stream_path, file_path):
72 cmd = [self.STREAM_TO_FILE, '<', stream_path, '>', file_path]
73 self.run_shell_command(cmd)
74
75 def file_to_stream(self, file_path, stream_path):
76 cmd = [self.FILE_TO_STREAM, file_path, '>', stream_path]
77 self.run_shell_command(cmd)
78
79 @contextlib.contextmanager
80 def flight_server(self, scenario_name=None):
81 cmd = self.FLIGHT_SERVER_CMD + ['-port=0']
82 if scenario_name:
83 cmd = cmd + ['-scenario', scenario_name]
84 if self.debug:
85 log(' '.join(cmd))
86 server = subprocess.Popen(cmd,
87 stdout=subprocess.PIPE,
88 stderr=subprocess.PIPE)
89
90 try:
91 output = server.stdout.readline().decode()
92 if not output.startswith("Server listening on localhost:"):
93 server.kill()
94 out, err = server.communicate()
95 raise RuntimeError(
96 "Flight-Go server did not start properly, "
97 "stdout: \n{}\n\nstderr:\n{}\n"
98 .format(output + out.decode(), err.decode())
99 )
100 port = int(output.split(":")[1])
101 yield port
102 finally:
103 server.kill()
104 server.wait(5)
105
106 def flight_request(self, port, json_path=None, scenario_name=None):
107 cmd = self.FLIGHT_CLIENT_CMD + [
108 '-port=' + str(port),
109 ]
110 if json_path:
111 cmd.extend(('-path', json_path))
112 elif scenario_name:
113 cmd.extend(('-scenario', scenario_name))
114 else:
115 raise TypeError("Must provide one of json_path or scenario_name")
116
117 if self.debug:
118 log(' '.join(cmd))
119 run_cmd(cmd)