Skip to content

Commit 9c54a78

Browse files
committed
Support MySQL backend
Bug: T242055
1 parent 8d6a81e commit 9c54a78

File tree

7 files changed

+80
-14
lines changed

7 files changed

+80
-14
lines changed

.travis.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,30 @@ notifications:
1414
addons:
1515
apt:
1616
packages:
17-
- openjdk-8-jre-headless
17+
- openjdk-8-jre-headless
18+
19+
services:
20+
- mysql
1821

1922
env:
2023
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=sqlite TEST_MODE=fs
2124
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=cassandra TEST_MODE=fs
25+
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=mysql TEST_MODE=fs
2226
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=sqlite TEST_MODE=fefs
2327
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=cassandra TEST_MODE=fefs
28+
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=mysql TEST_MODE=fefs
2429
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=sqlite TEST_MODE=febe
2530
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=cassandra TEST_MODE=febe
31+
- CASSANDRA_VERSION=3.11.4 TEST_TARGET=mysql TEST_MODE=febe
32+
33+
matrix:
34+
allow_failures:
35+
- node_js: "6"
36+
env: CASSANDRA_VERSION=3.11.4 TEST_TARGET=mysql TEST_MODE=fs
37+
- node_js: "6"
38+
env: CASSANDRA_VERSION=3.11.4 TEST_TARGET=mysql TEST_MODE=fefs
39+
- node_js: "6"
40+
env: CASSANDRA_VERSION=3.11.4 TEST_TARGET=mysql TEST_MODE=febe
2641

2742
before_install:
2843
- wget https://archive.apache.org/dist/cassandra/${CASSANDRA_VERSION}/apache-cassandra-${CASSANDRA_VERSION}-bin.tar.gz -P ../
@@ -32,6 +47,11 @@ before_install:
3247
- echo "-Xms256m" >> ../apache-cassandra-${CASSANDRA_VERSION}/conf/jvm.options
3348
- echo "-Xmx512m" >> ../apache-cassandra-${CASSANDRA_VERSION}/conf/jvm.options
3449
- sed -i -e 's/^-XX:+UseNUMA/#-XX:+UseNUMA/' ../apache-cassandra-${CASSANDRA_VERSION}/conf/jvm.options
35-
- if [[ ${TEST_TARGET} == 'cassandra' ]]; then bash -x ../apache-cassandra-${CASSANDRA_VERSION}/bin/cassandra; else /bin/true; fi
50+
- if [[ ${TEST_TARGET} == 'cassandra' ]]; then bash -x ../apache-cassandra-${CASSANDRA_VERSION}/bin/cassandra;
51+
elif [[ ${TEST_TARGET} == 'mysql' ]]; then
52+
mysql -uroot -e "CREATE DATABASE \`test_db\`;";
53+
mysql -uroot -e "CREATE USER 'mysql'@\`%\` IDENTIFIED BY 'mysql';";
54+
mysql -uroot -e "GRANT ALL PRIVILEGES ON \`test_db\`.* TO 'mysql'@\`%\`;";
55+
else /bin/true; fi
3656

3757
script: npm run lint && npm run coverage -- ${TEST_TARGET} ${TEST_MODE} && (npm run-script coveralls || exit 0)

config.backend.test.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ default_project: &default_project
2828
backend: '{env(RB_TEST_BACKEND, sqlite)}'
2929
hosts: [localhost]
3030
keyspace: system
31-
username: cassandra
32-
password: cassandra
31+
username: '{env(RB_TEST_BACKEND_USERNAME, cassandra)}'
32+
password: '{env(RB_TEST_BACKEND_PASSWORD, cassandra)}'
3333
defaultConsistency: one # or 'localQuorum' for production
3434
storage_groups:
3535
- name: test.group.local
3636
domains: /./
37-
# ignored in cassandra, but useful in SQLite testing
38-
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}'
37+
host: localhost # ignored in cassandra, but useful in MySQL testing
38+
database: test_db # ignored in cassandra, but useful in MySQL testing
39+
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}' # ignored in cassandra, but useful in SQLite testing
3940
/action:
4041
x-modules:
4142
- path: sys/action.js

