Skip to content

Commit f30d7af

Browse files
liufuyangtennix
authored andcommitted
Add script to test TiSpark (#33)
* Add script to test TiSpark * Remove mysql test, use tispark-tests to test tidb connection
1 parent a51525f commit f30d7af

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ services:
44
- docker
55

66
before_install:
7+
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
8+
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
9+
- sudo apt-get update
10+
- sudo apt-get -y install docker-ce # update docker version
11+
- sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
12+
- docker -v
13+
- docker-compose -v
714
- docker-compose up -d
8-
- sleep 5 # wait all components get ready
15+
- sleep 10 # wait all components get ready
916
- docker-compose ps
17+
- docker images
18+
- docker network ls
1019
- docker-compose logs
1120

1221
script:
1322
- docker ps -a --format="{{.Names}} {{.Image}} {{.Status}}" | grep -v 'Up' | grep -v 'Exited (0)' | awk '{print} END {if (NR>0) {exit 1;}}'
14-
- mysql -h 127.0.0.1 -P 4000 -u root -e "select tidb_version()\G" # test if tidb-server is working
23+
- docker-compose -f docker-compose-test.yml run --rm tispark-tests bash /opt/spark/tests/loaddata.sh # add some data for tests
24+
- docker-compose -f docker-compose-test.yml run --rm tispark-tests /opt/spark/bin/spark-submit /opt/spark/tests/tests.py # run tispark tests

docker-compose-test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '2.1'
2+
3+
services:
4+
tispark-tests:
5+
image: pingcap/tispark:latest
6+
volumes:
7+
- ./config/spark-defaults.conf:/opt/spark/conf/spark-defaults.conf:ro
8+
- ./tispark-tests/tests:/opt/spark/tests:ro
9+
10+
networks:
11+
default:
12+
external:
13+
name: tidb-docker-compose_default

tispark-tests/tests/loaddata.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
cd /opt/spark/data/tispark-sample-data
4+
5+
mysql -h tidb -P 4000 -u root < dss.ddl

tispark-tests/tests/tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pyspark.sql import SparkSession
2+
import pytispark.pytispark as pti
3+
4+
spark = SparkSession.builder.master("spark://tispark-master:7077").appName("TiSpark tests").getOrCreate()
5+
6+
ti = pti.TiContext(spark)
7+
8+
ti.tidbMapDatabase("TPCH_001")
9+
10+
count = spark.sql("select count(*) as c from lineitem").first()['c']
11+
12+
assert 60175 == count

0 commit comments

Comments
 (0)