]>
git.proxmox.com Git - ceph.git/blob - 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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
22 from .tester
import Tester
23 from .util
import run_cmd
, ARROW_ROOT_DEFAULT
, log
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
34 class JavaTester(Tester
):
40 JAVA_OPTS
= ['-Dio.netty.tryReflectionSetAccessible=true',
41 '-Darrow.struct.conflict.policy=CONFLICT_APPEND']
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')
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']
65 if arrow_path
is not None:
66 cmd
.extend(['-a', arrow_path
])
68 if json_path
is not None:
69 cmd
.extend(['-j', json_path
])
71 cmd
.extend(['-c', command
])
78 def validate(self
, json_path
, arrow_path
):
79 return self
._run
(arrow_path
, json_path
, 'VALIDATE')
81 def json_to_file(self
, json_path
, arrow_path
):
82 return self
._run
(arrow_path
, json_path
, 'JSON_TO_ARROW')
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
]
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
]
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
,
106 cmd
.extend(('-j', json_path
))
108 cmd
.extend(('-scenario', scenario_name
))
110 raise TypeError("Must provide one of json_path or scenario_name")
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
,
122 cmd
.extend(('-scenario', scenario_name
))
125 server
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
,
126 stderr
=subprocess
.PIPE
)
128 output
= server
.stdout
.readline().decode()
129 if not output
.startswith("Server listening on localhost:"):
131 out
, err
= server
.communicate()
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])