]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/dev/archery/archery/integration/tester_java.py
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / dev / archery / archery / integration / tester_java.py
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
18 import contextlib
19 import os
20 import subprocess
21
22 from .tester import Tester
23 from .util import run_cmd, ARROW_ROOT_DEFAULT, log
24
25
26 def load_version_from_pom():
27 import xml.etree.ElementTree as ET
28 tree = ET.parse(os.path.join(ARROW_ROOT_DEFAULT, 'java', 'pom.xml'))
29 tag_pattern = '{http://maven.apache.org/POM/4.0.0}version'
30 version_tag = list(tree.getroot().findall(tag_pattern))[0]
31 return version_tag.text
32
33
34 class JavaTester(Tester):
35 PRODUCER = True
36 CONSUMER = True
37 FLIGHT_SERVER = True
38 FLIGHT_CLIENT = True
39
40 JAVA_OPTS = ['-Dio.netty.tryReflectionSetAccessible=true',
41 '-Darrow.struct.conflict.policy=CONFLICT_APPEND']
42
43 _arrow_version = load_version_from_pom()
44 ARROW_TOOLS_JAR = os.environ.get(
45 'ARROW_JAVA_INTEGRATION_JAR',
46 os.path.join(ARROW_ROOT_DEFAULT,
47 'java/tools/target/arrow-tools-{}-'
48 'jar-with-dependencies.jar'.format(_arrow_version)))
49 ARROW_FLIGHT_JAR = os.environ.get(
50 'ARROW_FLIGHT_JAVA_INTEGRATION_JAR',
51 os.path.join(ARROW_ROOT_DEFAULT,
52 'java/flight/flight-core/target/flight-core-{}-'
53 'jar-with-dependencies.jar'.format(_arrow_version)))
54 ARROW_FLIGHT_SERVER = ('org.apache.arrow.flight.example.integration.'
55 'IntegrationTestServer')
56 ARROW_FLIGHT_CLIENT = ('org.apache.arrow.flight.example.integration.'
57 'IntegrationTestClient')
58
59 name = 'Java'
60
61 def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):
62 cmd = ['java'] + self.JAVA_OPTS + \
63 ['-cp', self.ARROW_TOOLS_JAR, 'org.apache.arrow.tools.Integration']
64
65 if arrow_path is not None:
66 cmd.extend(['-a', arrow_path])
67
68 if json_path is not None:
69 cmd.extend(['-j', json_path])
70
71 cmd.extend(['-c', command])
72
73 if self.debug:
74 log(' '.join(cmd))
75
76 run_cmd(cmd)
77
78 def validate(self, json_path, arrow_path):
79 return self._run(arrow_path, json_path, 'VALIDATE')
80
81 def json_to_file(self, json_path, arrow_path):
82 return self._run(arrow_path, json_path, 'JSON_TO_ARROW')
83
84 def stream_to_file(self, stream_path, file_path):
85 cmd = ['java'] + self.JAVA_OPTS + \
86 ['-cp', self.ARROW_TOOLS_JAR,
87 'org.apache.arrow.tools.StreamToFile', stream_path, file_path]
88 if self.debug:
89 log(' '.join(cmd))
90 run_cmd(cmd)
91
92 def file_to_stream(self, file_path, stream_path):
93 cmd = ['java'] + self.JAVA_OPTS + \
94 ['-cp', self.ARROW_TOOLS_JAR,
95 'org.apache.arrow.tools.FileToStream', file_path, stream_path]
96 if self.debug:
97 log(' '.join(cmd))
98 run_cmd(cmd)
99
100 def flight_request(self, port, json_path=None, scenario_name=None):
101 cmd = ['java'] + self.JAVA_OPTS + \
102 ['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_CLIENT,
103 '-port', str(port)]
104
105 if json_path:
106 cmd.extend(('-j', json_path))
107 elif scenario_name:
108 cmd.extend(('-scenario', scenario_name))
109 else:
110 raise TypeError("Must provide one of json_path or scenario_name")
111
112 if self.debug:
113 log(' '.join(cmd))
114 run_cmd(cmd)
115
116 @contextlib.contextmanager
117 def flight_server(self, scenario_name=None):
118 cmd = ['java'] + self.JAVA_OPTS + \
119 ['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_SERVER,
120 '-port', '0']
121 if scenario_name:
122 cmd.extend(('-scenario', scenario_name))
123 if self.debug:
124 log(' '.join(cmd))
125 server = subprocess.Popen(cmd, stdout=subprocess.PIPE,
126 stderr=subprocess.PIPE)
127 try:
128 output = server.stdout.readline().decode()
129 if not output.startswith("Server listening on localhost:"):
130 server.kill()
131 out, err = server.communicate()
132 raise RuntimeError(
133 "Flight-Java server did not start properly, "
134 "stdout:\n{}\n\nstderr:\n{}\n"
135 .format(output + out.decode(), err.decode()))
136 port = int(output.split(":")[1])
137 yield port
138 finally:
139 server.kill()
140 server.wait(5)