Apache DataFusion SQL Query Engine
ARROW-6466: [Integration][CI] Move integration test code to `archery integration` command. Dockerize integration tests
Wes McKinney96dabcc50b1c
diff --git a/.travis.yml b/.travis.ymlindex 1481dee94f..32f0a87edc 100644--- a/.travis.yml+++ b/.travis.yml@@ -185,33 +185,15 @@ matrix:- docker-compose run java-all-jdks# -------------------------------------------------------------------------- - name: "Integration w/ OpenJDK 8, conda-forge toolchain"- language: java+ - name: "Protocol / Flight Integration Tests"+ language: cppos: linuxenv: ARROW_TEST_GROUP=integration- jdk: openjdk8- env:- - ARROW_TRAVIS_USE_TOOLCHAIN=1- - ARROW_TRAVIS_FLIGHT=1- - ARROW_TRAVIS_INTEGRATION=1- # TODO(ARROW-4764): Using system java and plasma built with conda doesn't work- #- ARROW_TRAVIS_PLASMA=1- #- ARROW_TRAVIS_PLASMA_JAVA_CLIENT=1- - ARROW_TRAVIS_MIMALLOC=1before_script:- if [ $ARROW_CI_INTEGRATION_AFFECTED != "1" ]; then exit; fi- - $TRAVIS_BUILD_DIR/ci/travis_install_clang_tools.sh- - $TRAVIS_BUILD_DIR/ci/travis_install_linux.sh- # C++: Only build integration targets- - export ARROW_CPP_BUILD_TARGETS=arrow-integration- - export ARROW_TRAVIS_OPTIONAL_INSTALL=1- - $TRAVIS_BUILD_DIR/ci/travis_before_script_cpp.sh- # Javascript- - nvm install 11.12- - $TRAVIS_BUILD_DIR/ci/travis_before_script_js.sh+ - docker-compose pull integrationscript:- - $TRAVIS_BUILD_DIR/ci/travis_script_integration.sh- # - $TRAVIS_BUILD_DIR/ci/travis_script_plasma_java_client.sh+ - docker-compose run integration# -------------------------------------------------------------------------- name: "NodeJS"diff --git a/ci/docker_integration.sh b/ci/docker_integration.shnew file mode 100755index 0000000000..8331a55e95--- /dev/null+++ b/ci/docker_integration.sh@@ -0,0 +1,126 @@+#!/usr/bin/env bash+# 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.++set -eu++BIN_DIR=/bin+CPP_DIR=/build/cpp+JAVA_DIR=/build/java+JS_DIR=/build/js++# Copy various stuff into our Docker build directory+pushd /arrow+rsync -r \+ LICENSE.txt NOTICE.txt \+ header java js format integration testing /build+popd++mkdir -p $BIN_DIR+mkdir -p $CPP_DIR++# Install archery tool, require writable -e install+cp -r /arrow/dev/archery /archery+pip install -e /archery++# archery requires NumPy+pip install numpy++# Archery integration test environment variables+export ARROW_ROOT=/build+export ARROW_TEST_DATA=/arrow/testing/data++# Make a minimal C++ build for running integration tests+function build_cpp() {+ pushd $CPP_DIR++ cmake /arrow/cpp \+ -DCMAKE_BUILD_TYPE=debug \+ -DBOOST_SOURCE=SYSTEM \+ -DARROW_BUILD_INTEGRATION=ON \+ -DARROW_FLIGHT=ON \+ -DARROW_COMPUTE=OFF \+ -DARROW_DATASET=OFF \+ -DARROW_FILESYSTEM=OFF \+ -DARROW_HDFS=OFF \+ -DARROW_JEMALLOC=OFF \+ -DARROW_JSON=OFF \+ -DARROW_USE_GLOG=OFF \+ -DARROW_WITH_BZ2=OFF \+ -DARROW_WITH_ZLIB=OFF \+ -DARROW_WITH_ZSTD=OFF \+ -DARROW_WITH_LZ4=OFF \+ -DARROW_WITH_SNAPPY=OFF \+ -DARROW_WITH_BROTLI=OFF++ make -j4 arrow-integration+ export ARROW_CPP_EXE_PATH=$CPP_DIR/debug+}++function build_java() {+ export MAVEN_OPTS="-Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"++ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64++ # /arrow/java is read-only+ pushd /arrow+ popd++ pushd $JAVA_DIR+ mvn package -B -DskipTests -Drat.skip=true++ popd+}++# Build Go+function build_go() {+ pushd /arrow/go/arrow++ export GO111MODULE=on+ export GOBIN=$BIN_DIR+ which go+ go version+ go env+ go get -v ./...++ popd+}++# Build JS+function build_js() {+ source $NVM_DIR/nvm.sh+ nvm install $NODE_VERSION+ nvm alias default $NODE_VERSION+ nvm use default++ pushd $JS_DIR++ npm install+ npm run build -- -t apache-arrow++ popd+}++# Run integration tests+GOLD_14_1=$ARROW_TEST_DATA/arrow-ipc/integration/0.14.1++build_cpp+build_go+build_js+build_java++archery integration --with-all --run-flightdiff --git a/ci/travis_script_integration.sh b/ci/travis_script_integration.shdeleted file mode 100755index 8356c348ad..0000000000--- a/ci/travis_script_integration.sh+++ /dev/null@@ -1,80 +0,0 @@-#!/usr/bin/env bash--# 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.--set -ex--source $TRAVIS_BUILD_DIR/ci/travis_env_common.sh--source $TRAVIS_BUILD_DIR/ci/travis_install_conda.sh--export ARROW_CPP_EXE_PATH=$ARROW_CPP_BUILD_DIR/debug--pushd $ARROW_JAVA_DIR--echo "mvn package"-$TRAVIS_MVN -B clean package 2>&1 > mvn_package.log || (cat mvn_package.log && false)--popd--pushd $ARROW_JS_DIR--# lint and compile JS source-npm run lint-npm run build -- -t apache-arrow--popd--pushd $ARROW_GO_DIR/arrow--eval $(gimme 1.12.x)--export GO111MODULE=on-export GOBIN=`pwd`/bin--which go-go version-go env-go get -v ./...--popd--pushd $ARROW_INTEGRATION_DIR--conda activate $CPP_TOOLCHAIN-# Install integration test requirements-conda install -y -q python=3.6 six numpy--# ARROW-4008: Create a directory to write temporary files since /tmp can be-# unstable in Travis CI-INTEGRATION_TEMPDIR=$TRAVIS_BUILD_DIR/integration_temp-GOLD_14_1=$ARROW_TEST_DATA/arrow-ipc/integration/0.14.1-mkdir -p $INTEGRATION_TEMPDIR--python integration_test.py --debug --tempdir=$INTEGRATION_TEMPDIR --gold_dirs=$GOLD_14_1 --run_flight--popd--# pushd $ARROW_JS_DIR--# run tests against source to generate coverage data-# npm run test:coverage-# Uncomment to upload to coveralls-# cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js;--# popddiff --git a/dev/archery/archery/cli.py b/dev/archery/archery/cli.pyindex a9df88a500..7d489d4c36 100644--- a/dev/archery/archery/cli.py+++ b/dev/archery/archery/cli.py@@ -17,8 +17,10 @@# under the License.import click+import errnoimport jsonimport logging+import osimport sysfrom .benchmark.compare import RunnerComparator, DEFAULT_THRESHOLD@@ -77,6 +79,8 @@ def archery(ctx, debug, pdb, quiet):if debug:logger.setLevel(logging.DEBUG)+ ctx.debug = debug+if pdb:import pdbsys.excepthook = lambda t, v, e: pdb.pm()@@ -449,5 +453,75 @@ def benchmark_diff(ctx, src, preserve, output, cmake_extras,output.write("\n")+# ----------------------------------------------------------------------+# Integration testing++def _set_default(opt, default):+ if opt is None:+ return default+ return opt++[email protected](short_help="Execute protocol and Flight integration tests")[email protected]('--with-all', is_flag=True, default=False,+ help=('Include all known lanauges by default '+ ' in integration tests'))[email protected]('--random-seed', type=int, default=12345,+ help="Seed for PRNG when generating test data")[email protected]('--with-cpp', type=bool, default=False,+ help='Include C++ in integration tests')[email protected]('--with-java', type=bool, default=False,+ help='Include Java in integration tests')[email protected]('--with-js', type=bool, default=False,+ help='Include JavaScript in integration tests')[email protected]('--with-go', type=bool, default=False,+ help='Include Go in integration tests')[email protected]('--write_generated_json', default=False,+ help='Generate test JSON to indicated path')[email protected]('--run-flight', is_flag=True, default=False,+ help='Run Flight integration tests')[email protected]('--debug', type=bool, default=False,+ help='Run executables in debug mode as relevant')[email protected]('--tempdir', default=None,+ help=('Directory to use for writing '+ 'integration test temporary files'))[email protected]('stop_on_error', '-x', '--stop-on-error',+ is_flag=True, default=False,+ help='Stop on first error')[email protected]('--gold_dirs', multiple=True,+ help="gold integration test file paths")+def integration(with_all=False, random_seed=12345, **args):+ from .integration.runner import write_js_test_json, run_all_tests+ import numpy as np++ # Make runs involving data generation deterministic+ np.random.seed(random_seed)++ gen_path = args['write_generated_json']++ languages = ['cpp', 'java', 'js', 'go']++ enabled_languages = 0+ for lang in languages:+ param = 'with_{}'.format(lang)+ if with_all:+ args[param] = with_all++ if args[param]:+ enabled_languages += 1++ if gen_path:+ try:+ os.makedirs(gen_path)+ except OSError as e:+ if e.errno != errno.EEXIST:+ raise+ write_js_test_json(gen_path)+ else:+ if enabled_languages == 0:+ raise Exception("Must enable at least 1 language to test")+ run_all_tests(**args)++if __name__ == "__main__":archery(obj={})diff --git a/dev/archery/archery/integration/__init__.py b/dev/archery/archery/integration/__init__.pynew file mode 100644index 0000000000..13a83393a9--- /dev/null+++ b/dev/archery/archery/integration/__init__.py@@ -0,0 +1,16 @@+# 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.diff --git a/integration/integration_test.py b/dev/archery/archery/integration/datagen.pysimilarity index 56%rename from integration/integration_test.pyrename to dev/archery/archery/integration/datagen.pyindex 8c0423358a..6f43a42da3 100644--- a/integration/integration_test.py+++ b/dev/archery/archery/integration/datagen.py@@ -16,92 +16,15 @@# under the License.from collections import OrderedDict-import argparseimport binascii-import contextlib-import glob-import gzip-import itertoolsimport jsonimport osimport random-import six-import string-import subprocess-import sysimport tempfile-import traceback-import uuid-import errnoimport numpy as np--ARROW_HOME = os.path.abspath(__file__).rsplit("/", 2)[0]--# Control for flakiness-np.random.seed(12345)---def load_version_from_pom():- import xml.etree.ElementTree as ET- tree = ET.parse(os.path.join(ARROW_HOME, 'java', 'pom.xml'))- tag_pattern = '{http://maven.apache.org/POM/4.0.0}version'- version_tag = list(tree.getroot().findall(tag_pattern))[0]- return version_tag.text---def guid():- return uuid.uuid4().hex---# from pandas-RANDS_CHARS = np.array(list(string.ascii_letters + string.digits),- dtype=(np.str_, 1))---def rands(nchars):- """- Generate one random byte string.-- See `rands_array` if you want to create an array of random strings.-- """- return ''.join(np.random.choice(RANDS_CHARS, nchars))---def tobytes(o):- if isinstance(o, six.text_type):- return o.encode('utf8')- return o---def frombytes(o):- if isinstance(o, six.binary_type):- return o.decode('utf8')- return o---# from the merge_arrow_pr.py script-def run_cmd(cmd):- if isinstance(cmd, six.string_types):- cmd = cmd.split(' ')-- try:- output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)- except subprocess.CalledProcessError as e:- # this avoids hiding the stdout / stderr of failed processes- print('Command failed: %s' % ' '.join(cmd))- print('With output:')- print('--------------')- print(frombytes(e.output))- print('--------------')- raise e-- return frombytes(output)--# -----------------------------------------------------------------------# Data generation+from .util import (frombytes, rands, tobytes, SKIP_ARROW, SKIP_FLIGHT)class DataType(object):@@ -910,11 +833,6 @@ class JsonRecordBatch(object):])-# SKIP categories-SKIP_ARROW = 'arrow'-SKIP_FLIGHT = 'flight'--class JsonFile(object):def __init__(self, name, schema, batches, dictionaries=None,@@ -1179,616 +1097,3 @@ def get_generated_json_files(tempdir=None, flight=False):generated_paths.append(file_obj)return generated_paths---# -----------------------------------------------------------------------# Testing harness---class IntegrationRunner(object):-- def __init__(self, json_files, testers, args):- self.json_files = json_files- self.testers = testers- self.temp_dir = args.tempdir or tempfile.mkdtemp()- self.debug = args.debug- self.stop_on_error = args.stop_on_error- self.gold_dirs = args.gold_dirs-- def run(self):- failures = []-- for producer, consumer in itertools.product(- filter(lambda t: t.PRODUCER, self.testers),- filter(lambda t: t.CONSUMER, self.testers)):- for failure in self._compare_implementations(- producer, consumer, self._produce_consume, self.json_files):- failures.append(failure)- if self.gold_dirs:- for gold_dir, consumer in itertools.product(- self.gold_dirs,- filter(lambda t: t.CONSUMER, self.testers)):- print('\n\n\n\n')- print('******************************************************')- print('Tests against golden files in {}'.format(gold_dir))- print('******************************************************')-- def run_gold(producer, consumer, test_case):- self._run_gold(gold_dir, producer, consumer, test_case)- for failure in self._compare_implementations(- consumer, consumer, run_gold, self._gold_tests(gold_dir)):- failures.append(failure)-- return failures-- def run_flight(self):- failures = []- servers = filter(lambda t: t.FLIGHT_SERVER, self.testers)- clients = filter(lambda t: (t.FLIGHT_CLIENT and t.CONSUMER),- self.testers)- for server, client in itertools.product(servers, clients):- for failure in self._compare_flight_implementations(server,- client):- failures.append(failure)- return failures-- def _gold_tests(self, gold_dir):- prefix = os.path.basename(os.path.normpath(gold_dir))- SUFFIX = ".json.gz"- golds = [jf for jf in os.listdir(gold_dir) if jf.endswith(SUFFIX)]- for json_path in golds:- name = json_path[json_path.index('_')+1: -len(SUFFIX)]- base_name = prefix + "_" + name + ".gold.json"- out_path = os.path.join(self.temp_dir, base_name)- with gzip.open(os.path.join(gold_dir, json_path)) as i:- with open(out_path, "wb") as out:- out.write(i.read())-- try:- skip = next(f for f in self.json_files- if f.name == name).skip- except StopIteration:- skip = set()- yield JsonFile(name, None, None, skip=skip, path=out_path)-- def _compare_implementations(- self, producer, consumer, run_binaries, test_cases):- print('##########################################################')- print(- '{0} producing, {1} consuming'.format(producer.name, consumer.name)- )- print('##########################################################')-- for test_case in test_cases:- json_path = test_case.path- print('==========================================================')- print('Testing file {0}'.format(json_path))- print('==========================================================')-- if producer.name in test_case.skip:- print('-- Skipping test because producer {0} does '- 'not support'.format(producer.name))- continue-- if consumer.name in test_case.skip:- print('-- Skipping test because consumer {0} does '- 'not support'.format(consumer.name))- continue-- if SKIP_ARROW in test_case.skip:- print('-- Skipping test')- continue-- try:- run_binaries(producer, consumer, test_case)- except Exception:- traceback.print_exc()- yield (test_case, producer, consumer, sys.exc_info())- if self.stop_on_error:- break- else:- continue-- def _produce_consume(self, producer, consumer, test_case):- # Make the random access file- json_path = test_case.path- file_id = guid()[:8]- name = os.path.splitext(os.path.basename(json_path))[0]-- producer_file_path = os.path.join(self.temp_dir, file_id + '_' +- name + '.json_as_file')- producer_stream_path = os.path.join(self.temp_dir, file_id + '_' +- name + '.producer_file_as_stream')- consumer_file_path = os.path.join(self.temp_dir, file_id + '_' +- name + '.consumer_stream_as_file')-- print('-- Creating binary inputs')- producer.json_to_file(json_path, producer_file_path)-- # Validate the file- print('-- Validating file')- consumer.validate(json_path, producer_file_path)-- print('-- Validating stream')- producer.file_to_stream(producer_file_path, producer_stream_path)- consumer.stream_to_file(producer_stream_path, consumer_file_path)- consumer.validate(json_path, consumer_file_path)-- def _run_gold(self, gold_dir, producer, consumer, test_case):- json_path = test_case.path-- # Validate the file- print('-- Validating file')- producer_file_path = os.path.join(- gold_dir, "generated_" + test_case.name + ".arrow_file")- consumer.validate(json_path, producer_file_path)-- print('-- Validating stream')- consumer_stream_path = os.path.join(- gold_dir, "generated_" + test_case.name + ".stream")- file_id = guid()[:8]- name = os.path.splitext(os.path.basename(json_path))[0]-- consumer_file_path = os.path.join(self.temp_dir, file_id + '_' +- name + '.consumer_stream_as_file')-- consumer.stream_to_file(consumer_stream_path, consumer_file_path)- consumer.validate(json_path, consumer_file_path)-- def _compare_flight_implementations(self, producer, consumer):- print('##########################################################')- print(- '{0} serving, {1} requesting'.format(producer.name, consumer.name)- )- print('##########################################################')-- for test_case in self.json_files:- json_path = test_case.path- print('=' * 58)- print('Testing file {0}'.format(json_path))- print('=' * 58)-- if ('Java' in (producer.name, consumer.name) and- "map" in test_case.name):- print('TODO(ARROW-1279): Enable map tests ' +- ' for Java and JS once Java supports them and JS\'' +- ' are unbroken')- continue-- if SKIP_FLIGHT in test_case.skip:- print('-- Skipping test')- continue-- try:- with producer.flight_server():- # Have the client upload the file, then download and- # compare- consumer.flight_request(producer.FLIGHT_PORT, json_path)- except Exception:- traceback.print_exc()- yield (test_case, producer, consumer, sys.exc_info())- continue---class Tester(object):- PRODUCER = False- CONSUMER = False- FLIGHT_SERVER = False- FLIGHT_CLIENT = False- FLIGHT_PORT = 31337-- def __init__(self, args):- self.args = args- self.debug = args.debug-- def run_shell_command(self, cmd):- cmd = ' '.join(cmd)- if self.debug:- print(cmd)- subprocess.check_call(cmd, shell=True)-- def json_to_file(self, json_path, arrow_path):- raise NotImplementedError-- def stream_to_file(self, stream_path, file_path):- raise NotImplementedError-- def file_to_stream(self, file_path, stream_path):- raise NotImplementedError-- def validate(self, json_path, arrow_path):- raise NotImplementedError-- def flight_server(self):- raise NotImplementedError-- def flight_request(self, port, json_path):- raise NotImplementedError---class JavaTester(Tester):- PRODUCER = True- CONSUMER = True- FLIGHT_SERVER = True- FLIGHT_CLIENT = True-- FLIGHT_PORT = 31338-- JAVA_OPTS = ['-Dio.netty.tryReflectionSetAccessible=true']-- _arrow_version = load_version_from_pom()- ARROW_TOOLS_JAR = os.environ.get(- 'ARROW_JAVA_INTEGRATION_JAR',- os.path.join(ARROW_HOME,- 'java/tools/target/arrow-tools-{}-'- 'jar-with-dependencies.jar'.format(_arrow_version)))- ARROW_FLIGHT_JAR = os.environ.get(- 'ARROW_FLIGHT_JAVA_INTEGRATION_JAR',- os.path.join(ARROW_HOME,- 'java/flight/target/arrow-flight-{}-'- 'jar-with-dependencies.jar'.format(_arrow_version)))- ARROW_FLIGHT_SERVER = ('org.apache.arrow.flight.example.integration.'- 'IntegrationTestServer')- ARROW_FLIGHT_CLIENT = ('org.apache.arrow.flight.example.integration.'- 'IntegrationTestClient')-- name = 'Java'-- def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):- cmd = ['java'] + self.JAVA_OPTS + \- ['-cp', self.ARROW_TOOLS_JAR, 'org.apache.arrow.tools.Integration']-- if arrow_path is not None:- cmd.extend(['-a', arrow_path])-- if json_path is not None:- cmd.extend(['-j', json_path])-- cmd.extend(['-c', command])-- if self.debug:- print(' '.join(cmd))-- run_cmd(cmd)-- def validate(self, json_path, arrow_path):- return self._run(arrow_path, json_path, 'VALIDATE')-- def json_to_file(self, json_path, arrow_path):- return self._run(arrow_path, json_path, 'JSON_TO_ARROW')-- def stream_to_file(self, stream_path, file_path):- cmd = ['java'] + self.JAVA_OPTS + \- ['-cp', self.ARROW_TOOLS_JAR,- 'org.apache.arrow.tools.StreamToFile', stream_path, file_path]- if self.debug:- print(' '.join(cmd))- run_cmd(cmd)-- def file_to_stream(self, file_path, stream_path):- cmd = ['java'] + self.JAVA_OPTS + \- ['-cp', self.ARROW_TOOLS_JAR,- 'org.apache.arrow.tools.FileToStream', file_path, stream_path]- if self.debug:- print(' '.join(cmd))- run_cmd(cmd)-- def flight_request(self, port, json_path):- cmd = ['java'] + self.JAVA_OPTS + \- ['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_CLIENT,- '-port', str(port), '-j', json_path]- if self.debug:- print(' '.join(cmd))- run_cmd(cmd)-- @contextlib.contextmanager- def flight_server(self):- cmd = ['java'] + self.JAVA_OPTS + \- ['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_SERVER,- '-port', str(self.FLIGHT_PORT)]- if self.debug:- print(' '.join(cmd))- server = subprocess.Popen(cmd, stdout=subprocess.PIPE)- try:- output = server.stdout.readline().decode()- if not output.startswith("Server listening on localhost"):- raise RuntimeError(- "Flight-Java server did not start properly, output: " +- output)- yield- finally:- server.kill()- server.wait(5)---class CPPTester(Tester):- PRODUCER = True- CONSUMER = True- FLIGHT_SERVER = True- FLIGHT_CLIENT = True-- EXE_PATH = os.environ.get(- 'ARROW_CPP_EXE_PATH',- os.path.join(ARROW_HOME, 'cpp/build/debug'))-- CPP_INTEGRATION_EXE = os.path.join(EXE_PATH, 'arrow-json-integration-test')- STREAM_TO_FILE = os.path.join(EXE_PATH, 'arrow-stream-to-file')- FILE_TO_STREAM = os.path.join(EXE_PATH, 'arrow-file-to-stream')-- FLIGHT_PORT = 31337-- FLIGHT_SERVER_CMD = [- os.path.join(EXE_PATH, 'flight-test-integration-server'),- "-port", str(FLIGHT_PORT)]- FLIGHT_CLIENT_CMD = [- os.path.join(EXE_PATH, 'flight-test-integration-client'),- "-host", "localhost"]-- name = 'C++'-- def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):- cmd = [self.CPP_INTEGRATION_EXE, '--integration']-- if arrow_path is not None:- cmd.append('--arrow=' + arrow_path)-- if json_path is not None:- cmd.append('--json=' + json_path)-- cmd.append('--mode=' + command)-- if self.debug:- print(' '.join(cmd))-- run_cmd(cmd)-- def validate(self, json_path, arrow_path):- return self._run(arrow_path, json_path, 'VALIDATE')-- def json_to_file(self, json_path, arrow_path):- return self._run(arrow_path, json_path, 'JSON_TO_ARROW')-- def stream_to_file(self, stream_path, file_path):- cmd = ['cat', stream_path, '|', self.STREAM_TO_FILE, '>', file_path]- self.run_shell_command(cmd)-- def file_to_stream(self, file_path, stream_path):- cmd = [self.FILE_TO_STREAM, file_path, '>', stream_path]- self.run_shell_command(cmd)-- @contextlib.contextmanager- def flight_server(self):- if self.debug:- print(' '.join(self.FLIGHT_SERVER_CMD))- server = subprocess.Popen(self.FLIGHT_SERVER_CMD,- stdout=subprocess.PIPE)- try:- output = server.stdout.readline().decode()- if not output.startswith("Server listening on localhost"):- raise RuntimeError(- "Flight-C++ server did not start properly, output: " +- output)- yield- finally:- server.kill()- server.wait(5)-- def flight_request(self, port, json_path):- cmd = self.FLIGHT_CLIENT_CMD + [- '-port=' + str(port),- '-path=' + json_path,- ]- if self.debug:- print(' '.join(cmd))- run_cmd(cmd)---class JSTester(Tester):- PRODUCER = True- CONSUMER = True-- EXE_PATH = os.path.join(ARROW_HOME, 'js/bin')- VALIDATE = os.path.join(EXE_PATH, 'integration.js')- JSON_TO_ARROW = os.path.join(EXE_PATH, 'json-to-arrow.js')- STREAM_TO_FILE = os.path.join(EXE_PATH, 'stream-to-file.js')- FILE_TO_STREAM = os.path.join(EXE_PATH, 'file-to-stream.js')-- name = 'JS'-- def _run(self, exe_cmd, arrow_path=None, json_path=None,- command='VALIDATE'):- cmd = [exe_cmd]-- if arrow_path is not None:- cmd.extend(['-a', arrow_path])-- if json_path is not None:- cmd.extend(['-j', json_path])-- cmd.extend(['--mode', command])-- if self.debug:- print(' '.join(cmd))-- run_cmd(cmd)-- def validate(self, json_path, arrow_path):- return self._run(self.VALIDATE, arrow_path, json_path, 'VALIDATE')-- def json_to_file(self, json_path, arrow_path):- cmd = ['node',- '--no-warnings', self.JSON_TO_ARROW,- '-a', arrow_path,- '-j', json_path]- self.run_shell_command(cmd)-- def stream_to_file(self, stream_path, file_path):- cmd = ['cat', stream_path, '|',- 'node', '--no-warnings', self.STREAM_TO_FILE, '>',- file_path]- self.run_shell_command(cmd)-- def file_to_stream(self, file_path, stream_path):- cmd = ['cat', file_path, '|',- 'node', '--no-warnings', self.FILE_TO_STREAM, '>',- stream_path]- self.run_shell_command(cmd)---class GoTester(Tester):- PRODUCER = True- CONSUMER = True-- # FIXME(sbinet): revisit for Go modules- GOPATH = os.getenv('GOPATH', '~/go')- GOBIN = os.environ.get('GOBIN', os.path.join(GOPATH, 'bin'))-- GO_INTEGRATION_EXE = os.path.join(GOBIN, 'arrow-json-integration-test')- STREAM_TO_FILE = os.path.join(GOBIN, 'arrow-stream-to-file')- FILE_TO_STREAM = os.path.join(GOBIN, 'arrow-file-to-stream')-- name = 'Go'-- def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):- cmd = [self.GO_INTEGRATION_EXE]-- if arrow_path is not None:- cmd.extend(['-arrow', arrow_path])-- if json_path is not None:- cmd.extend(['-json', json_path])-- cmd.extend(['-mode', command])-- if self.debug:- print(' '.join(cmd))-- run_cmd(cmd)-- def validate(self, json_path, arrow_path):- return self._run(arrow_path, json_path, 'VALIDATE')-- def json_to_file(self, json_path, arrow_path):- return self._run(arrow_path, json_path, 'JSON_TO_ARROW')-- def stream_to_file(self, stream_path, file_path):- cmd = ['cat', stream_path, '|', self.STREAM_TO_FILE, '>', file_path]- self.run_shell_command(cmd)-- def file_to_stream(self, file_path, stream_path):- cmd = [self.FILE_TO_STREAM, file_path, '>', stream_path]- self.run_shell_command(cmd)---def get_static_json_files():- glob_pattern = os.path.join(ARROW_HOME, 'integration', 'data', '*.json')- return [JsonFile(name=os.path.basename(p), path=p, skip=set(),- schema=None, batches=None)- for p in glob.glob(glob_pattern)]---def run_all_tests(args):- testers = []-- if args.enable_cpp:- testers.append(CPPTester(args))-- if args.enable_java:- testers.append(JavaTester(args))-- if args.enable_js:- testers.append(JSTester(args))-- if args.enable_go:- testers.append(GoTester(args))-- static_json_files = get_static_json_files()- generated_json_files = get_generated_json_files(tempdir=args.tempdir,- flight=args.run_flight)- json_files = static_json_files + generated_json_files-- runner = IntegrationRunner(json_files, testers, args)- failures = []- failures.extend(runner.run())- if args.run_flight:- failures.extend(runner.run_flight())-- fail_count = 0- if failures:- print("################# FAILURES #################")- for test_case, producer, consumer, exc_info in failures:- fail_count += 1- print("FAILED TEST:", end=" ")- print(test_case.name, producer.name, "producing, ",- consumer.name, "consuming")- if exc_info:- traceback.print_exception(*exc_info)- print()-- print(fail_count, "failures")- if fail_count > 0:- sys.exit(1)---def write_js_test_json(directory):- generate_map_case().write(os.path.join(directory, 'map.json'))- generate_nested_case().write(os.path.join(directory, 'nested.json'))- generate_decimal_case().write(os.path.join(directory, 'decimal.json'))- generate_datetime_case().write(os.path.join(directory, 'datetime.json'))- (generate_dictionary_case()- .write(os.path.join(directory, 'dictionary.json')))- (generate_primitive_case([])- .write(os.path.join(directory, 'primitive_no_batches.json')))- (generate_primitive_case([7, 10])- .write(os.path.join(directory, 'primitive.json')))- (generate_primitive_case([0, 0, 0])- .write(os.path.join(directory, 'primitive-empty.json')))---if __name__ == '__main__':- parser = argparse.ArgumentParser(description='Arrow integration test CLI')-- parser.add_argument('--enable-c++', dest='enable_cpp',- action='store', type=int, default=1,- help='Include C++ in integration tests')- parser.add_argument('--enable-java', dest='enable_java',- action='store', type=int, default=1,- help='Include Java in integration tests')- parser.add_argument('--enable-js', dest='enable_js',- action='store', type=int, default=1,- help='Include JavaScript in integration tests')- parser.add_argument('--enable-go', dest='enable_go',- action='store', type=int, default=1,- help='Include Go in integration tests')-- parser.add_argument('--write_generated_json', dest='generated_json_path',- action='store', default=False,- help='Generate test JSON')- parser.add_argument('--run_flight', dest='run_flight',- action='store_true', default=False,- help='Run Flight integration tests')- parser.add_argument('--debug', dest='debug', action='store_true',- default=False,- help='Run executables in debug mode as relevant')- parser.add_argument('--tempdir', dest='tempdir',- default=tempfile.mkdtemp(),- help=('Directory to use for writing '- 'integration test temporary files'))-- parser.add_argument('-x', '--stop-on-error', dest='stop_on_error',- action='store_true', default=False,- help='Stop on first error')-- parser.add_argument('--gold_dirs', action='append',- help="gold integration test file paths")-- args = parser.parse_args()- if args.generated_json_path:- try:- os.makedirs(args.generated_json_path)- except OSError as e:- if e.errno != errno.EEXIST:- raise- write_js_test_json(args.generated_json_path)- else:- run_all_tests(args)diff --git a/dev/archery/archery/integration/runner.py b/dev/archery/archery/integration/runner.pynew file mode 100644index 0000000000..9fa3f6194c--- /dev/null+++ b/dev/archery/archery/integration/runner.py@@ -0,0 +1,303 @@+# 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 gzip+import itertools+import os+import sys+import tempfile+import traceback++from .tester_cpp import CPPTester+from .tester_go import GoTester+from .tester_java import JavaTester+from .tester_js import JSTester+from .util import ARROW_ROOT_DEFAULT, guid, SKIP_ARROW, SKIP_FLIGHT+from . import datagen+++class IntegrationRunner(object):++ def __init__(self, json_files, testers, tempdir=None, debug=False,+ stop_on_error=True, gold_dirs=None, **unused_kwargs):+ self.json_files = json_files+ self.testers = testers+ self.temp_dir = tempdir or tempfile.mkdtemp()+ self.debug = debug+ self.stop_on_error = stop_on_error+ self.gold_dirs = gold_dirs++ def run(self):+ failures = []++ for producer, consumer in itertools.product(+ filter(lambda t: t.PRODUCER, self.testers),+ filter(lambda t: t.CONSUMER, self.testers)):+ for failure in self._compare_implementations(+ producer, consumer, self._produce_consume, self.json_files):+ failures.append(failure)+ if self.gold_dirs:+ for gold_dir, consumer in itertools.product(+ self.gold_dirs,+ filter(lambda t: t.CONSUMER, self.testers)):+ print('\n\n\n\n')+ print('******************************************************')+ print('Tests against golden files in {}'.format(gold_dir))+ print('******************************************************')++ def run_gold(producer, consumer, test_case):+ self._run_gold(gold_dir, producer, consumer, test_case)+ for failure in self._compare_implementations(+ consumer, consumer, run_gold, self._gold_tests(gold_dir)):+ failures.append(failure)++ return failures++ def run_flight(self):+ failures = []+ servers = filter(lambda t: t.FLIGHT_SERVER, self.testers)+ clients = filter(lambda t: (t.FLIGHT_CLIENT and t.CONSUMER),+ self.testers)+ for server, client in itertools.product(servers, clients):+ for failure in self._compare_flight_implementations(server,+ client):+ failures.append(failure)+ return failures++ def _gold_tests(self, gold_dir):+ prefix = os.path.basename(os.path.normpath(gold_dir))+ SUFFIX = ".json.gz"+ golds = [jf for jf in os.listdir(gold_dir) if jf.endswith(SUFFIX)]+ for json_path in golds:+ name = json_path[json_path.index('_')+1: -len(SUFFIX)]+ base_name = prefix + "_" + name + ".gold.json"+ out_path = os.path.join(self.temp_dir, base_name)+ with gzip.open(os.path.join(gold_dir, json_path)) as i:+ with open(out_path, "wb") as out:+ out.write(i.read())++ try:+ skip = next(f for f in self.json_files+ if f.name == name).skip+ except StopIteration:+ skip = set()+ yield datagen.JsonFile(name, None, None, skip=skip, path=out_path)++ def _compare_implementations(+ self, producer, consumer, run_binaries, test_cases):+ print('##########################################################')+ print(+ '{0} producing, {1} consuming'.format(producer.name, consumer.name)+ )+ print('##########################################################')++ for test_case in test_cases:+ json_path = test_case.path+ print('==========================================================')+ print('Testing file {0}'.format(json_path))+ print('==========================================================')++ if producer.name in test_case.skip:+ print('-- Skipping test because producer {0} does '+ 'not support'.format(producer.name))+ continue++ if consumer.name in test_case.skip:+ print('-- Skipping test because consumer {0} does '+ 'not support'.format(consumer.name))+ continue++ if SKIP_ARROW in test_case.skip:+ print('-- Skipping test')+ continue++ try:+ run_binaries(producer, consumer, test_case)+ except Exception:+ traceback.print_exc()+ yield (test_case, producer, consumer, sys.exc_info())+ if self.stop_on_error:+ break+ else:+ continue++ def _produce_consume(self, producer, consumer, test_case):+ # Make the random access file+ json_path = test_case.path+ file_id = guid()[:8]+ name = os.path.splitext(os.path.basename(json_path))[0]++ producer_file_path = os.path.join(self.temp_dir, file_id + '_' ++ name + '.json_as_file')+ producer_stream_path = os.path.join(self.temp_dir, file_id + '_' ++ name + '.producer_file_as_stream')+ consumer_file_path = os.path.join(self.temp_dir, file_id + '_' ++ name + '.consumer_stream_as_file')++ print('-- Creating binary inputs')+ producer.json_to_file(json_path, producer_file_path)++ # Validate the file+ print('-- Validating file')+ consumer.validate(json_path, producer_file_path)++ print('-- Validating stream')+ producer.file_to_stream(producer_file_path, producer_stream_path)+ consumer.stream_to_file(producer_stream_path, consumer_file_path)+ consumer.validate(json_path, consumer_file_path)++ def _run_gold(self, gold_dir, producer, consumer, test_case):+ json_path = test_case.path++ # Validate the file+ print('-- Validating file')+ producer_file_path = os.path.join(+ gold_dir, "generated_" + test_case.name + ".arrow_file")+ consumer.validate(json_path, producer_file_path)++ print('-- Validating stream')+ consumer_stream_path = os.path.join(+ gold_dir, "generated_" + test_case.name + ".stream")+ file_id = guid()[:8]+ name = os.path.splitext(os.path.basename(json_path))[0]++ consumer_file_path = os.path.join(self.temp_dir, file_id + '_' ++ name + '.consumer_stream_as_file')++ consumer.stream_to_file(consumer_stream_path, consumer_file_path)+ consumer.validate(json_path, consumer_file_path)++ def _compare_flight_implementations(self, producer, consumer):+ print('##########################################################')+ print(+ '{0} serving, {1} requesting'.format(producer.name, consumer.name)+ )+ print('##########################################################')++ for test_case in self.json_files:+ json_path = test_case.path+ print('=' * 58)+ print('Testing file {0}'.format(json_path))+ print('=' * 58)++ if ('Java' in (producer.name, consumer.name) and+ "map" in test_case.name):+ print('TODO(ARROW-1279): Enable map tests ' ++ ' for Java and JS once Java supports them and JS\'' ++ ' are unbroken')+ continue++ if SKIP_FLIGHT in test_case.skip:+ print('-- Skipping test')+ continue++ try:+ with producer.flight_server():+ # Have the client upload the file, then download and+ # compare+ consumer.flight_request(producer.FLIGHT_PORT, json_path)+ except Exception:+ traceback.print_exc()+ yield (test_case, producer, consumer, sys.exc_info())+ continue+++def get_static_json_files():+ glob_pattern = os.path.join(ARROW_ROOT_DEFAULT,+ 'integration', 'data', '*.json')+ return [+ datagen.JsonFile(name=os.path.basename(p), path=p, skip=set(),+ schema=None, batches=None)+ for p in glob.glob(glob_pattern)+ ]+++def run_all_tests(enable_cpp=True, enable_java=True, enable_js=True,+ enable_go=True, run_flight=False,+ tempdir=None, **kwargs):+ tempdir = tempdir or tempfile.mkdtemp()++ testers = []++ if enable_cpp:+ testers.append(CPPTester(kwargs))++ if enable_java:+ testers.append(JavaTester(kwargs))++ if enable_js:+ testers.append(JSTester(kwargs))++ if enable_go:+ testers.append(GoTester(kwargs))++ static_json_files = get_static_json_files()+ generated_json_files = datagen.get_generated_json_files(+ tempdir=tempdir,+ flight=run_flight+ )+ json_files = static_json_files + generated_json_files++ runner = IntegrationRunner(json_files, testers, **kwargs)+ failures = []+ failures.extend(runner.run())+ if run_flight:+ failures.extend(runner.run_flight())++ fail_count = 0+ if failures:+ print("################# FAILURES #################")+ for test_case, producer, consumer, exc_info in failures:+ fail_count += 1+ print("FAILED TEST:", end=" ")+ print(test_case.name, producer.name, "producing, ",+ consumer.name, "consuming")+ if exc_info:+ traceback.print_exception(*exc_info)+ print()++ print(fail_count, "failures")+ if fail_count > 0:+ sys.exit(1)+++def write_js_test_json(directory):+ datagen.generate_map_case().write(+ os.path.join(directory, 'map.json')+ )+ datagen.generate_nested_case().write(+ os.path.join(directory, 'nested.json')+ )+ datagen.generate_decimal_case().write(+ os.path.join(directory, 'decimal.json')+ )+ datagen.generate_datetime_case().write(+ os.path.join(directory, 'datetime.json')+ )+ datagen.generate_dictionary_case().write(+ os.path.join(directory, 'dictionary.json')+ )+ datagen.generate_primitive_case([]).write(+ os.path.join(directory, 'primitive_no_batches.json')+ )+ datagen.generate_primitive_case([7, 10]).write(+ os.path.join(directory, 'primitive.json')+ )+ datagen.generate_primitive_case([0, 0, 0]).write(+ os.path.join(directory, 'primitive-empty.json')+ )diff --git a/dev/archery/archery/integration/tester.py b/dev/archery/archery/integration/tester.pynew file mode 100644index 0000000000..e3f075a36c--- /dev/null+++ b/dev/archery/archery/integration/tester.py@@ -0,0 +1,56 @@+# 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.++# Base class for language-specific integration test harnesses++import subprocess+++class Tester(object):+ PRODUCER = False+ CONSUMER = False+ FLIGHT_SERVER = False+ FLIGHT_CLIENT = False+ FLIGHT_PORT = 31337++ def __init__(self, debug=False, **args):+ self.args = args+ self.debug = debug++ def run_shell_command(self, cmd):+ cmd = ' '.join(cmd)+ if self.debug:+ print(cmd)+ subprocess.check_call(cmd, shell=True)++ def json_to_file(self, json_path, arrow_path):+ raise NotImplementedError++ def stream_to_file(self, stream_path, file_path):+ raise NotImplementedError++ def file_to_stream(self, file_path, stream_path):+ raise NotImplementedError++ def validate(self, json_path, arrow_path):+ raise NotImplementedError++ def flight_server(self):+ raise NotImplementedError++ def flight_request(self, port, json_path):+ raise NotImplementedErrordiff --git a/dev/archery/archery/integration/tester_cpp.py b/dev/archery/archery/integration/tester_cpp.pynew file mode 100644index 0000000000..541aaf27ac--- /dev/null+++ b/dev/archery/archery/integration/tester_cpp.py@@ -0,0 +1,105 @@+# 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 contextlib+import os+import subprocess++from .tester import Tester+from .util import run_cmd, ARROW_ROOT_DEFAULT+++class CPPTester(Tester):+ PRODUCER = True+ CONSUMER = True+ FLIGHT_SERVER = True+ FLIGHT_CLIENT = True++ EXE_PATH = os.environ.get(+ 'ARROW_CPP_EXE_PATH',+ os.path.join(ARROW_ROOT_DEFAULT, 'cpp/build/debug'))++ CPP_INTEGRATION_EXE = os.path.join(EXE_PATH, 'arrow-json-integration-test')+ STREAM_TO_FILE = os.path.join(EXE_PATH, 'arrow-stream-to-file')+ FILE_TO_STREAM = os.path.join(EXE_PATH, 'arrow-file-to-stream')++ FLIGHT_PORT = 31337++ FLIGHT_SERVER_CMD = [+ os.path.join(EXE_PATH, 'flight-test-integration-server'),+ "-port", str(FLIGHT_PORT)]+ FLIGHT_CLIENT_CMD = [+ os.path.join(EXE_PATH, 'flight-test-integration-client'),+ "-host", "localhost"]++ name = 'C++'++ def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):+ cmd = [self.CPP_INTEGRATION_EXE, '--integration']++ if arrow_path is not None:+ cmd.append('--arrow=' + arrow_path)++ if json_path is not None:+ cmd.append('--json=' + json_path)++ cmd.append('--mode=' + command)++ if self.debug:+ print(' '.join(cmd))++ run_cmd(cmd)++ def validate(self, json_path, arrow_path):+ return self._run(arrow_path, json_path, 'VALIDATE')++ def json_to_file(self, json_path, arrow_path):+ return self._run(arrow_path, json_path, 'JSON_TO_ARROW')++ def stream_to_file(self, stream_path, file_path):+ cmd = ['cat', stream_path, '|', self.STREAM_TO_FILE, '>', file_path]+ self.run_shell_command(cmd)++ def file_to_stream(self, file_path, stream_path):+ cmd = [self.FILE_TO_STREAM, file_path, '>', stream_path]+ self.run_shell_command(cmd)++ @contextlib.contextmanager+ def flight_server(self):+ if self.debug:+ print(' '.join(self.FLIGHT_SERVER_CMD))+ server = subprocess.Popen(self.FLIGHT_SERVER_CMD,+ stdout=subprocess.PIPE)+ try:+ output = server.stdout.readline().decode()+ if not output.startswith("Server listening on localhost"):+ raise RuntimeError(+ "Flight-C++ server did not start properly, output: " ++ output)+ yield+ finally:+ server.kill()+ server.wait(5)++ def flight_request(self, port, json_path):+ cmd = self.FLIGHT_CLIENT_CMD + [+ '-port=' + str(port),+ '-path=' + json_path,+ ]+ if self.debug:+ print(' '.join(cmd))+ run_cmd(cmd)diff --git a/dev/archery/archery/integration/tester_go.py b/dev/archery/archery/integration/tester_go.pynew file mode 100644index 0000000000..27df4d1f5b--- /dev/null+++ b/dev/archery/archery/integration/tester_go.py@@ -0,0 +1,66 @@+# 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++from .tester import Tester+from .util import run_cmd+++class GoTester(Tester):+ PRODUCER = True+ CONSUMER = True++ # FIXME(sbinet): revisit for Go modules+ GOPATH = os.getenv('GOPATH', '~/go')+ GOBIN = os.environ.get('GOBIN', os.path.join(GOPATH, 'bin'))++ GO_INTEGRATION_EXE = os.path.join(GOBIN, 'arrow-json-integration-test')+ STREAM_TO_FILE = os.path.join(GOBIN, 'arrow-stream-to-file')+ FILE_TO_STREAM = os.path.join(GOBIN, 'arrow-file-to-stream')++ name = 'Go'++ def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):+ cmd = [self.GO_INTEGRATION_EXE]++ if arrow_path is not None:+ cmd.extend(['-arrow', arrow_path])++ if json_path is not None:+ cmd.extend(['-json', json_path])++ cmd.extend(['-mode', command])++ if self.debug:+ print(' '.join(cmd))++ run_cmd(cmd)++ def validate(self, json_path, arrow_path):+ return self._run(arrow_path, json_path, 'VALIDATE')++ def json_to_file(self, json_path, arrow_path):+ return self._run(arrow_path, json_path, 'JSON_TO_ARROW')++ def stream_to_file(self, stream_path, file_path):+ cmd = ['cat', stream_path, '|', self.STREAM_TO_FILE, '>', file_path]+ self.run_shell_command(cmd)++ def file_to_stream(self, file_path, stream_path):+ cmd = [self.FILE_TO_STREAM, file_path, '>', stream_path]+ self.run_shell_command(cmd)diff --git a/dev/archery/archery/integration/tester_java.py b/dev/archery/archery/integration/tester_java.pynew file mode 100644index 0000000000..f37291d94b--- /dev/null+++ b/dev/archery/archery/integration/tester_java.py@@ -0,0 +1,126 @@+# 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 contextlib+import os+import subprocess++from .tester import Tester+from .util import run_cmd, ARROW_ROOT_DEFAULT+++def load_version_from_pom():+ import xml.etree.ElementTree as ET+ tree = ET.parse(os.path.join(ARROW_ROOT_DEFAULT, 'java', 'pom.xml'))+ tag_pattern = '{http://maven.apache.org/POM/4.0.0}version'+ version_tag = list(tree.getroot().findall(tag_pattern))[0]+ return version_tag.text+++class JavaTester(Tester):+ PRODUCER = True+ CONSUMER = True+ FLIGHT_SERVER = True+ FLIGHT_CLIENT = True++ FLIGHT_PORT = 31338++ JAVA_OPTS = ['-Dio.netty.tryReflectionSetAccessible=true']++ _arrow_version = load_version_from_pom()+ ARROW_TOOLS_JAR = os.environ.get(+ 'ARROW_JAVA_INTEGRATION_JAR',+ os.path.join(ARROW_ROOT_DEFAULT,+ 'java/tools/target/arrow-tools-{}-'+ 'jar-with-dependencies.jar'.format(_arrow_version)))+ ARROW_FLIGHT_JAR = os.environ.get(+ 'ARROW_FLIGHT_JAVA_INTEGRATION_JAR',+ os.path.join(ARROW_ROOT_DEFAULT,+ 'java/flight/target/arrow-flight-{}-'+ 'jar-with-dependencies.jar'.format(_arrow_version)))+ ARROW_FLIGHT_SERVER = ('org.apache.arrow.flight.example.integration.'+ 'IntegrationTestServer')+ ARROW_FLIGHT_CLIENT = ('org.apache.arrow.flight.example.integration.'+ 'IntegrationTestClient')++ name = 'Java'++ def _run(self, arrow_path=None, json_path=None, command='VALIDATE'):+ cmd = ['java'] + self.JAVA_OPTS + \+ ['-cp', self.ARROW_TOOLS_JAR, 'org.apache.arrow.tools.Integration']++ if arrow_path is not None:+ cmd.extend(['-a', arrow_path])++ if json_path is not None:+ cmd.extend(['-j', json_path])++ cmd.extend(['-c', command])++ if self.debug:+ print(' '.join(cmd))++ run_cmd(cmd)++ def validate(self, json_path, arrow_path):+ return self._run(arrow_path, json_path, 'VALIDATE')++ def json_to_file(self, json_path, arrow_path):+ return self._run(arrow_path, json_path, 'JSON_TO_ARROW')++ def stream_to_file(self, stream_path, file_path):+ cmd = ['java'] + self.JAVA_OPTS + \+ ['-cp', self.ARROW_TOOLS_JAR,+ 'org.apache.arrow.tools.StreamToFile', stream_path, file_path]+ if self.debug:+ print(' '.join(cmd))+ run_cmd(cmd)++ def file_to_stream(self, file_path, stream_path):+ cmd = ['java'] + self.JAVA_OPTS + \+ ['-cp', self.ARROW_TOOLS_JAR,+ 'org.apache.arrow.tools.FileToStream', file_path, stream_path]+ if self.debug:+ print(' '.join(cmd))+ run_cmd(cmd)++ def flight_request(self, port, json_path):+ cmd = ['java'] + self.JAVA_OPTS + \+ ['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_CLIENT,+ '-port', str(port), '-j', json_path]+ if self.debug:+ print(' '.join(cmd))+ run_cmd(cmd)++ @contextlib.contextmanager+ def flight_server(self):+ cmd = ['java'] + self.JAVA_OPTS + \+ ['-cp', self.ARROW_FLIGHT_JAR, self.ARROW_FLIGHT_SERVER,+ '-port', str(self.FLIGHT_PORT)]+ if self.debug:+ print(' '.join(cmd))+ server = subprocess.Popen(cmd, stdout=subprocess.PIPE)+ try:+ output = server.stdout.readline().decode()+ if not output.startswith("Server listening on localhost"):+ raise RuntimeError(+ "Flight-Java server did not start properly, output: " ++ output)+ yield+ finally:+ server.kill()+ server.wait(5)diff --git a/dev/archery/archery/integration/tester_js.py b/dev/archery/archery/integration/tester_js.pynew file mode 100644index 0000000000..34939d040e--- /dev/null+++ b/dev/archery/archery/integration/tester_js.py@@ -0,0 +1,73 @@+# 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++from .tester import Tester+from .util import run_cmd, ARROW_ROOT_DEFAULT+++class JSTester(Tester):+ PRODUCER = True+ CONSUMER = True++ EXE_PATH = os.path.join(ARROW_ROOT_DEFAULT, 'js/bin')+ VALIDATE = os.path.join(EXE_PATH, 'integration.js')+ JSON_TO_ARROW = os.path.join(EXE_PATH, 'json-to-arrow.js')+ STREAM_TO_FILE = os.path.join(EXE_PATH, 'stream-to-file.js')+ FILE_TO_STREAM = os.path.join(EXE_PATH, 'file-to-stream.js')++ name = 'JS'++ def _run(self, exe_cmd, arrow_path=None, json_path=None,+ command='VALIDATE'):+ cmd = [exe_cmd]++ if arrow_path is not None:+ cmd.extend(['-a', arrow_path])++ if json_path is not None:+ cmd.extend(['-j', json_path])++ cmd.extend(['--mode', command])++ if self.debug:+ print(' '.join(cmd))++ run_cmd(cmd)++ def validate(self, json_path, arrow_path):+ return self._run(self.VALIDATE, arrow_path, json_path, 'VALIDATE')++ def json_to_file(self, json_path, arrow_path):+ cmd = ['node',+ '--no-warnings', self.JSON_TO_ARROW,+ '-a', arrow_path,+ '-j', json_path]+ self.run_shell_command(cmd)++ def stream_to_file(self, stream_path, file_path):+ cmd = ['cat', stream_path, '|',+ 'node', '--no-warnings', self.STREAM_TO_FILE, '>',+ file_path]+ self.run_shell_command(cmd)++ def file_to_stream(self, file_path, stream_path):+ cmd = ['cat', file_path, '|',+ 'node', '--no-warnings', self.FILE_TO_STREAM, '>',+ stream_path]+ self.run_shell_command(cmd)diff --git a/dev/archery/archery/integration/util.py b/dev/archery/archery/integration/util.pynew file mode 100644index 0000000000..4410295b4e--- /dev/null+++ b/dev/archery/archery/integration/util.py@@ -0,0 +1,81 @@+# 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+import six+import string+import subprocess+import uuid++import numpy as np+++def guid():+ return uuid.uuid4().hex+++RANDS_CHARS = np.array(list(string.ascii_letters + string.digits),+ dtype=(np.str_, 1))++# SKIP categories+SKIP_ARROW = 'arrow'+SKIP_FLIGHT = 'flight'++ARROW_ROOT_DEFAULT = os.environ.get(+ 'ARROW_ROOT',+ os.path.abspath(__file__).rsplit("/", 4)[0]+)+++def rands(nchars):+ """+ Generate one random byte string.++ See `rands_array` if you want to create an array of random strings.++ """+ return ''.join(np.random.choice(RANDS_CHARS, nchars))+++def tobytes(o):+ if isinstance(o, six.text_type):+ return o.encode('utf8')+ return o+++def frombytes(o):+ if isinstance(o, six.binary_type):+ return o.decode('utf8')+ return o+++def run_cmd(cmd):+ if isinstance(cmd, six.string_types):+ cmd = cmd.split(' ')++ try:+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)+ except subprocess.CalledProcessError as e:+ # this avoids hiding the stdout / stderr of failed processes+ print('Command failed: %s' % ' '.join(cmd))+ print('With output:')+ print('--------------')+ print(frombytes(e.output))+ print('--------------')+ raise e++ return frombytes(output)diff --git a/dev/release/verify-release-candidate.sh b/dev/release/verify-release-candidate.shindex 37ea560acd..021c0b1937 100755--- a/dev/release/verify-release-candidate.sh+++ b/dev/release/verify-release-candidate.sh@@ -441,20 +441,23 @@ test_integration() {export ARROW_JAVA_INTEGRATION_JAR=$JAVA_DIR/tools/target/arrow-tools-$VERSION-jar-with-dependencies.jarexport ARROW_CPP_EXE_PATH=$CPP_BUILD_DIR/release- pushd integration+ pip3 install -e dev/archery- INTEGRATION_TEST_ARGS="--enable-c++=${TEST_INTEGRATION_CPP} --enable-java=${TEST_INTEGRATION_JAVA} --enable-js=${TEST_INTEGRATION_JS} --enable-go=${TEST_INTEGRATION_GO}"+ INTEGRATION_TEST_ARGS=""if [ "${ARROW_FLIGHT}" = "ON" ]; then- INTEGRATION_TEST_ARGS="${INTEGRATION_TEST_ARGS} --run_flight"+ INTEGRATION_TEST_ARGS="${INTEGRATION_TEST_ARGS} --run-flight"fi# Flight integration test executable have runtime dependency on# release/libgtest.soLD_LIBRARY_PATH=$ARROW_CPP_EXE_PATH:$LD_LIBRARY_PATH \- python integration_test.py $INTEGRATION_TEST_ARGS-- popd+ archery integration \+ --with-cpp=${TEST_INTEGRATION_CPP} \+ --with-java=${TEST_INTEGRATION_JAVA} \+ --with-js=${TEST_INTEGRATION_JS} \+ --with-go=${TEST_INTEGRATION_GO} \+ $INTEGRATION_TEST_ARGS}test_source_distribution() {diff --git a/docker-compose.yml b/docker-compose.ymlindex 19ab185bab..b6ad685da6 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -300,6 +300,15 @@ services:dockerfile: go/Dockerfilevolumes: *ubuntu-volumes+ integration:+ image: arrowdev/arrow-integration:latest+ build:+ context: .+ dockerfile: integration/Dockerfile+ volumes:+ - .:/arrow:ro # ensures that docker won't contaminate the host directory+ - maven-cache:/root/.m2:delegated+java:# Usage:# docker-compose build javadiff --git a/integration/Dockerfile b/integration/Dockerfilenew file mode 100644index 0000000000..5f3d2e7998--- /dev/null+++ b/integration/Dockerfile@@ -0,0 +1,52 @@+# 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.++FROM arrowdev/arrow-cpp:latest++# Use bash+SHELL ["/bin/bash", "-o", "pipefail", "-c"]++# install apt extra stuff we need+RUN apt-get update -y -q && \+ apt-get install -y -q --no-install-recommends \+ curl \+ maven \+ rsync \+ tzdata \+ openjdk-11-jdk && \+ apt-get clean && rm -rf /var/lib/apt/lists/*++# Various environment variables+ENV GOROOT=/go \+ GOPATH=/ \+ LC_ALL=C.UTF-8 \+ LANG=C.UTF-8 \+ NVM_DIR=/.nvm \+ NODE_VERSION=11.12++# Install Go+RUN curl -sL --output go.tar.gz https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz && \+ tar -xf go.tar.gz && \+ rm go.tar.gz++ENV PATH $PATH:$GOROOT/bin++# Install Node with nvm+RUN mkdir $NVM_DIR && \+ curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.0/install.sh | bash++CMD ["arrow/ci/docker_integration.sh"]\ No newline at end of filediff --git a/integration/README.md b/integration/README.mdindex 760a175027..e9be92876d 100644--- a/integration/README.md+++ b/integration/README.md@@ -33,7 +33,7 @@ Our strategy for integration testing between Arrow implementations is as follows## Environment setupThe integration test data generator and runner is written in Python and-currently requires Python 3.5 or higher. You can create a standalone Python+currently requires Python 3.6 or higher. You can create a standalone Pythondistribution and environment for running the tests by using [miniconda][1]. OnLinux this is:@@ -57,35 +57,26 @@ After this, you can follow the instructions in the next section.## Running the existing integration tests-First, build the Java and C++ projects. For Java, you must run+The integration tests are run using the `archery integration` command.```-mvn package+archery integration --help```-Now, the integration tests rely on two environment variables which point to the-Java `arrow-tool` JAR and the build path for the C++ executables:+Depending on which components you have built, you can enable and add them to+the test run. For example, if you only have the C++ project built, you set:-```bash-JAVA_DIR=$ARROW_HOME/java-CPP_BUILD_DIR=$ARROW_HOME/cpp/build--VERSION=0.11.0-SNAPSHOT-export ARROW_JAVA_INTEGRATION_JAR=$JAVA_DIR/tools/target/arrow-tools-$VERSION-jar-with-dependencies.jar+```export ARROW_CPP_EXE_PATH=$CPP_BUILD_DIR/debug+archery integration --enable-cpp=1```-Here `$ARROW_HOME` is the location of your Arrow git clone. The-`$CPP_BUILD_DIR` may be different depending on how you built with CMake-(in-source or out-of-source).--Once this is done, run the integration tests with (optionally adding `--debug`-for additional output)+For Java, it may look like:```-python integration_test.py--python integration_test.py --debug # additional output+VERSION=0.11.0-SNAPSHOT+export ARROW_JAVA_INTEGRATION_JAR=$JAVA_DIR/tools/target/arrow-tools-$VERSION-jar-with-dependencies.jar+archery integration --enable-cpp=1 --enable-java=1```[1]: https://conda.io/miniconda.html