config.fullstack.test.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ default_project: &default_project
7171
backend: '{env(RB_TEST_BACKEND, sqlite)}'
7272
hosts: [localhost]
7373
keyspace: system
74-
username: cassandra
75-
password: cassandra
74+
username: '{env(RB_TEST_BACKEND_USERNAME, cassandra)}'
75+
password: '{env(RB_TEST_BACKEND_PASSWORD, cassandra)}'
7676
defaultConsistency: one # or 'localQuorum' for production
7777
storage_groups:
7878
- name: test.group.local
7979
domains: /./
80-
# ignored in cassandra, but useful in SQLite testing
81-
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}'
80+
host: localhost # ignored in cassandra, but useful in MySQL testing
81+
database: test_db # ignored in cassandra, but useful in MySQL testing
82+
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}' # ignored in cassandra, but useful in SQLite testing
8283

8384
wikimedia_project: &wikimedia_project
8485
x-modules:

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"tables",
2626
"queues",
2727
"cassandra",
28+
"mysql",
2829
"kafka"
2930
],
3031
"author": "Wikimedia Service Team <services@wikimedia.org>",
@@ -43,6 +44,7 @@
4344
"jsonwebtoken": "^8.5.1",
4445
"mediawiki-title": "^0.7.2",
4546
"restbase-mod-table-cassandra": "^1.2.1",
47+
"restbase-mod-table-mysql": "^0.1.1",
4648
"semver": "latest",
4749
"service-runner": "^2.7.3",
4850
"uuid": "^3.3.3"

sys/table.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ module.exports = (options) => {
99
options.conf.backend = options.conf.backend || 'cassandra';
1010
options.log = options.logger.log.bind(options.logger);
1111

12-
if (options.conf.backend !== 'cassandra' &&
13-
options.conf.backend !== 'sqlite') {
12+
if (
13+
options.conf.backend !== 'cassandra' &&
14+
options.conf.backend !== 'mysql' &&
15+
options.conf.backend !== 'sqlite'
16+
) {
1417
throw new Error(`Unsupported backend version specified: ${options.conf.backend}`);
1518
}
1619

test/utils/cleandb.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
rb_test_backend=${RB_TEST_BACKEND:-$2}
4+
35
dropKeyspaces ( ) {
46
if [ "$#" -eq 1 ]
57
then
@@ -13,4 +15,26 @@ dropKeyspaces ( ) {
1315
fi
1416
}
1517

16-
dropKeyspaces "local_group_test"
18+
dropTables ( ) {
19+
if [ "$#" -eq 1 ]
20+
then
21+
DATABASE=$1
22+
echo "looking for database named '*$DATABASE*'..."
23+
echo 'begin;' | mysql -BD${DATABASE}
24+
for TABLE in `echo 'show tables;' | mysql -BD${DATABASE}`
25+
do
26+
echo dropping table $TABLE
27+
echo "drop table if exists $TABLE;" | mysql -BD${DATABASE}
28+
done
29+
echo 'commit;' | mysql -BD${DATABASE}
30+
fi
31+
}
32+
33+
if [ "$rb_test_backend" = "cassandra" ]; then
34+
dropKeyspaces "local_group_test"
35+
elif [ "$rb_test_backend" = "mysql" ]; then
36+
dropTables "test_db"
37+
else
38+
echo "Invalid TEST_TARGET $rb_test_backend. Must me 'sqlite', 'cassandra' or 'mysql' if specified"
39+
exit 1
40+
fi

test/utils/run_tests.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,24 @@ elif [ "$test_target" = "cassandra" ]; then
3333
echo "Cassandra is ready."
3434
fi
3535
export RB_TEST_BACKEND=cassandra
36+
export RB_TEST_BACKEND_USERNAME=cassandra
37+
export RB_TEST_BACKEND_PASSWORD=cassandra
38+
sh ./test/utils/cleandb.sh local_group_test
39+
elif [ "$test_target" = "mysql" ]; then
40+
echo "Running with MySQL backend"
41+
if [ `nc -z localhost 3306 < /dev/null; echo $?` != 0 ]; then
42+
echo "Waiting for MySQL to start..."
43+
while [ `nc -z localhost 3306; echo $?` != 0 ]; do
44+
sleep 1
45+
done
46+
echo "MySQL is ready."
47+
fi
48+
export RB_TEST_BACKEND=mysql
49+
export RB_TEST_BACKEND_USERNAME=mysql
50+
export RB_TEST_BACKEND_PASSWORD=mysql
3651
sh ./test/utils/cleandb.sh local_group_test
3752
else
38-
echo "Invalid TEST_TARGET $test_target. Must me 'sqlite' or 'cassandra' if specified"
53+
echo "Invalid TEST_TARGET $test_target. Must me 'sqlite', 'cassandra' or 'mysql' if specified"
3954
exit 1
4055
fi
4156

0 commit comments

Comments
 (0)