Skip to content

Commit

Permalink
Support MySQL backend
Browse files Browse the repository at this point in the history
Bug: T242055
  • Loading branch information
lens0021 committed Jul 27, 2020
1 parent e578e79 commit 460ee9a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
node-version: [6.11, 10.x, 12.x]
cassandra-version: [3.11.4]
test-target: [sqlite, cassandra]
test-target: [sqlite, cassandra, mysql]
test-mode: [fs, fefs, febe]

steps:
Expand All @@ -43,5 +43,12 @@ jobs:
sed -i -e 's/^-XX:+UseNUMA/#-XX:+UseNUMA/' ../apache-cassandra-${{ matrix.cassandra-version }}/conf/jvm.options
export PATH=${PATH}:../apache-cassandra-${{ matrix.cassandra-version }}/bin
cassandra
- name: Setup MySql
if: matrix.test-target == 'mysql'
run: |
sudo systemctl start mysql.service
mysql -uroot -proot -e "CREATE DATABASE \`test_db\`;";
mysql -uroot -proot -e "CREATE USER 'mysql'@\`%\` IDENTIFIED BY 'mysql';";
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON \`test_db\`.* TO 'mysql'@\`%\`;";
- run: npm install
- run: npm run lint && npm run coverage -- ${{ matrix.test-target }} ${{ matrix.test-mode }}
9 changes: 5 additions & 4 deletions config.backend.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ default_project: &default_project
backend: '{env(RB_TEST_BACKEND, sqlite)}'
hosts: [localhost]
keyspace: system
username: cassandra
password: cassandra
username: '{env(RB_TEST_BACKEND_USERNAME, cassandra)}'
password: '{env(RB_TEST_BACKEND_PASSWORD, cassandra)}'
defaultConsistency: one # or 'localQuorum' for production
storage_groups:
- name: test.group.local
domains: /./
# ignored in cassandra, but useful in SQLite testing
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}'
host: localhost # ignored in cassandra, but useful in MySQL testing
database: test_db # ignored in cassandra, but useful in MySQL testing
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}' # ignored in cassandra, but useful in SQLite testing
/action:
x-modules:
- path: sys/action.js
Expand Down
9 changes: 5 additions & 4 deletions config.fullstack.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ default_project: &default_project
backend: '{env(RB_TEST_BACKEND, sqlite)}'
hosts: [localhost]
keyspace: system
username: cassandra
password: cassandra
username: '{env(RB_TEST_BACKEND_USERNAME, cassandra)}'
password: '{env(RB_TEST_BACKEND_PASSWORD, cassandra)}'
defaultConsistency: one # or 'localQuorum' for production
storage_groups:
- name: test.group.local
domains: /./
# ignored in cassandra, but useful in SQLite testing
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}'
host: localhost # ignored in cassandra, but useful in MySQL testing
database: test_db # ignored in cassandra, but useful in MySQL testing
dbname: '{env(RB_SQLITE_FILE, test.db.sqlite3)}' # ignored in cassandra, but useful in SQLite testing

wikimedia_project: &wikimedia_project
x-modules:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tables",
"queues",
"cassandra",
"mysql",
"kafka"
],
"author": "Wikimedia Service Team <services@wikimedia.org>",
Expand All @@ -43,6 +44,7 @@
"jsonwebtoken": "^8.5.1",
"mediawiki-title": "^0.7.2",
"restbase-mod-table-cassandra": "^1.2.1",
"restbase-mod-table-mysql": "^0.1.1",
"semver": "^7.3.2",
"service-runner": "^2.7.8",
"uuid": "^7.0.3"
Expand Down
7 changes: 5 additions & 2 deletions sys/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ module.exports = (options) => {
options.conf.backend = options.conf.backend || 'cassandra';
options.log = options.logger.log.bind(options.logger);

if (options.conf.backend !== 'cassandra' &&
options.conf.backend !== 'sqlite') {
if (
options.conf.backend !== 'cassandra' &&
options.conf.backend !== 'mysql' &&
options.conf.backend !== 'sqlite'
) {
throw new Error(`Unsupported backend version specified: ${options.conf.backend}`);
}

Expand Down
26 changes: 25 additions & 1 deletion test/utils/cleandb.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

rb_test_backend=${RB_TEST_BACKEND:-$2}

dropKeyspaces ( ) {
if [ "$#" -eq 1 ]
then
Expand All @@ -13,4 +15,26 @@ dropKeyspaces ( ) {
fi
}

dropKeyspaces "local_group_test"
dropTables ( ) {
if [ "$#" -eq 1 ]
then
DATABASE=$1
echo "looking for database named '*$DATABASE*'..."
echo 'begin;' | mysql -BD${DATABASE}
for TABLE in `echo 'show tables;' | mysql -BD${DATABASE}`
do
echo dropping table $TABLE
echo "drop table if exists $TABLE;" | mysql -BD${DATABASE}
done
echo 'commit;' | mysql -BD${DATABASE}
fi
}

if [ "$rb_test_backend" = "cassandra" ]; then
dropKeyspaces "local_group_test"
elif [ "$rb_test_backend" = "mysql" ]; then
dropTables "test_db"
else
echo "Invalid TEST_TARGET $rb_test_backend. Must me 'sqlite', 'cassandra' or 'mysql' if specified"
exit 1
fi
17 changes: 16 additions & 1 deletion test/utils/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@ elif [ "$test_target" = "cassandra" ]; then
echo "Cassandra is ready."
fi
export RB_TEST_BACKEND=cassandra
export RB_TEST_BACKEND_USERNAME=cassandra
export RB_TEST_BACKEND_PASSWORD=cassandra
sh ./test/utils/cleandb.sh local_group_test
elif [ "$test_target" = "mysql" ]; then
echo "Running with MySQL backend"
if [ `nc -z localhost 3306 < /dev/null; echo $?` != 0 ]; then
echo "Waiting for MySQL to start..."
while [ `nc -z localhost 3306; echo $?` != 0 ]; do
sleep 1
done
echo "MySQL is ready."
fi
export RB_TEST_BACKEND=mysql
export RB_TEST_BACKEND_USERNAME=mysql
export RB_TEST_BACKEND_PASSWORD=mysql
sh ./test/utils/cleandb.sh local_group_test
else
echo "Invalid TEST_TARGET $test_target. Must me 'sqlite' or 'cassandra' if specified"
echo "Invalid TEST_TARGET $test_target. Must me 'sqlite', 'cassandra' or 'mysql' if specified"
exit 1
fi

Expand Down

0 comments on commit 460ee9a

Please sign in to comment.