Skip to content

Commit 9b5e233

Browse files
authored
Add initial HDFS tests (#1225)
* Add initial HDFS tests Signed-off-by: Yong Tang <yong.tang.github@outlook.com> * Install Java and libhdfs.so for tests * Fix kokorun Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
1 parent 71d9603 commit 9b5e233

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

.github/workflows/build.wheel.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,20 @@ if [[ $(uname) == "Linux" ]]; then
2929
apt-get -y -qq install $PYTHON_VERSION ffmpeg dnsutils libmp3lame0
3030
curl -sSOL https://bootstrap.pypa.io/get-pip.py
3131
$PYTHON_VERSION get-pip.py -q
32+
33+
# Install Java
34+
apt-get -y -qq install openjdk-8-jdk
35+
update-alternatives --config java
36+
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
37+
38+
# Install Hadoop
39+
curl -OL https://archive.apache.org/dist/hadoop/common/hadoop-2.7.0/hadoop-2.7.0.tar.gz
40+
tar -xzf hadoop-2.7.0.tar.gz -C /usr/local
41+
export HADOOP_HOME=/usr/local/hadoop-2.7.0
42+
43+
# Update environmental variable
44+
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${JAVA_HOME}/jre/lib/amd64/server:${HADOOP_HOME}/lib/native
45+
export CLASSPATH=$(${HADOOP_HOME}/bin/hadoop classpath --glob)
46+
export
3247
fi
3348
run_test $PYTHON_VERSION

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ jobs:
298298
bash -x -e tests/test_sql/sql_test.sh
299299
bash -x -e tests/test_gcloud/test_gcs.sh gcs-emulator
300300
bash -x -e tests/test_pulsar/pulsar_test.sh
301+
bash -x -e tests/test_hdfs/hdfs_test.sh
301302
- name: Test Linux
302303
run: |
303304
set -x -e

.kokorun/io_cpu.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ bash -x -e tests/test_azure/start_azure.sh
8181
bash -x -e tests/test_sql/sql_test.sh sql
8282
bash -x -e tests/test_elasticsearch/elasticsearch_test.sh start
8383
bash -x -e tests/test_mongodb/mongodb_test.sh start
84+
bash -x -e tests/test_hdfs/hdfs_test.sh
8485

8586
docker run -i --rm -v $PWD:/v -w /v --net=host \
8687
buildpack-deps:20.04 bash -x -e .github/workflows/build.wheel.sh python${PYTHON_VERSION}

tests/test_hdfs/hdfs_test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
17+
set -e
18+
set -o pipefail
19+
20+
HADOOP_VERSION=2.7.0
21+
docker pull sequenceiq/hadoop-docker:$HADOOP_VERSION
22+
docker run -d --rm --net=host --name=tensorflow-io-hdfs sequenceiq/hadoop-docker:$HADOOP_VERSION
23+
echo "Waiting for 30 secs until hadoop is up and running"
24+
sleep 30
25+
docker logs tensorflow-io-hdfs
26+
echo "Hadoop up"
27+
exit 0

tests/test_hdfs_eager.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
# use this file except in compliance with the License. You may obtain a copy of
5+
# the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations under
13+
# the License.
14+
# ==============================================================================
15+
"""Tests for HDFS file system"""
16+
17+
import os
18+
import sys
19+
import socket
20+
import time
21+
import tempfile
22+
import tensorflow as tf
23+
import tensorflow_io as tfio
24+
import pytest
25+
26+
27+
@pytest.mark.skipif(
28+
sys.platform in ("win32", "darwin"),
29+
reason="TODO HDFS not setup properly on macOS/Windows yet",
30+
)
31+
def test_read_file():
32+
"""Test case for reading HDFS"""
33+
34+
address = socket.gethostbyname(socket.gethostname())
35+
print("ADDRESS: {}".format(address))
36+
37+
body = b"1234567"
38+
tf.io.write_file("hdfse://{}:9000/file.txt".format(address), body)
39+
40+
content = tf.io.read_file("hdfse://{}:9000/file.txt".format(address))
41+
print("CONTENT: {}".format(content))
42+
assert content == body

0 commit comments

Comments
 (0)