sapling/tests/hgsql/library.sh
Thomas Jacob 0e6b93a0e0 Add support for RocksDB
Summary:
- Add support for RocksDB engine (developed as a drop in replacement for innodb) to hgsql to allow new xdb.hgsql.1-10 shards to host hg repos
- Prefer MySQL test DBs in same region
- Run all hgsql unit tests also for RocksDB engine
- Allow for nested ifs to make that possible (downside if you switch off rockdb tests, innodb tests are run twice)

Reviewed By: quark-zju

Differential Revision: D7014064

fbshipit-source-id: 073c36176aa7eaf74252ef33c3f47da594920b28
2018-04-13 21:51:13 -07:00

108 lines
2.4 KiB
Bash

TESTDIR=${TESTDIR:-.}
GETDB_PATH="$TESTDIR/${HGTEST_GETDB_PATH:-getdb.sh}"
if [[ ! -f "$GETDB_PATH" ]]; then
echo "skipped: getdb.sh missing. copy from getdb.sh.example and edit it"
exit 80
fi
if ! ${PYTHON:-python} -c "import mysql.connector" 2>/dev/null; then
echo "skipped: mysql-connector-python missing"
exit 80
fi
source "$GETDB_PATH" >/dev/null
# Convert legacy fields from legacy getdb.sh implementation
if [[ -z $DBHOST && -z $DBPORT && -n $DBHOSTPORT ]]; then
# Assuming they are set using the legacy way: $DBHOSTPORT
DBHOST=`echo $DBHOSTPORT | cut -d : -f 1`
DBPORT=`echo $DBHOSTPORT | cut -d : -f 2`
fi
[[ -z $DBHOST ]] && DBHOST=localhost
[[ -z $DBPORT ]] && DBPORT=3306
[[ -z $DBENGINE ]] && DBENGINE=innodb
[[ -z $DBPASS && -n $PASSWORD ]] && DBPASS="$PASSWORD"
[[ -z $DBUSER && -n $USER ]] && DBUSER="$USER"
[[ -z $DBNAME ]] && DBNAME="testdb_hgsql_$$_$(date +%s)" && DBAUTODROP=1
[[ -n $DBPASS ]] && DBPASSOPT="-p$DBPASS"
MYSQLLOG="${MYSQLLOG:-/dev/null}"
# skip if DBENGINE is not supported
( mysql -h "$DBHOST" -P "$DBPORT" -u "$DBUSER" "$DBPASSOPT" \
--execute='SHOW ENGINES' --silent --skip-column-names | \
egrep -iq "^$DBENGINE[[:space:]](default|yes)[[:space:]]" )
if [[ $? != 0 ]]; then
echo "skipped: $DBENGINE unsupported"
exit 80
fi
mysql -h "$DBHOST" -P "$DBPORT" -u "$DBUSER" "$DBPASSOPT" &>> "$MYSQLLOG" <<EOF
CREATE DATABASE IF NOT EXISTS $DBNAME;
USE $DBNAME;
DROP TABLE IF EXISTS revisions;
DROP TABLE IF EXISTS revision_references;
$(cat $TESTDIR/hgsql/schema.$DBENGINE.sql)
EOF
if [[ $? != 0 ]]; then
echo "skipped: unable to initialize the database. check your getdb.sh"
exit 80
fi
function droptestdb() {
mysql -h "$DBHOST" -P "$DBPORT" -u "$DBUSER" "$DBPASSOPT" &>> "$MYSQLLOG" <<EOF
DROP DATABASE $DBNAME;
EOF
}
[[ $DBAUTODROP == 1 ]] && trap droptestdb EXIT
function initserver() {
hg init --config extensions.hgsql= $1
configureserver $1 $2
}
configureserver() {
cat >> $1/.hg/hgrc <<EOF
[extensions]
hgsql=
strip=
[hgsql]
enabled = True
host = $DBHOST
database = $DBNAME
user = $DBUSER
password = $DBPASS
port = $DBPORT
reponame = $2
engine = $DBENGINE
[server]
preferuncompressed=True
uncompressed=True
[ui]
ssh=python "$TESTDIR/dummyssh"
EOF
}
function initclient() {
hg init $1
configureclient $1
}
configureclient() {
cat >> $1/.hg/hgrc <<EOF
[ui]
ssh=python "$TESTDIR/dummyssh"
[extensions]
hgsql=
strip=
EOF
}