diff --git a/.travis.yml b/.travis.yml index e0cd03f..8353765 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,24 @@ sudo: true -language: python +os: linux dist: bionic - -services: -- docker - +language: c +services: docker addons: hosts: - mariadb.example.com before_install: - - export PROJ_PATH=`pwd` - - chmod +x .travis/script.sh + - git clone https://github.com/mariadb-corporation/connector-test-machine.git + +install: + - export MAIN_PATH=`pwd` + # install pyenv to test multiple python version + - git clone https://github.com/pyenv/pyenv.git ~/.pyenv + - export PYENV_ROOT="$HOME/.pyenv" + - eval "$(pyenv init -)" + - export PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH" + # install c dependency - sudo apt-get install software-properties-common - - sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 - - sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.accretive-networks.net/mariadb/repo/10.4/ubuntu bionic main' - - sudo apt-get remove --purge mysql* - - sudo apt update - sudo apt-get install -f libssl-dev libssl1.1 - sudo apt-get install -f - git clone https://github.com/mariadb-corporation/mariadb-connector-c.git ~/.cc_3.1 @@ -26,54 +28,73 @@ before_install: - cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr - make -j4 - sudo make install - - cd $PROJ_PATH - - git clone https://github.com/pyenv/pyenv.git ~/.pyenv - - export PYENV_ROOT="$HOME/.pyenv" - - export PATH="$PYENV_ROOT/bin:$PATH" - - echo $PATH - - eval "$(pyenv init -)" - -install: - - wget -qO- 'https://github.com/tianon/pgp-happy-eyeballs/raw/master/hack-my-builds.sh' | bash - # generate SSL certificates - - mkdir tmp - - chmod +x .travis/gen-ssl.sh - - chmod +x .travis/build/build.sh - - chmod +x .travis/build/docker-entrypoint.sh - - chmod 777 .travis/build/ - - .travis/gen-ssl.sh mariadb.example.com tmp - - export PROJ_PATH=`pwd` - - export SSLCERT=$PROJ_PATH/tmp - - export TEST_SSL_CA_FILE=$SSLCERT/server.crt - - export TEST_SSL_CLIENT_KEY_FILE=$SSLCERT/client.key - - export TEST_SSL_CLIENT_CERT_FILE=$SSLCERT/client.crt - - export TEST_SSL_CLIENT_KEYSTORE_FILE=$SSLCERT/client-keystore.p12 - export MARIADB_PLUGIN_DIR==`mariadb_config --plugindir` - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/mariadb + # install "install-latest" to retrieve latest python version corresponding to major.minor version + - git clone https://github.com/momo-lab/pyenv-install-latest.git "$(pyenv root)"/plugins/pyenv-install-latest + - export REAL_PYTHON_VERSION=$(pyenv install-latest --print $PYTHON_VER) + - echo $REAL_PYTHON_VERSION + - pyenv install $REAL_PYTHON_VERSION + - export PYENV_VERSION=$REAL_PYTHON_VERSION + - pyenv versions + # install server + - cd $MAIN_PATH + - source connector-test-machine/launch.sh -t "$srv" -v "$v" -d testp -l "$local" env: global: - - TEST_PORT=3305 - - TEST_HOST=mariadb.example.com + - PYTHON_VER="3.10" -matrix: +jobs: + fast_finish: true allow_failures: -# - env: DB=mariadb:10.5 SQLALCHEMY=1 + - env: srv=build v=10.6 include: - - env: SKYSQL=true PYTHON_VER="3.9.0" - - env: DB=mariadb:10.4 PYTHON_VER="3.6.0" - - env: DB=mariadb:10.4 PYTHON_VER="3.9.0" -# - env: DB=mariadb:10.4 PYTHON_VER="pypy3.6-7.3.1" -# - env: DB=mariadb:10.4 BENCH=1 - - env: DB=mariadb:10.6 PYTHON_VER="3.10.0" - - env: DB=mariadb:10.5 PYTHON_VER="3.6.0" - - env: DB=mariadb:10.4 PYTHON_VER="3.6.0" MAXSCALE_VERSION=2.2.9 TEST_PORT=4007 TEST_USER=bob TEXT_DATABASE=test2 SKIP_LEAK=1 - - env: DB=mariadb:10.2 PYTHON_VER="3.6.0" - - env: DB=mariadb:10.3 PYTHON_VER="3.6.0" - - env: DB=mysql:5.7 PYTHON_VER="3.6.0" + - env: srv=mariadb v=10.2 local=1 + - env: srv=mariadb v=10.3 local=1 + - env: srv=mariadb v=10.4 local=1 + - env: srv=mariadb v=10.5 local=1 + - env: srv=mariadb v=10.6 local=1 PYTHON_VER="3.6" + - env: srv=mariadb v=10.6 local=1 PYTHON_VER="3.7" + - env: srv=mariadb v=10.6 local=1 PYTHON_VER="3.8" + - env: srv=mariadb v=10.6 local=1 PYTHON_VER="3.9" + - env: srv=mariadb v=10.6 local=1 PYTHON_VER="3.10" + - env: srv=mariadb v=10.6 local=1 PYTHON_VER="3.10" BENCH=1 + - env: srv=mariadb v=10.7 local=1 + - if: type = push AND fork = false + env: srv=maxscale + - if: type = push AND fork = false + env: srv=mariadb-es v=10.6 + - if: type = push AND fork = false + env: srv=skysql RUN_LONG_TEST=0 + - if: type = push AND fork = false + env: srv=skysql-ha RUN_LONG_TEST=0 + - if: type = push AND fork = false + env: srv=build v=10.6 + - if: type = push AND fork = false + env: srv=mysql v=5.7 + - if: type = push AND fork = false + env: srv=mysql v=8.0 notifications: email: false script: - - .travis/script.sh + - python --version + - python setup.py build + - python setup.py install + - cd testing + - |- + if [ -z "$BENCH" ] ; then + python -m unittest discover -v + else + pip install mysql-connector-python pymysql pyperf + export TEST_MODULE=mariadb + python bench_init.py + python bench.py -o mariadb_bench.json --inherit-environ=TEST_DB_USER,TEST_DB_HOST,TEST_DB_DATABASE,TEST_DB_PORT,TEST_REQUIRE_TLS,TEST_DB_PASSWORD,TEST_MODULE + export TEST_MODULE=mysql.connector + python bench.py -o mysql-connector-python_bench.json --inherit-environ=TEST_DB_USER,TEST_DB_HOST,TEST_DB_DATABASE,TEST_DB_PORT,TEST_REQUIRE_TLS,TEST_DB_PASSWORD,TEST_MODULE + export TEST_MODULE=pymysql + python bench.py -o pymysql_bench.json --inherit-environ=TEST_DB_USER,TEST_DB_HOST,TEST_DB_DATABASE,TEST_DB_PORT,TEST_REQUIRE_TLS,TEST_DB_PASSWORD,TEST_MODULE + python -m pyperf compare_to pymysql_bench.json mysql-connector-python_bench.json mariadb_bench.json --table + fi diff --git a/.travis/build/Dockerfile b/.travis/build/Dockerfile deleted file mode 100644 index d5b0296..0000000 --- a/.travis/build/Dockerfile +++ /dev/null @@ -1,99 +0,0 @@ -# vim:set ft=dockerfile: -FROM ubuntu:bionic - -# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added -RUN groupadd -r mysql && useradd -r -g mysql mysql - -# https://bugs.debian.org/830696 (apt uses gpgv by default in newer releases, rather than gpg) -RUN set -ex; \ - apt-get update; \ - if ! which gpg; then \ - apt-get install -y --no-install-recommends gnupg; \ - fi; \ -# Ubuntu includes "gnupg" (not "gnupg2", but still 2.x), but not dirmngr, and gnupg 2.x requires dirmngr -# so, if we're not running gnupg 1.x, explicitly install dirmngr too - if ! gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \ - apt-get install -y --no-install-recommends dirmngr; \ - fi; \ - rm -rf /var/lib/apt/lists/* - -# add gosu for easy step-down from root -ENV GOSU_VERSION 1.10 -RUN set -ex; \ - \ - fetchDeps=' \ - ca-certificates \ - wget \ - '; \ - apt-get update; \ - apt-get install -y --no-install-recommends $fetchDeps; \ - rm -rf /var/lib/apt/lists/*; \ - \ - dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ - wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \ - wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \ - \ -# verify the signature - export GNUPGHOME="$(mktemp -d)"; \ - gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ - gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ - command -v gpgconf > /dev/null && gpgconf --kill all || :; \ - rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \ - \ - chmod +x /usr/local/bin/gosu; \ -# verify that the binary works - gosu nobody true; \ - \ - apt-get purge -y --auto-remove $fetchDeps - -RUN mkdir /docker-entrypoint-initdb.d - -# install "pwgen" for randomizing passwords -# install "apt-transport-https" for Percona's repo (switched to https-only) -RUN apt-get update && apt-get install -y --no-install-recommends \ - apt-transport-https ca-certificates \ - tzdata \ - pwgen \ - && rm -rf /var/lib/apt/lists/* - -RUN { \ - echo "mariadb-server-10.4" mysql-server/root_password password 'unused'; \ - echo "mariadb-server-10.4" mysql-server/root_password_again password 'unused'; \ - } | debconf-set-selections - -RUN apt-get update -y -RUN apt-get install -y software-properties-common wget -RUN apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db -RUN apt-key adv --recv-keys --keyserver ha.pool.sks-keyservers.net F1656F24C74CD1D8 -RUN echo 'deb http://yum.mariadb.org/galera/repo/deb bionic main' > /etc/apt/sources.list.d/galera-test-repo.list -RUN apt-get update -y - -RUN apt-get install -y curl libdbi-perl rsync socat galera3 libnuma1 libaio1 zlib1g-dev libreadline5 libjemalloc1 libsnappy1v5 libcrack2 - -COPY *.deb /root/ -RUN chmod 777 /root/* - -RUN dpkg --install /root/mysql-common* -RUN dpkg --install /root/mariadb-common* -RUN dpkg -R --unpack /root/ -RUN apt-get install -f -y - -RUN rm -rf /var/lib/apt/lists/* \ - && sed -ri 's/^user\s/#&/' /etc/mysql/my.cnf /etc/mysql/conf.d/* \ - && rm -rf /var/lib/mysql && mkdir -p /var/lib/mysql /var/run/mysqld \ - && chown -R mysql:mysql /var/lib/mysql /var/run/mysqld \ - && chmod 777 /var/run/mysqld \ - && find /etc/mysql/ -name '*.cnf' -print0 \ - | xargs -0 grep -lZE '^(bind-address|log)' \ - | xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/' \ - && echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf - -VOLUME /var/lib/mysql - -COPY docker-entrypoint.sh /usr/local/bin/ -RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat -ENTRYPOINT ["docker-entrypoint.sh"] - -EXPOSE 3306 -CMD ["mysqld"] - diff --git a/.travis/build/build.sh b/.travis/build/build.sh deleted file mode 100644 index 2975752..0000000 --- a/.travis/build/build.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash - -echo "**************************************************************************" -echo "* searching for last complete build" -echo "**************************************************************************" - -wget -q -o /dev/null index.html http://hasky.askmonty.org/archive/10.4/ -grep -o ">build-[0-9]*" index.html | grep -o "[0-9]*" | tac | while read -r line ; do - - curl -s --head http://hasky.askmonty.org/archive/10.4/build-$line/kvm-deb-bionic-amd64/md5sums.txt | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null - if [ $? = "0" ]; then - echo "**************************************************************************" - echo "* Processing $line" - echo "**************************************************************************" - wget -q -o /dev/null -O $line.html http://hasky.askmonty.org/archive/10.4/build-$line/kvm-deb-bionic-amd64/debs/binary/ - grep -o ">[^\"]*\.deb" $line.html | grep -o "[^>]*\.deb" | while read -r file ; do - if [[ "$file" =~ ^mariadb-plugin.* ]] ; - then - echo "skipped file: $file" - else - echo "download file: $file" - wget -q -o /dev/null -O .travis/build/$file http://hasky.askmonty.org/archive/10.4/build-$line/kvm-deb-bionic-amd64/debs/binary/$file - fi - done - - exit - else - echo "skip build $line" - fi -done - - - diff --git a/.travis/build/docker-entrypoint.sh b/.travis/build/docker-entrypoint.sh deleted file mode 100644 index 721cc7d..0000000 --- a/.travis/build/docker-entrypoint.sh +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash -set -eo pipefail -shopt -s nullglob - -# if command starts with an option, prepend mysqld -if [ "${1:0:1}" = '-' ]; then - set -- mysqld "$@" -fi - -# skip setup if they want an option that stops mysqld -wantHelp= -for arg; do - case "$arg" in - -'?'|--help|--print-defaults|-V|--version) - wantHelp=1 - break - ;; - esac -done - -# usage: file_env VAR [DEFAULT] -# ie: file_env 'XYZ_DB_PASSWORD' 'example' -# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of -# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) -file_env() { - local var="$1" - local fileVar="${var}_FILE" - local def="${2:-}" - if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then - echo >&2 "error: both $var and $fileVar are set (but are exclusive)" - exit 1 - fi - local val="$def" - if [ "${!var:-}" ]; then - val="${!var}" - elif [ "${!fileVar:-}" ]; then - val="$(< "${!fileVar}")" - fi - export "$var"="$val" - unset "$fileVar" -} - -_check_config() { - toRun=( "$@" --verbose --help --log-bin-index="$(mktemp -u)" ) - if ! errors="$("${toRun[@]}" 2>&1 >/dev/null)"; then - cat >&2 <<-EOM - ERROR: mysqld failed while attempting to check config - command was: "${toRun[*]}" - $errors - EOM - exit 1 - fi -} - -# Fetch value from server config -# We use mysqld --verbose --help instead of my_print_defaults because the -# latter only show values present in config files, and not server defaults -_get_config() { - local conf="$1"; shift - "$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null \ - | awk '$1 == "'"$conf"'" && /^[^ \t]/ { sub(/^[^ \t]+[ \t]+/, ""); print; exit }' - # match "datadir /some/path with/spaces in/it here" but not "--xyz=abc\n datadir (xyz)" -} - -# allow the container to be started with `--user` -if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then - _check_config "$@" - DATADIR="$(_get_config 'datadir' "$@")" - mkdir -p "$DATADIR" - find "$DATADIR" \! -user mysql -exec chown mysql '{}' + - exec gosu mysql "$BASH_SOURCE" "$@" -fi - -if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then - # still need to check config, container may have started with --user - _check_config "$@" - # Get config - DATADIR="$(_get_config 'datadir' "$@")" - - if [ ! -d "$DATADIR/mysql" ]; then - file_env 'MYSQL_ROOT_PASSWORD' - if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then - echo >&2 'error: database is uninitialized and password option is not specified ' - echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD' - exit 1 - fi - - mkdir -p "$DATADIR" - - echo 'Initializing database' - installArgs=( --datadir="$DATADIR" --rpm ) - if { mysql_install_db --help || :; } | grep -q -- '--auth-root-authentication-method'; then - # beginning in 10.4.3, install_db uses "socket" which only allows system user root to connect, switch back to "normal" to allow mysql root without a password - # see https://github.com/MariaDB/server/commit/b9f3f06857ac6f9105dc65caae19782f09b47fb3 - # (this flag doesn't exist in 10.0 and below) - installArgs+=( --auth-root-authentication-method=normal ) - fi - # "Other options are passed to mysqld." (so we pass all "mysqld" arguments directly here) - mysql_install_db "${installArgs[@]}" "${@:2}" - echo 'Database initialized' - - SOCKET="$(_get_config 'socket' "$@")" - "$@" --skip-networking --socket="${SOCKET}" & - pid="$!" - - mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" ) - - for i in {30..0}; do - if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then - break - fi - echo 'MySQL init process in progress...' - sleep 1 - done - if [ "$i" = 0 ]; then - echo >&2 'MySQL init process failed.' - exit 1 - fi - - if [ -z "$MYSQL_INITDB_SKIP_TZINFO" ]; then - # sed is for https://bugs.mysql.com/bug.php?id=20545 - mysql_tzinfo_to_sql /usr/share/zoneinfo | sed 's/Local time zone must be set--see zic manual page/FCTY/' | "${mysql[@]}" mysql - fi - - if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then - export MYSQL_ROOT_PASSWORD="$(pwgen -1 32)" - echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD" - fi - - rootCreate= - # default root to listen for connections from anywhere - file_env 'MYSQL_ROOT_HOST' '%' - if [ ! -z "$MYSQL_ROOT_HOST" -a "$MYSQL_ROOT_HOST" != 'localhost' ]; then - # no, we don't care if read finds a terminating character in this heredoc - # https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151 - read -r -d '' rootCreate <<-EOSQL || true - CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ; - GRANT ALL ON *.* TO 'root'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ; - EOSQL - fi - - "${mysql[@]}" <<-EOSQL - -- What's done in this file shouldn't be replicated - -- or products like mysql-fabric won't work - SET @@SESSION.SQL_LOG_BIN=0; - DELETE FROM mysql.user WHERE user NOT IN ('mysql.sys', 'mysqlxsys', 'root') OR host NOT IN ('localhost') ; - SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASSWORD}') ; - GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ; - ${rootCreate} - DROP DATABASE IF EXISTS test ; - FLUSH PRIVILEGES ; - EOSQL - - if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then - mysql+=( -p"${MYSQL_ROOT_PASSWORD}" ) - fi - - file_env 'MYSQL_DATABASE' - if [ "$MYSQL_DATABASE" ]; then - echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" | "${mysql[@]}" - mysql+=( "$MYSQL_DATABASE" ) - fi - - file_env 'MYSQL_USER' - file_env 'MYSQL_PASSWORD' - if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then - echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}" - - if [ "$MYSQL_DATABASE" ]; then - echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}" - fi - fi - - echo - for f in /docker-entrypoint-initdb.d/*; do - case "$f" in - *.sh) echo "$0: running $f"; . "$f" ;; - *.sql) echo "$0: running $f"; "${mysql[@]}" < "$f"; echo ;; - *.sql.gz) echo "$0: running $f"; gunzip -c "$f" | "${mysql[@]}"; echo ;; - *) echo "$0: ignoring $f" ;; - esac - echo - done - - if ! kill -s TERM "$pid" || ! wait "$pid"; then - echo >&2 'MySQL init process failed.' - exit 1 - fi - - echo - echo 'MySQL init process done. Ready for start up.' - echo - fi -fi - -exec "$@" \ No newline at end of file diff --git a/.travis/docker-compose.yml b/.travis/docker-compose.yml deleted file mode 100644 index 0792a73..0000000 --- a/.travis/docker-compose.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: '2' -services: - db: - image: $DB - command: --innodb-log-file-size=400m --max-allowed-packet=40m --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key --bind-address=0.0.0.0 $ADDITIONAL_CONF - ports: - - 3305:3306 - volumes: - - $SSLCERT:/etc/sslcert - - $ENTRYPOINT:/pam - environment: - MYSQL_DATABASE: testp - MYSQL_ALLOW_EMPTY_PASSWORD: 1 - MYSQL_ROOT_PASSWORD: - - - diff --git a/.travis/entrypoint/dbinit.sql b/.travis/entrypoint/dbinit.sql deleted file mode 100644 index 665bca2..0000000 --- a/.travis/entrypoint/dbinit.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE USER 'bob'@'%'; -GRANT ALL ON *.* TO 'bob'@'%' with grant option; - -CREATE USER 'boby'@'%' identified by 'heyPassw0@rd'; -GRANT ALL ON *.* TO 'boby'@'%' with grant option; - -INSTALL PLUGIN pam SONAME 'auth_pam'; - -FLUSH PRIVILEGES; - -CREATE DATABASE test2; \ No newline at end of file diff --git a/.travis/entrypoint/pam.sh b/.travis/entrypoint/pam.sh deleted file mode 100644 index 4a879a0..0000000 --- a/.travis/entrypoint/pam.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -tee /etc/pam.d/mariadb << EOF -auth required pam_unix.so audit -auth required pam_unix.so audit -account required pam_unix.so audit -EOF - -useradd testPam -chpasswd << EOF -testPam:myPwd -EOF - -usermod -a -G shadow mysql - -echo "pam configuration done" \ No newline at end of file diff --git a/.travis/gen-ssl.sh b/.travis/gen-ssl.sh deleted file mode 100644 index 01c8fce..0000000 --- a/.travis/gen-ssl.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash -set -e - -log () { - echo "$@" 1>&2 -} - -print_error () { - echo "$@" 1>&2 - exit 1 -} - -print_usage () { - print_error "Usage: gen-ssl-cert-key " -} - -gen_cert_subject () { - local fqdn="$1" - [[ "${fqdn}" != "" ]] || print_error "FQDN cannot be blank" - echo "/C=XX/ST=X/O=X/localityName=X/CN=${fqdn}/organizationalUnitName=X/emailAddress=X/" -} - -main () { - local fqdn="$1" - local sslDir="$2" - [[ "${fqdn}" != "" ]] || print_usage - [[ -d "${sslDir}" ]] || print_error "Directory does not exist: ${sslDir}" - - local caCertFile="${sslDir}/ca.crt" - local caKeyFile="${sslDir}/ca.key" - local certFile="${sslDir}/server.crt" - local keyFile="${sslDir}/server.key" - local csrFile="${sslDir}/csrFile.key" - local clientCertFile="${sslDir}/client.crt" - local clientKeyFile="${sslDir}/client.key" - local clientKeystoreFile="${sslDir}/client-keystore.p12" - local pcks12FullKeystoreFile="${sslDir}/fullclient-keystore.p12" - local clientReqFile="${sslDir}/clientReqFile.key" - - log "Generating CA key" - openssl genrsa -out "${caKeyFile}" 2048 - - log "Generating CA certificate" - openssl req \ - -sha1 \ - -new \ - -x509 \ - -nodes \ - -days 3650 \ - -subj "$(gen_cert_subject ca.example.com)" \ - -key "${caKeyFile}" \ - -out "${caCertFile}" - - log "Generating private key" - openssl genrsa -out "${keyFile}" 2048 - - log "Generating certificate signing request" - openssl req \ - -new \ - -batch \ - -sha1 \ - -subj "$(gen_cert_subject "$fqdn")" \ - -set_serial 01 \ - -key "${keyFile}" \ - -out "${csrFile}" \ - -nodes - - log "Generating X509 certificate" - openssl x509 \ - -req \ - -sha1 \ - -set_serial 01 \ - -CA "${caCertFile}" \ - -CAkey "${caKeyFile}" \ - -days 3650 \ - -in "${csrFile}" \ - -signkey "${keyFile}" \ - -out "${certFile}" - - log "Generating client certificate" - openssl req \ - -batch \ - -newkey rsa:2048 \ - -days 3600 \ - -subj "$(gen_cert_subject "$fqdn")" \ - -nodes \ - -keyout "${clientKeyFile}" \ - -out "${clientReqFile}" - - openssl x509 \ - -req \ - -in "${clientReqFile}" \ - -days 3600 \ - -CA "${caCertFile}" \ - -CAkey "${caKeyFile}" \ - -set_serial 01 \ - -out "${clientCertFile}" - - # Now generate a keystore with the client cert & key - log "Generating client keystore" - openssl pkcs12 \ - -export \ - -in "${clientCertFile}" \ - -inkey "${clientKeyFile}" \ - -out "${clientKeystoreFile}" \ - -name "mysqlAlias" \ - -passout pass:kspass - - # Now generate a full keystore with the client cert & key + trust certificates - log "Generating full client keystore" - openssl pkcs12 \ - -export \ - -in "${clientCertFile}" \ - -inkey "${clientKeyFile}" \ - -out "${pcks12FullKeystoreFile}" \ - -name "mysqlAlias" \ - -passout pass:kspass - - # Clean up CSR file: - rm "$csrFile" - rm "$clientReqFile" - - log "Generated key file and certificate in: ${sslDir}" - ls -l "${sslDir}" -} - -main "$@" - diff --git a/.travis/maxscale-compose.yml b/.travis/maxscale-compose.yml deleted file mode 100644 index b5b5095..0000000 --- a/.travis/maxscale-compose.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: '2.1' -services: - maxscale: - depends_on: - - db - ports: - - 4006:4006 - - 4007:4007 - - 4008:4008 - build: - context: . - dockerfile: maxscale/Dockerfile - args: - MAXSCALE_VERSION: $MAXSCALE_VERSION - db: - image: $DB - command: --max-connections=500 --max-allowed-packet=40m --innodb-log-file-size=400m --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --ssl-ca=/etc/sslcert/ca.crt --ssl-cert=/etc/sslcert/server.crt --ssl-key=/etc/sslcert/server.key --bind-address=0.0.0.0 - ports: - - 3305:3306 - volumes: - - $SSLCERT:/etc/sslcert - - $ENTRYPOINT:/docker-entrypoint-initdb.d - environment: - MYSQL_DATABASE: testp - MYSQL_ALLOW_EMPTY_PASSWORD: 1 diff --git a/.travis/maxscale/Dockerfile b/.travis/maxscale/Dockerfile deleted file mode 100644 index 61e4181..0000000 --- a/.travis/maxscale/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -FROM centos:7 - -ARG MAXSCALE_VERSION -ENV MAXSCALE_VERSION ${MAXSCALE_VERSION:-2.2.9} - -COPY maxscale/mariadb.repo /etc/yum.repos.d/ - -RUN rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB \ - && yum -y install https://downloads.mariadb.com/MaxScale/${MAXSCALE_VERSION}/centos/7/x86_64/maxscale-${MAXSCALE_VERSION}-1.centos.7.x86_64.rpm \ - && yum -y update - -RUN yum -y install maxscale-${MAXSCALE_VERSION} MariaDB-client \ - && yum clean all \ - && rm -rf /tmp/* - -COPY maxscale/docker-entrypoint.sh / -RUN chmod 777 /etc/maxscale.cnf -COPY maxscale/maxscale.cnf /etc/ -RUN chmod 777 /docker-entrypoint.sh - - -EXPOSE 4006 4007 4008 - -ENTRYPOINT ["/docker-entrypoint.sh"] \ No newline at end of file diff --git a/.travis/maxscale/docker-entrypoint.sh b/.travis/maxscale/docker-entrypoint.sh deleted file mode 100644 index 1f2d02c..0000000 --- a/.travis/maxscale/docker-entrypoint.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo 'creating configuration done' - -sleep 15 - -################################################################################################# -# wait for db availability for 60s -################################################################################################# -mysql=( mysql --protocol=tcp -ubob -hdb --port=3306 ) -for i in {60..0}; do - if echo 'use test2' | "${mysql[@]}" &> /dev/null; then - break - fi - echo 'DB init process in progress...' - sleep 1 -done - -echo 'use test2' | "${mysql[@]}" -if [ "$i" = 0 ]; then - echo 'DB init process failed.' - exit 1 -fi - -echo 'maxscale launching ...' - -tail -n 500 /etc/maxscale.cnf - -/usr/bin/maxscale --user=root --nodaemon - -cd /var/log/maxscale -ls -lrt -tail -n 500 /var/log/maxscale/maxscale.log diff --git a/.travis/maxscale/mariadb.repo b/.travis/maxscale/mariadb.repo deleted file mode 100644 index d15c559..0000000 --- a/.travis/maxscale/mariadb.repo +++ /dev/null @@ -1,7 +0,0 @@ -# MariaDB 10.3 CentOS repository list - created 2018-11-09 14:50 UTC -# http://downloads.mariadb.org/mariadb/repositories/ -[mariadb] -name = MariaDB -baseurl = http://yum.mariadb.org/10.3/centos7-amd64 -gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB -gpgcheck=1 \ No newline at end of file diff --git a/.travis/maxscale/maxscale.cnf b/.travis/maxscale/maxscale.cnf deleted file mode 100644 index 59788bd..0000000 --- a/.travis/maxscale/maxscale.cnf +++ /dev/null @@ -1,125 +0,0 @@ -# MaxScale documentation on GitHub: -# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Documentation-Contents.md - -# Global parameters -# -# Complete list of configuration options: -# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Getting-Started/Configuration-Guide.md - - -[maxscale] -threads=2 -log_messages=1 -log_trace=1 -log_debug=1 - -# Server definitions -# -# Set the address of the server to the network -# address of a MySQL server. -# - -[server1] -type=server -address=db -port=3306 -protocol=MariaDBBackend -authenticator_options=skip_authentication=true -router_options=master - -# Monitor for the servers -# -# This will keep MaxScale aware of the state of the servers. -# MySQL Monitor documentation: -# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Monitors/MySQL-Monitor.md - -[MySQLMonitor] -type=monitor -module=mariadbmon -servers=server1 -user=boby -passwd=heyPassw0@rd -monitor_interval=10000 - -# Service definitions -# -# Service Definition for a read-only service and -# a read/write splitting service. -# - -# ReadConnRoute documentation: -# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadConnRoute.md - -[Read-OnlyService] -enable_root_user=1 -version_string=10.4.99-MariaDB-maxScale -type=service -router=readconnroute -servers=server1 -user=boby -passwd=heyPassw0@rd -router_options=slave -localhost_match_wildcard_host=1 - -[Read-WriteService] -enable_root_user=1 -version_string=10.4.99-MariaDB-maxScale -type=service -router=readwritesplit -servers=server1 -user=boby -passwd=heyPassw0@rd -localhost_match_wildcard_host=1 - -[WriteService] -type=service -router=readconnroute -servers=server1 -user=boby -passwd=heyPassw0@rd -router_options=master -localhost_match_wildcard_host=1 -version_string=10.4.99-MariaDB-maxScale - - -# This service enables the use of the MaxAdmin interface -# MaxScale administration guide: -# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Reference/MaxAdmin.mda - -[MaxAdminService] -enable_root_user=1 -version_string=10.4.99-MariaDB-maxScale -type=service -router=cli - -# Listener definitions for the services -# -# These listeners represent the ports the -# services will listen on. -# -[WriteListener] -type=listener -service=WriteService -protocol=MariaDBClient -port=4007 -#socket=/var/lib/maxscale/writeconn.sock - -[Read-OnlyListener] -type=listener -service=Read-OnlyService -protocol=MariaDBClient -port=4008 -#socket=/var/lib/maxscale/readconn.sock - -[Read-WriteListener] -type=listener -service=Read-WriteService -protocol=MariaDBClient -port=4006 -#socket=/var/lib/maxscale/rwsplit.sock - -[MaxAdminListener] -type=listener -service=MaxAdminService -protocol=maxscaled -socket=/tmp/maxadmin.sock diff --git a/.travis/script.sh b/.travis/script.sh deleted file mode 100644 index 1bf542b..0000000 --- a/.travis/script.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/bin/bash - -set -x -set -e - -################################################################################################################### -# test different type of configuration -################################################################################################################### -mysql=( mysql --protocol=tcp -ubob -h127.0.0.1 --port=3305 ) -if [ -n "$SKYSQL" ] ; then - - if [ -z "$SKYSQL_TEST_HOST" ] ; then - echo "No SkySQL configuration found !" - exit 1 - fi - - export TEST_USER=$SKYSQL_TEST_USER - export TEST_HOST=$SKYSQL_TEST_HOST - export TEST_PASSWORD=$SKYSQL_TEST_PASSWORD - export TEST_PORT=$SKYSQL_TEST_PORT - export TEST_DATABASE=$SKYSQL_TEST_DATABASE -else - if [ "$DB" = "build" ] ; then - .travis/build/build.sh - docker build -t build:latest --label build .travis/build/ - fi - - - export ENTRYPOINT=$PROJ_PATH/.travis/entrypoint - - if [ -n "$MAXSCALE_VERSION" ] ; then - ################################################################################################################### - # launch Maxscale with one server - ################################################################################################################### - export COMPOSE_FILE=.travis/maxscale-compose.yml - export ENTRYPOINT=$PROJ_PATH/.travis/sql - docker-compose -f ${COMPOSE_FILE} build - docker-compose -f ${COMPOSE_FILE} up -d - mysql=( mysql --protocol=tcp -ubob -h127.0.0.1 --port=4007 ) - else - docker-compose -f .travis/docker-compose.yml up -d - fi - - for i in {60..0}; do - if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then - break - fi - echo 'data server still not active' - sleep 1 - done - - if [ -z "$MAXSCALE_VERSION" ] ; then - docker-compose -f .travis/docker-compose.yml exec -u root db bash /pam/pam.sh - sleep 1 - docker-compose -f .travis/docker-compose.yml stop db - sleep 1 - docker-compose -f .travis/docker-compose.yml up -d - docker-compose -f .travis/docker-compose.yml logs db - - for i in {60..0}; do - if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then - break - fi - echo 'data server still not active' - sleep 1 - done - fi -fi - -#if [ -n "$SQLALCHEMY"] ; then -# pyenv install 3.9.0 -# export PYENV_VERSION=3.9.0 -# python setup.py build -# python setup.py install -# git clone https://github.com/sqlalchemy/sqlalchemy.git sqlalchemy -# cd sqlalchemy -# pytest --dburi "mariadb+mariadbconnector://sqlalchemy:root@localhost/test?charset=utf8mb4" -# cd .. -#fi - -if [ -n "$BENCH" ] ; then -# pyenv install pypy3.6-7.2.0 -# pyenv install miniconda3-4.3.30 - pyenv install 3.8.0 - - - export PYENV_VERSION=3.8.0 - python setup.py build - python setup.py install - pip install mysql-connector-python pyperf - export TEST_MODULE=mariadb - cd testing - python bench_init.py - python bench.py -o mariadb_bench.json --inherit-environ=TEST_USER,TEST_HOST,TEST_PORT,TEST_MODULE - export TEST_MODULE=mysql.connector - python bench.py -o mysql_bench.json --inherit-environ=TEST_USER,TEST_HOST,TEST_PORT,TEST_MODULE - - python -m pyperf compare_to mysql_bench.json mariadb_bench.json --table - cd .. - -# export PYENV_VERSION=miniconda3-4.3.30 -# python setup.py build -# python setup.py install -# pip install mysql-connector-python pyperf -# python bench_mariadb.py -o mariadb_bench_miniconda3_4_3_30.json --inherit-environ=TEST_USER,TEST_HOST,TEST_PORT -# python bench_mysql.py -o mysql_bench_miniconda3_4_3_30.json --inherit-environ=TEST_USER,TEST_HOST,TEST_PORT - -# python -m pyperf compare_to mysql_bench_miniconda3_4_3_30.json mariadb_bench_miniconda3_4_3_30.json --table - -# export PYENV_VERSION=pypy2.6-7.2.0 -# python setup.py build -# python setup.py install -# pip install mysql-connector-python pyperf -# cd testing -# export TEST_MODULE=mariadb -# python bench.py -o mariadb_bench_pypy3_6.json --inherit-environ=TEST_USER,TEST_HOST,TEST_PORT -# export TEST_MODULE=mysql.connector -# python bench.py -o mysql_bench_pypy3_6.json --inherit-environ=TEST_USER,TEST_HOST,TEST_PORT -# python -m pyperf compare_to mysql_bench_pypy3_6.json mariadb_bench_pypy3_6.json --table -# cd .. - -# python -m pyperf compare_to mysql_bench.json mariadb_bench.json mysql_bench_pypy3_6.json mariadb_bench_pypy3_6.json \ -# mysql_bench_miniconda3_4_3_30.json mariadb_bench_miniconda3_4_3_30.json --table -else - pyenv install $PYTHON_VER - export PYENV_VERSION=$PYTHON_VER - - python setup.py build - python setup.py install - cd testing - - python -m unittest discover -v - cd .. -fi - - diff --git a/.travis/sql/dbinit.sql b/.travis/sql/dbinit.sql deleted file mode 100644 index 8108417..0000000 --- a/.travis/sql/dbinit.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE USER 'bob'@'%'; -GRANT ALL ON *.* TO 'bob'@'%' with grant option; - -CREATE USER 'boby'@'%' identified by 'heyPassw0@rd'; -GRANT ALL ON *.* TO 'boby'@'%' with grant option; - -FLUSH PRIVILEGES; - -CREATE DATABASE test2; \ No newline at end of file diff --git a/testing/bench.py b/testing/bench.py index 3cf7a58..3eca7dd 100644 --- a/testing/bench.py +++ b/testing/bench.py @@ -3,22 +3,22 @@ # requirement: pip install pyperf -import importlib +import importlib from benchmarks.internal_bench import test_suite from benchmarks.internal_bench import run_test -from test.conf_test import conf, glob +from test.conf_test import conf, glob -module= glob(); +module = glob() dbdrv = importlib.import_module(module["module"]) def main(): default_conf = conf() conn = dbdrv.connect(**default_conf) - run_test(test_suite(), conn) + run_test(test_suite(dbdrv.paramstyle), conn, dbdrv.paramstyle) conn.close() if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/testing/bench_init.py b/testing/bench_init.py index 7623f01..959e8d5 100644 --- a/testing/bench_init.py +++ b/testing/bench_init.py @@ -8,13 +8,14 @@ from test.conf_test import conf, glob from benchmarks.setup_db import init_db, end_db -module= glob(); +module = glob() dbdrv = importlib.import_module(module["module"]) + def main(): default_conf = conf() conn = dbdrv.connect(**default_conf) - init_db(conn) + init_db(conn, dbdrv.paramstyle) conn.close() if __name__ == "__main__": diff --git a/testing/bench_mariadb.py b/testing/bench_mariadb.py deleted file mode 100644 index 878350c..0000000 --- a/testing/bench_mariadb.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -O -# -*- coding: utf-8 -*- - -# requirement: pip install pyperf - -import importlib - -from benchmarks.internal_bench import test_suite -from benchmarks.internal_bench import run_test -from test.conf_test import conf - -import os - -module= os.environ.get('TEST_MODULE', 'mariadb'), -dbdrv = importlib.import_module(module[0]) - - -def main(): - default_conf = conf() - conn = dbdrv.connect(**default_conf) - run_test(test_suite(), conn) - conn.close() - -if __name__ == "__main__": - main() diff --git a/testing/bench_mysql.py b/testing/bench_mysql.py deleted file mode 100644 index df25bd2..0000000 --- a/testing/bench_mysql.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -O -# -*- coding: utf-8 -*- - -# requirement: pip install MySQL-pythonmysql-connector-python pyperf - -import mysql.connector - -from benchmarks.internal_bench import test_suite -from benchmarks.internal_bench import run_test -from test.conf_test import conf - - -def main(): - default_conf = conf() - conn = mysql.connector.connect(**default_conf) - run_test(test_suite(), conn) - conn.close() - -if __name__ == "__main__": - main() diff --git a/testing/benchmarks/benchmark/bulk.py b/testing/benchmarks/benchmark/bulk.py index 9e1bf33..5d5487a 100644 --- a/testing/benchmarks/benchmark/bulk.py +++ b/testing/benchmarks/benchmark/bulk.py @@ -4,7 +4,7 @@ import pyperf -def bulk(loops, conn): +def bulk(loops, conn, paramstyle): cursor = conn.cursor() cursor.execute("CREATE TEMPORARY TABLE test_update_bulk (a int primary key, b int)") # conn.autocommit= False @@ -12,11 +12,18 @@ def bulk(loops, conn): vals = [(i,) for i in range(10000)] range_it = range(loops) for value in range_it: - cursor.executemany("INSERT INTO test_update_bulk VALUES (%s, NULL)", vals); - conn.commit() - cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=%s", vals); - conn.commit() - cursor.executemany("DELETE FROM test_update_bulk WHERE a=%s", vals); + if paramstyle == 'qmark': + cursor.executemany("INSERT INTO test_update_bulk VALUES (?, NULL)", vals) + conn.commit() + cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=?", vals) + conn.commit() + cursor.executemany("DELETE FROM test_update_bulk WHERE a=?", vals) + else: + cursor.executemany("INSERT INTO test_update_bulk VALUES (%s, NULL)", vals) + conn.commit() + cursor.executemany("UPDATE test_update_bulk SET b=2 WHERE a=%s", vals) + conn.commit() + cursor.executemany("DELETE FROM test_update_bulk WHERE a=%s", vals) conn.commit() cursor.execute("DROP TABLE IF EXISTS test_update_bulk") del cursor diff --git a/testing/benchmarks/benchmark/do_1.py b/testing/benchmarks/benchmark/do_1.py index 6f7e766..95eaab9 100644 --- a/testing/benchmarks/benchmark/do_1.py +++ b/testing/benchmarks/benchmark/do_1.py @@ -4,7 +4,7 @@ import pyperf -def do1(loops, conn): +def do1(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) diff --git a/testing/benchmarks/benchmark/fetch.py b/testing/benchmarks/benchmark/fetch.py index 6726d83..39692a8 100644 --- a/testing/benchmarks/benchmark/fetch.py +++ b/testing/benchmarks/benchmark/fetch.py @@ -3,7 +3,7 @@ import pyperf -def str_fetchall(loops, conn): +def str_fetchall(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() @@ -14,7 +14,7 @@ def str_fetchall(loops, conn): del cursor return pyperf.perf_counter() - t0 -def str_fetchloop(loops, conn): +def str_fetchloop(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() @@ -26,7 +26,7 @@ def str_fetchloop(loops, conn): del cursor return pyperf.perf_counter() - t0 -def num_fetchall(loops, conn): +def num_fetchall(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() @@ -37,7 +37,7 @@ def num_fetchall(loops, conn): del cursor return pyperf.perf_counter() - t0 -def num_fetchloop(loops, conn): +def num_fetchloop(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() diff --git a/testing/benchmarks/benchmark/select_1.py b/testing/benchmarks/benchmark/select_1.py index 90bfe5b..ef48d71 100644 --- a/testing/benchmarks/benchmark/select_1.py +++ b/testing/benchmarks/benchmark/select_1.py @@ -4,7 +4,7 @@ import pyperf -def select_1(loops, conn): +def select_1(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() diff --git a/testing/benchmarks/benchmark/select_10_cols_from_seq_1_to_10000.py b/testing/benchmarks/benchmark/select_10_cols_from_seq_1_to_10000.py index c142988..1bcaa44 100644 --- a/testing/benchmarks/benchmark/select_10_cols_from_seq_1_to_10000.py +++ b/testing/benchmarks/benchmark/select_10_cols_from_seq_1_to_10000.py @@ -14,7 +14,7 @@ request += " from seq_1_to_10000" -def select_10_cols_from_seq_1_to_10000(loops, conn): +def select_10_cols_from_seq_1_to_10000(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() diff --git a/testing/benchmarks/benchmark/select_1_mysql_user.py b/testing/benchmarks/benchmark/select_1_mysql_user.py index 5bdd430..eb12597 100644 --- a/testing/benchmarks/benchmark/select_1_mysql_user.py +++ b/testing/benchmarks/benchmark/select_1_mysql_user.py @@ -4,7 +4,7 @@ import pyperf -def select_1_mysql_user(loops, conn): +def select_1_mysql_user(loops, conn, paramstyle): range_it = range(loops) t0 = pyperf.perf_counter() cursor = conn.cursor() diff --git a/testing/benchmarks/benchmark/select_param.py b/testing/benchmarks/benchmark/select_param.py index 235a39b..597489e 100644 --- a/testing/benchmarks/benchmark/select_param.py +++ b/testing/benchmarks/benchmark/select_param.py @@ -4,12 +4,15 @@ import pyperf -def select_param(loops, conn): +def select_param(loops, conn, paramstyle): cursor = conn.cursor() range_it = range(loops) t0 = pyperf.perf_counter() for value in range_it: - cursor.execute("select %(val)s", {'val': 1}) + if paramstyle == 'qmark': + cursor.execute("select ?", (1,)) + else: + cursor.execute("select %(val)s", {'val': 1}) row = cursor.fetchall() cursor.close() return pyperf.perf_counter() - t0 \ No newline at end of file diff --git a/testing/benchmarks/internal_bench.py b/testing/benchmarks/internal_bench.py index 9c8b4f8..97cf69b 100644 --- a/testing/benchmarks/internal_bench.py +++ b/testing/benchmarks/internal_bench.py @@ -3,31 +3,31 @@ import pyperf, os + from benchmarks.benchmark.do_1 import do1 from benchmarks.benchmark.fetch import * from benchmarks.benchmark.select_1 import select_1 from benchmarks.benchmark.select_param import select_param -from benchmarks.benchmark.select_10_cols_from_seq_1_to_10000 import \ - select_10_cols_from_seq_1_to_10000 +from benchmarks.benchmark.select_10_cols_from_seq_1_to_10000 import select_10_cols_from_seq_1_to_10000 from benchmarks.benchmark.select_1_mysql_user import select_1_mysql_user from benchmarks.benchmark.bulk import bulk -def run_test(tests, conn): + +def run_test(tests, conn, paramstyle): runner = pyperf.Runner() for test in tests: - runner.bench_time_func(test['label'], test['method'], conn) - + runner.bench_time_func(test['label'], test['method'], conn, paramstyle) -def test_suite(): +def test_suite(paramstyle): is_mysql= int(os.environ.get('TEST_MYSQL', '1')) ts= [ - {'label': 'str_fetchloop', 'method': str_fetchloop}, - {'label': 'str_fetchall', 'method': str_fetchall}, - {'label': 'num_fetchloop', 'method': num_fetchloop}, - {'label': 'num_fetchall', 'method': num_fetchall}, + {'label': '100 rows * 3 col utf8 string using fetchone', 'method': str_fetchloop}, + {'label': '100 rows * 3 col utf8 string using fetchall', 'method': str_fetchall}, + {'label': '1000 rows * 5 numeric col using fetchone', 'method': num_fetchloop}, + {'label': '1000 rows * 5 numeric col using fetchall', 'method': num_fetchall}, {'label': 'select 1', 'method': select_1}, - {'label': 'select param', 'method': select_param}, + {'label': 'select ? - param 1', 'method': select_param}, {'label': 'bulk: insert/update/delete', 'method': bulk}, ] if is_mysql == 1: @@ -35,4 +35,4 @@ def test_suite(): ts.append({'label': 'do 1', 'method': do1}) ts.append({'label': 'Select <10 cols of 100 chars> from_seq_1_to_100000', 'method': select_10_cols_from_seq_1_to_10000}) - return ts + return ts \ No newline at end of file diff --git a/testing/benchmarks/setup_db.py b/testing/benchmarks/setup_db.py index 1d1dddb..1d2801c 100644 --- a/testing/benchmarks/setup_db.py +++ b/testing/benchmarks/setup_db.py @@ -1,18 +1,29 @@ -def init_db(conn): +def init_db(conn, paramstyle): + my_string = "abcdefghi🌟" + str1 = "".join([my_string]*10) + str2 = "".join([my_string]*24) + str3 = "".join([my_string]*1024) cursor=conn.cursor() cursor.execute("DROP TABLE IF EXISTS str_test") cursor.execute("CREATE TABLE str_test (col1 varchar(200), col2 TEXT, col3 TEXT)") - vals = [('A' * 200, 'A' * 254, 'A' * 0xFFF) for i in range(100)] - cursor.executemany("INSERT INTO str_test VALUES (%s, %s, %s)", vals) + vals = [(str1, str2, str3) for i in range(100)] + if paramstyle == 'qmark': + cursor.executemany("INSERT INTO str_test VALUES (?, ?, ?)", vals) + else: + cursor.executemany("INSERT INTO str_test VALUES (%s, %s, %s)", vals) + del cursor - + cursor=conn.cursor() cursor.execute("DROP TABLE IF EXISTS num_test") cursor.execute("CREATE TABLE num_test(col1 smallint, col2 int, col3 smallint, col4 bigint, col5 float, col6 decimal(10,5) )") vals = [(i % 128,0xFF+i,0xFFF+i, 0xFFFF+i, 10000+i+0.3123, 20000+i+0.1234) for i in range(1000)] - cursor.executemany("INSERT INTO num_test VALUES (%s,%s,%s,%s,%s,%s)", vals) + if paramstyle == 'qmark': + cursor.executemany("INSERT INTO num_test VALUES (?,?,?,?,?,?)", vals) + else: + cursor.executemany("INSERT INTO num_test VALUES (%s,%s,%s,%s,%s,%s)", vals) conn.commit() del cursor diff --git a/testing/test/base_test.py b/testing/test/base_test.py index 182cce9..5520c20 100644 --- a/testing/test/base_test.py +++ b/testing/test/base_test.py @@ -1,14 +1,31 @@ #!/usr/bin/env python -O # -*- coding: utf-8 -*- +import os import mariadb from .conf_test import conf + def is_skysql(): - if conf()["host"][-13:] == "db.skysql.net": - return True - return False + if conf()["host"][-13:] == "db.skysql.net": + return True + return False + + +def is_maxscale(): + return os.environ.get('srv') == "maxscale" or os.environ.get('srv') == 'skysql-ha' + +def is_mysql(): + mysql_server = 1 + conn = create_connection() + cursor = conn.cursor() + cursor.execute("select version()") + row = cursor.fetchone() + if "MARIADB" in row[0].upper(): + mysql_server = 0 + del cursor, conn + return mysql_server def create_connection(additional_conf=None): default_conf = conf() diff --git a/testing/test/conf_test.py b/testing/test/conf_test.py index 0f4d533..add7de7 100644 --- a/testing/test/conf_test.py +++ b/testing/test/conf_test.py @@ -11,16 +11,16 @@ def glob(): def conf(): d = { - "user": os.environ.get('TEST_USER', 'root'), - "host": os.environ.get('TEST_HOST', 'localhost'), - "unix_socket" : "/tmp/mysql.sock", - "database": os.environ.get('TEST_DATABASE', 'testp'), - "port": int(os.environ.get('TEST_PORT', '3306')), + "user": os.environ.get('TEST_DB_USER', 'root'), + "host": os.environ.get('TEST_DB_HOST', 'localhost'), + "database": os.environ.get('TEST_DB_DATABASE', 'testp'), + "port": int(os.environ.get('TEST_DB_PORT', '3306')), } - if d["host"][-13:] == "db.skysql.net": - d["ssl"]= True + if os.environ.get('TEST_REQUIRE_TLS'): + if os.environ.get('TEST_REQUIRE_TLS') == "1": + d["ssl"] = True if os.environ.get('TEST_RESET_SESSION'): d["pool_reset_connection"] = int(os.environ.get('TEST_RESET_SESSION', '1')) - if os.environ.get('TEST_PASSWORD'): - d["password"] = os.environ.get('TEST_PASSWORD') + if os.environ.get('TEST_DB_PASSWORD'): + d["password"] = os.environ.get('TEST_DB_PASSWORD') return d diff --git a/testing/test/integration/test_connection.py b/testing/test/integration/test_connection.py index 52dd976..5104d3a 100644 --- a/testing/test/integration/test_connection.py +++ b/testing/test/integration/test_connection.py @@ -6,7 +6,7 @@ import mariadb -from test.base_test import create_connection, is_skysql +from test.base_test import create_connection, is_skysql, is_maxscale from test.conf_test import conf import platform @@ -84,7 +84,7 @@ def test_compress(self): cursor=new_conn.cursor() cursor.execute("SHOW SESSION STATUS LIKE 'compression'") row=cursor.fetchone() - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.assertEqual(row[1], "OFF") else: self.assertEqual(row[1], "ON") @@ -96,7 +96,7 @@ def test_schema(self): self.skipTest("CREATE OR REPLACE SCHEMA not supported") if self.connection.server_version < 100202: self.skipTest("session tracking not supported") - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't tell schema change for now") default_conf = conf() @@ -110,7 +110,7 @@ def test_schema(self): self.assertEqual(conn.database, default_conf["database"]) def test_ping(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE wrong thread id") conn = self.connection cursor = conn.cursor() @@ -130,7 +130,7 @@ def test_ed25519(self): if is_skysql(): self.skipTest("Test fail on SkySQL") default_conf = conf() - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support ed25519 for now") if self.connection.server_version < 100122: self.skipTest("ed25519 not supported") diff --git a/testing/test/integration/test_converter.py b/testing/test/integration/test_converter.py index 7df887a..ec9eb47 100644 --- a/testing/test/integration/test_converter.py +++ b/testing/test/integration/test_converter.py @@ -12,14 +12,18 @@ import datetime from test.base_test import create_connection + class foo(int): - def bar(self):pass + def bar(self): pass + def timedelta_to_time(s): return (datetime.datetime.min + s).time() + def long_minus(s): - return s-1; + return s - 1; + conversions = { **{FIELD_TYPE.TIME: timedelta_to_time}, @@ -27,29 +31,30 @@ def long_minus(s): **{FIELD_TYPE.LONGLONG: long_minus}, } + class TestConversion(unittest.TestCase): def setUp(self): - self.connection= create_connection({"converter":conversions}) + self.connection = create_connection({"converter": conversions}) self.connection.autocommit = False def tearDown(self): del self.connection def test_convert_time(self): - cursor= self.connection.cursor() - a= datetime.time(12,29,21) + cursor = self.connection.cursor() + a = datetime.time(12, 29, 21) cursor.execute("SELECT ?", (a,)) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], a) del cursor def test_convert_long(self): - cursor= self.connection.cursor() - a= 12345 + cursor = self.connection.cursor() + a = 12345 cursor.execute("SELECT CAST(? AS SIGNED)", (12345,)) - row= cursor.fetchone() - self.assertEqual(row[0],a-1) + row = cursor.fetchone() + self.assertEqual(row[0], a - 1) del cursor diff --git a/testing/test/integration/test_cursor.py b/testing/test/integration/test_cursor.py index 6050589..a32eff3 100644 --- a/testing/test/integration/test_cursor.py +++ b/testing/test/integration/test_cursor.py @@ -12,24 +12,14 @@ import mariadb from mariadb.constants import * -from test.base_test import create_connection - -server_indicator_version= 100206 - -def is_mysql(): - mysql_server= 1 - conn= create_connection() - cursor= conn.cursor() - cursor.execute("select version()") - row= cursor.fetchone() - print(row[0].upper()) - if "MARIADB" in row[0].upper(): - mysql_server= 0 - del cursor, conn - return mysql_server +from test.base_test import create_connection, is_maxscale, is_mysql + +server_indicator_version = 100206 + class foo(int): - def bar(self):pass + def bar(self): pass + class TestCursor(unittest.TestCase): @@ -139,7 +129,7 @@ def test_blob(self): del cursor def test_inserttuple(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() cursor.execute("CREATE TEMPORARY TABLE test_inserttuple (id int, name varchar(64), " @@ -152,12 +142,12 @@ def test_inserttuple(self): cursor.executemany("INSERT INTO test_inserttuple VALUES (?,?,?)", params); cursor.execute("SELECT name FROM test_inserttuple ORDER BY id DESC") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual("Andrey", row[0]); del cursor def test_fetchmany(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() cursor.execute("CREATE TEMPORARY TABLE test_fetchmany (id int, name varchar(64), " @@ -255,7 +245,7 @@ def test_xfield_types(self): self.assertEqual(fieldinfo.type(info[7]), "STRING") self.assertEqual(fieldinfo.type(info[8]), "VAR_STRING") self.assertEqual(fieldinfo.type(info[9]), "BLOB") - if self.connection.server_version_info > (10, 5, 1) or is_mysql(): + if not is_maxscale() and (self.connection.server_version_info > (10, 5, 1) or is_mysql()): self.assertEqual(fieldinfo.type(info[10]), "JSON") else: self.assertEqual(fieldinfo.type(info[10]), "BLOB") @@ -266,7 +256,7 @@ def test_xfield_types(self): del cursor def test_bulk_delete(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() cursor.execute( @@ -284,7 +274,7 @@ def test_bulk_delete(self): del cursor def test_pyformat(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() @@ -303,7 +293,7 @@ def test_pyformat(self): self.assertEqual(row[0], "Andrey") def test_format(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() @@ -322,7 +312,7 @@ def test_format(self): self.assertEqual(row[0], "Andrey") def test_named_tuple(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor(named_tuple=1) @@ -344,7 +334,7 @@ def test_named_tuple(self): del cursor def test_laststatement(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor(named_tuple=1) @@ -418,12 +408,12 @@ def test_tuple(self): def test_indicator(self): if self.connection.server_version < server_indicator_version: self.skipTest("Requires server version >= 10.2.6") - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() cursor.execute("CREATE TEMPORARY TABLE ind1 (a int, b int default 2,c int)") - vals = [(1,4,3),(INDICATOR.NULL, INDICATOR.DEFAULT, 3)] + vals = [(1, 4, 3), (INDICATOR.NULL, INDICATOR.DEFAULT, 3)] cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals) cursor.execute("SELECT a, b, c FROM ind1") row = cursor.fetchone() @@ -494,12 +484,12 @@ def test_conpy34(self): cursor = self.connection.cursor() cursor.execute("CREATE TEMPORARY TABLE t1 (a varchar(20), b varchar(20))") try: - cursor.execute("INSERT INTO test.t1(fname, sname) VALUES (?, ?)", (("Walker", "Percy"), ("Flannery", "O'Connor"))) + cursor.execute("INSERT INTO test.t1(fname, sname) VALUES (?, ?)", + (("Walker", "Percy"), ("Flannery", "O'Connor"))) except mariadb.DataError: pass del cursor - def test_scroll(self): cursor = self.connection.cursor(buffered=True) stmt = "SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4" @@ -554,7 +544,7 @@ def test_conpy_9(self): del cursor def test_conpy_15(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() cursor.execute( @@ -580,7 +570,7 @@ def test_conpy_15(self): del cursor def test_conpy_14(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() self.assertEqual(cursor.rowcount, -1) @@ -621,7 +611,7 @@ def test_iterator(self): self.assertEqual(i + 1, row[0]) def test_update_bulk(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() @@ -694,7 +684,6 @@ def test_multiple_cursor(self): row = cursor2.fetchone() del cursor, cursor2 - def test_inaccurate_rownumber(self): cursor = self.connection.cursor(buffered=True) self.assertEqual(cursor.rownumber, None) @@ -729,50 +718,52 @@ def test_inaccurate_rownumber(self): del cursor def test_sp1(self): - con= create_connection() - cursor= con.cursor() + con = create_connection() + cursor = con.cursor() cursor.execute("DROP PROCEDURE IF EXISTS p1") cursor.execute("CREATE PROCEDURE p1( )\nBEGIN\n SELECT 1;\nEND") cursor.callproc("p1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) cursor.execute("DROP PROCEDURE IF EXISTS p1") def test_sp2(self): - con= create_connection() + con = create_connection() if con.server_version < 100301: self.skipTest("Not supported in versions < 10.3") - cursor= con.cursor() + cursor = con.cursor() cursor.execute("DROP PROCEDURE IF EXISTS p2") - cursor.execute("CREATE PROCEDURE p2(IN s1 VARCHAR(20), IN s2 VARCHAR(20), OUT o1 VARCHAR(40) )\nBEGIN\nSET o1:=CAST(CONCAT(s1,s2) AS char CHARACTER SET utf8mb4);\nEND") + cursor.execute( + "CREATE PROCEDURE p2(IN s1 VARCHAR(20), IN s2 VARCHAR(20), OUT o1 VARCHAR(40) )\nBEGIN\nSET o1:=CAST(CONCAT(s1,s2) AS char CHARACTER SET utf8mb4);\nEND") cursor.callproc("p2", ("foo", "bar", 1)) self.assertEqual(cursor.sp_outparams, True) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], "foobar") cursor.nextset() del cursor - cursor=con.cursor() + cursor = con.cursor() cursor.execute("CALL p2(?,?,?)", ("foo", "bar", 0)) self.assertEqual(cursor.sp_outparams, True) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], "foobar") cursor.execute("DROP PROCEDURE IF EXISTS p2") del cursor, con def test_sp3(self): - con= create_connection() + con = create_connection() if con.server_version < 100301: self.skipTest("Not supported in versions < 10.3") - cursor= con.cursor() + cursor = con.cursor() cursor.execute("DROP PROCEDURE IF EXISTS p3") - cursor.execute("CREATE PROCEDURE p3(IN s1 VARCHAR(20), IN s2 VARCHAR(20), OUT o1 VARCHAR(40) )\nBEGIN\nSELECT '1';\nSET o1:=CAST(CONCAT(s1,s2) AS char CHARACTER SET utf8mb4);\nEND") + cursor.execute( + "CREATE PROCEDURE p3(IN s1 VARCHAR(20), IN s2 VARCHAR(20), OUT o1 VARCHAR(40) )\nBEGIN\nSELECT '1';\nSET o1:=CAST(CONCAT(s1,s2) AS char CHARACTER SET utf8mb4);\nEND") cursor.callproc("p3", ("foo", "bar", 1)) self.assertEqual(cursor.sp_outparams, False) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], "1") cursor.nextset() self.assertEqual(cursor.sp_outparams, True) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], "foobar") cursor.execute("DROP PROCEDURE IF EXISTS p3") del cursor, con @@ -780,17 +771,18 @@ def test_sp3(self): def test_conpy42(self): if is_mysql(): self.skipTest("Skip (MySQL)") - con= create_connection() + con = create_connection() cursor = con.cursor() cursor.execute("CREATE TEMPORARY TABLE conpy42(a GEOMETRY)") cursor.execute("INSERT INTO conpy42 VALUES (PointFromText('point(1 1)'))") cursor.execute("SELECT a FROM conpy42") - row= cursor.fetchone() - self.assertEqual(row[0], b'\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?') + row = cursor.fetchone() + self.assertEqual(row[0], + b'\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?') del cursor def test_conpy35(self): - con= create_connection() + con = create_connection() cursor = con.cursor() cursor.execute("CREATE TEMPORARY table sample (id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(64))"); @@ -800,89 +792,89 @@ def test_conpy35(self): cursor = con.cursor(cursor_type=CURSOR.READ_ONLY) cursor.execute("SELECT * FROM sample ORDER BY id") - i= 0 + i = 0 for row in cursor: - i= i+1 + i = i + 1 self.assertEqual(row[0], i) del cursor def test_conpy45(self): - con= create_connection() + con = create_connection() cursor = con.cursor() cursor.execute("CREATE TEMPORARY table t1 (a time(3), b datetime(2))") cursor.execute("INSERT INTO t1 VALUES ('13:12:24.05111', '2020-10-10 14:12:24.123456')") cursor.execute("SELECT a,b FROM t1"); - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], datetime.timedelta(seconds=47544, microseconds=51000)) self.assertEqual(row[1], datetime.datetime(2020, 10, 10, 14, 12, 24, 120000)) del cursor del con def test_conpy46(self): - con= create_connection() + con = create_connection() with con.cursor() as cursor: - cursor.execute("SELECT 'foo'") - row= cursor.fetchone() + cursor.execute("SELECT 'foo'") + row = cursor.fetchone() self.assertEqual(row[0], "foo") try: - cursor.execute("SELECT 'bar'") + cursor.execute("SELECT 'bar'") except mariadb.ProgrammingError: pass del con def test_conpy47(self): - con= create_connection() - cursor=con.cursor() - cursor.execute("SELECT ?", (True, )) - row= cursor.fetchone() + con = create_connection() + cursor = con.cursor() + cursor.execute("SELECT ?", (True,)) + row = cursor.fetchone() self.assertEqual(row[0], 1) - cursor.execute("SELECT ?", (False, )) - row= cursor.fetchone() + cursor.execute("SELECT ?", (False,)) + row = cursor.fetchone() self.assertEqual(row[0], 0) del con def test_conpy48(self): - con= create_connection() - cur=con.cursor() + con = create_connection() + cur = con.cursor() cur.execute("select %s", [True]) - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 1) cur.execute("create temporary table t1 (a int)") - cur.executemany("insert into t1 values (%s)", [[1],(2,)]) + cur.executemany("insert into t1 values (%s)", [[1], (2,)]) cur.execute("select a from t1") - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 1) - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 2) del con def test_conpy51(self): - con= create_connection() - cur=con.cursor(buffered=True) + con = create_connection() + cur = con.cursor(buffered=True) cur.execute('create temporary table temp (a int unsigned)') cur.execute('insert into temp values (1), (2), (3)') cur.execute('select a from temp order by a') con.commit() - row= cur.fetchall() + row = cur.fetchall() self.assertEqual(row[0][0], 1) self.assertEqual(row[1][0], 2) self.assertEqual(row[2][0], 3) del con def test_conpy52(self): - con= create_connection() - cur=con.cursor(buffered=True) + con = create_connection() + cur = con.cursor(buffered=True) cur.execute('create temporary table temp (a int unsigned)') cur.execute('insert into temp values (1), (2), (3)') cur.execute('select a from temp order by a') con.commit() - row= cur.fetchall() + row = cur.fetchall() self.assertEqual(row[0][0], 1) self.assertEqual(row[1][0], 2) self.assertEqual(row[2][0], 3) - cur.execute('select a from temp where a > ?', (0, )) + cur.execute('select a from temp where a > ?', (0,)) con.commit() - row= cur.fetchall() + row = cur.fetchall() self.assertEqual(row[0][0], 1) self.assertEqual(row[1][0], 2) self.assertEqual(row[2][0], 3) @@ -890,81 +882,81 @@ def test_conpy52(self): del con def test_conpy49(self): - con= create_connection() - cur=con.cursor() + con = create_connection() + cur = con.cursor() cur.execute("create temporary table t1 (a decimal(10,2))") cur.execute("insert into t1 values (?)", (Decimal('10.2'),)) cur.execute("select a from t1") - row=cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], Decimal('10.20')) del con def test_conpy56(self): - con= create_connection() - cur=con.cursor(dictionary=True) + con = create_connection() + cur = con.cursor(dictionary=True) cur.execute("select 'foo' as bar, 'bar' as foo") - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row["foo"], "bar") self.assertEqual(row["bar"], "foo") del con def test_conpy53(self): - con= create_connection() - cur=con.cursor() + con = create_connection() + cur = con.cursor() cur.execute("select 1", ()) - row=cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 1) cur.execute("select 1", []) - row=cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 1) del con def test_conpy58(self): - con= create_connection() - cursor=con.cursor() - cursor.execute("SELECT %(val)s", {"val" : 3}) - row= cursor.fetchone() + con = create_connection() + cursor = con.cursor() + cursor.execute("SELECT %(val)s", {"val": 3}) + row = cursor.fetchone() self.assertEqual(row[0], 3) cursor.execute("CREATE TEMPORARY TABLE t1 (a int)") - cursor.executemany("INSERT INTO t1 VALUES (%(val)s)", [{"val" : 1}, {"val" : 2}]) + cursor.executemany("INSERT INTO t1 VALUES (%(val)s)", [{"val": 1}, {"val": 2}]) cursor.execute("SELECT a FROM t1 ORDER by a") - row= cursor.fetchall() + row = cursor.fetchall() self.assertEqual(row[0][0], 1) self.assertEqual(row[1][0], 2) del con def test_conpy59(self): - con= create_connection() - cursor=con.cursor() + con = create_connection() + cursor = con.cursor() cursor.execute("CREATE TEMPORARY TABLE t1 (a date)") cursor.execute("INSERT INTO t1 VALUES('0000-01-01')") cursor.execute("SELECT a FROM t1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], None) del con def test_conpy61(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") - con= create_connection() + con = create_connection() if self.connection.server_version < server_indicator_version: self.skipTest("Requires server version >= 10.2.6") - cursor=con.cursor() + cursor = con.cursor() cursor.execute("CREATE TEMPORARY TABLE ind1 (a int, b int default 2,c int)") - vals = [(1,4,3),(None, 2, 3)] + vals = [(1, 4, 3), (None, 2, 3)] cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals) cursor.execute("SELECT a, b, c FROM ind1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], None) cursor.execute("DELETE FROM ind1") - vals=[(1,4,3), (INDICATOR.NULL, INDICATOR.DEFAULT, None)] + vals = [(1, 4, 3), (INDICATOR.NULL, INDICATOR.DEFAULT, None)] cursor.executemany("INSERT INTO ind1 VALUES (?,?,?)", vals) cursor.execute("SELECT a, b, c FROM ind1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], None) self.assertEqual(row[1], 2) self.assertEqual(row[2], None) @@ -972,16 +964,16 @@ def test_conpy61(self): del cursor def test_conpy62(self): - con= create_connection() + con = create_connection() cur = con.cursor() - con= create_connection() + con = create_connection() query = "select round(.75 * (? / 3), 2) as val" - cur.execute(query,[5]) - row= cur.fetchone() + cur.execute(query, [5]) + row = cur.fetchone() self.assertEqual(row[0], Decimal(1.25)) def test_conpy67(self): - con= create_connection() + con = create_connection() cur = con.cursor() cur.execute("SELECT 1") self.assertEqual(cur.rowcount, 0) @@ -995,13 +987,13 @@ def test_conpy67(self): self.assertEqual(cur.rowcount, 0) def test_negative_numbers(self): - con= create_connection() + con = create_connection() cur = con.cursor() cur.execute("drop table if exists t1") cur.execute("create table t1(a tinyint, b int, c bigint)") cur.execute("insert into t1 values (?,?,?)", (-1, -300, -2147483649)) cur.execute("select a, b, c FROM t1") - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], -1) self.assertEqual(row[1], -300) self.assertEqual(row[2], -2147483649) @@ -1009,83 +1001,83 @@ def test_negative_numbers(self): con.close() def test_none_val(self): - con= create_connection() + con = create_connection() cur = con.cursor() cur.execute("CREATE TEMPORARY TABLE t1 (a int)") - vals= [(1,),(2,), (4,), (None,), (3,)] + vals = [(1,), (2,), (4,), (None,), (3,)] cur.executemany("INSERT INTO t1 VALUES (?)", vals) cur.execute("select a from t1 order by a") - rows= cur.fetchall() + rows = cur.fetchall() self.assertEqual(rows[0][0], None); del cur def test_conpy81(self): - con= create_connection() - cur=con.cursor() + con = create_connection() + cur = con.cursor() cur.execute("CREATE TEMPORARY TABLE t1 (a int)") cur.execute("INSERT INTO t1 VALUES(1)") cur.execute("SELECT a FROM t1") - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 1); cur.execute("SELECT a FROM t1 WHERE 1=?", (1,)) - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 1); del cur def test_conpy94(self): - con= create_connection() - cur= con.cursor() - a= foo(2) + con = create_connection() + cur = con.cursor() + a = foo(2) cur.execute("SELECT ?", (a,)) - row= cur.fetchone() + row = cur.fetchone() self.assertEqual(row[0], 2) del cur def test_conpy98(self): - con= create_connection() - cursor=con.cursor() + con = create_connection() + cursor = con.cursor() cursor.execute("SELECT CAST('foo' AS BINARY) AS anon_1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], b'foo') del cursor def test_conpy68(self): - con= create_connection() + con = create_connection() if con.server_version < 100207: self.skipTest("Not supported in versions < 10.2.7") - cursor=con.cursor() + cursor = con.cursor() cursor.execute("CREATE TEMPORARY TABLE t1 (a JSON)") - content = {'a': 'aaa', 'b': 'bbb', 'c': 123 } + content = {'a': 'aaa', 'b': 'bbb', 'c': 123} cursor.execute("INSERT INTO t1 VALUES(?)", (json.dumps(content),)) cursor.execute("SELECT a FROM t1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], json.dumps(content)) del cursor def test_conpy123(self): - con= create_connection({"client_flag" : CLIENT.MULTI_STATEMENTS}) - cursor1= con.cursor() + con = create_connection({"client_flag": CLIENT.MULTI_STATEMENTS}) + cursor1 = con.cursor() cursor1.execute("SELECT 1; SELECT 2") cursor1.close() - cursor2= con.cursor() + cursor2 = con.cursor() cursor2.execute("SELECT 1") - row= cursor2.fetchone() + row = cursor2.fetchone() self.assertEqual(row[0], 1) cursor2.close() con.close() def test_conpy103(self): - con= create_connection() - cursor= con.cursor() + con = create_connection() + cursor = con.cursor() cursor.execute("CREATE TEMPORARY TABLE t1 (a decimal(10,2))") cursor.executemany("INSERT INTO t1 VALUES (?)", [[decimal.Decimal(1)]]) cursor.execute("SELECT a FROM t1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], decimal.Decimal(1)) def test_conpy129(self): - conn= create_connection() - server_version= conn.server_version + conn = create_connection() + server_version = conn.server_version major = int(server_version / 10000) minor = int((server_version % 10000) / 100) patch = server_version % 100; @@ -1095,40 +1087,40 @@ def test_conpy129(self): def test_conpy133(self): if is_mysql(): self.skipTest("Skip (MySQL)") - conn= create_connection() + conn = create_connection() - cursor= conn.cursor() + cursor = conn.cursor() cursor.execute("SELECT /*! ? */", (1,)) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) del cursor - cursor= conn.cursor() + cursor = conn.cursor() cursor.execute("SELECT /*M! ? */", (1,)) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) del cursor - cursor= conn.cursor() + cursor = conn.cursor() cursor.execute("SELECT /*M!50601 ? */", (1,)) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) del cursor - cursor= conn.cursor() + cursor = conn.cursor() cursor.execute("SELECT /*!40301 ? */", (1,)) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[0], 1) del cursor - cursor= conn.cursor() + cursor = conn.cursor() try: cursor.execute("SELECT /*!50701 ? */", (1,)) except mariadb.DataError: pass del cursor - cursor= conn.cursor() + cursor = conn.cursor() try: cursor.execute("SELECT /*!250701 ? */", (1,)) except mariadb.DataError: @@ -1136,33 +1128,36 @@ def test_conpy133(self): del cursor def test_conpy139(self): - connection= create_connection() - cursor= connection.cursor() + connection = create_connection() + cursor = connection.cursor() cursor.execute("create temporary table t1 (a varchar(254) character set utf8mb4 collate utf8mb4_bin)") cursor.execute("insert into t1 values ('foo')") del cursor - c1= connection.cursor() - c2= connection.cursor(prepared=True) + c1 = connection.cursor() + c2 = connection.cursor(prepared=True) c1.execute("select a from t1") - r1= c1.fetchall() + r1 = c1.fetchall() c2.execute("select a from t1") - r2= c2.fetchall() + r2 = c2.fetchall() self.assertEqual(r1, r2) - + del c1, c2 connection.close() def test_conpy150(self): - connection= create_connection() - cursor= connection.cursor() - cursor.execute("create temporary table t1 (id int, a datetime not null default '0000-00-00 00:00:00', b date not null default '0000-00-00')") + if is_mysql(): + self.skipTest("Skip (MySQL)") + connection = create_connection() + cursor = connection.cursor() + cursor.execute( + "create temporary table t1 (id int, a datetime not null default '0000-00-00 00:00:00', b date not null default '0000-00-00')") cursor.execute("insert into t1 (id) values (1)"); cursor.execute("select * from t1") - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[1], None) self.assertEqual(row[2], None) cursor.execute("select * from t1 WHERE 1=?", (1,)) - row= cursor.fetchone() + row = cursor.fetchone() self.assertEqual(row[1], None) self.assertEqual(row[2], None) del cursor diff --git a/testing/test/integration/test_cursor_mysql.py b/testing/test/integration/test_cursor_mysql.py index 6d6715e..007ebf1 100644 --- a/testing/test/integration/test_cursor_mysql.py +++ b/testing/test/integration/test_cursor_mysql.py @@ -5,7 +5,7 @@ import unittest import os -from test.base_test import create_connection +from test.base_test import create_connection, is_maxscale class CursorMySQLTest(unittest.TestCase): @@ -17,7 +17,7 @@ def tearDown(self): del self.connection def test_parameter(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") cursor = self.connection.cursor() diff --git a/testing/test/integration/test_dbapi20.py b/testing/test/integration/test_dbapi20.py index d496949..519be0c 100644 --- a/testing/test/integration/test_dbapi20.py +++ b/testing/test/integration/test_dbapi20.py @@ -70,6 +70,8 @@ # from test.conf_test import conf +from test.base_test import is_maxscale + class DatabaseAPI20Test(unittest.TestCase): ''' Test a database self.driver for DB API 2.0 compatibility. @@ -404,7 +406,7 @@ def _paraminsert(self, cur): ) def test_executemany(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't support BULK yet") con = self._connect() try: diff --git a/testing/test/integration/test_module.py b/testing/test/integration/test_module.py index b7a65bd..f3328c8 100644 --- a/testing/test/integration/test_module.py +++ b/testing/test/integration/test_module.py @@ -20,15 +20,16 @@ def tearDown(self): del self.connection def test_conpy_63(self): - version= mariadb.__version__ - version_info= mariadb.__version_info__ + version = mariadb.__version__ + version_info = mariadb.__version_info__ - num_version= list(map(int, version.split('.'))) + num_version = list(map(int, version.split('.'))) self.assertEqual(num_version[0], version_info[0]) self.assertEqual(num_version[1], version_info[1]) self.assertEqual(num_version[2], version_info[2]) self.assertEqual(0, version_info[4]) + if __name__ == '__main__': unittest.main() diff --git a/testing/test/integration/test_nondbapi.py b/testing/test/integration/test_nondbapi.py index 2933c59..4d2b5cc 100644 --- a/testing/test/integration/test_nondbapi.py +++ b/testing/test/integration/test_nondbapi.py @@ -6,7 +6,7 @@ import os import mariadb -from test.base_test import create_connection, is_skysql +from test.base_test import create_connection, is_skysql, is_maxscale, is_mysql from test.conf_test import conf @@ -19,11 +19,11 @@ def tearDown(self): del self.connection def test_ping(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE return wrong thread id") new_conn = create_connection() - id = new_conn.connection_id; + id = new_conn.connection_id self.connection.kill(id) try: new_conn.ping() @@ -32,7 +32,7 @@ def test_ping(self): del new_conn new_conn = create_connection() new_conn.auto_reconnect = True - id = new_conn.connection_id; + id = new_conn.connection_id self.connection.kill(id) new_conn.ping() new_id = new_conn.connection_id @@ -44,11 +44,12 @@ def test_change_user(self): self.skipTest("SkySQL failure") if self.connection.server_version < 100103: self.skipTest("CREATE OR REPLACE USER not supported") - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE doesn't get new user immediately") if self.connection.server_name == "localhost": - curs= self.connection.cursor(buffered=True) - curs.execute("select * from information_schema.plugins where plugin_name='unix_socket' and plugin_status='ACTIVE'") + curs = self.connection.cursor(buffered=True) + curs.execute( + "select * from information_schema.plugins where plugin_name='unix_socket' and plugin_status='ACTIVE'") if curs.rowcount > 0: del curs self.skipTest("unix_socket is active") @@ -57,17 +58,21 @@ def test_change_user(self): default_conf = conf() cursor = self.connection.cursor() cursor.execute("drop user if exists foo") - cursor.execute("create user foo@'%'") - cursor.execute("GRANT ALL on `" + default_conf["database"] + "`.* TO foo@'%'") + if is_mysql() and self.connection.server_version < 80000: + cursor.execute("create user foo@'%'") + cursor.execute("GRANT ALL on `" + default_conf["database"] + "`.* TO foo@'%' IDENTIFIED BY 'heyPassw-!µ20§rd'") + else: + cursor.execute("create user foo@'%' IDENTIFIED BY 'heyPassw-!µ20§rd'") + cursor.execute("GRANT ALL on `" + default_conf["database"] + "`.* TO foo@'%'") new_conn = create_connection() - new_conn.change_user("foo", "", "") + new_conn.change_user("foo", "heyPassw-!µ20§rd", "") self.assertEqual("foo", new_conn.user) cursor.execute("drop user foo") del new_conn del cursor def test_reconnect(self): - if os.environ.get("MAXSCALE_VERSION"): + if is_maxscale(): self.skipTest("MAXSCALE wrong thread id") new_conn = create_connection() conn1_id = new_conn.connection_id diff --git a/testing/test/integration/test_pooling.py b/testing/test/integration/test_pooling.py index fd4eb6e..439e9cf 100644 --- a/testing/test/integration/test_pooling.py +++ b/testing/test/integration/test_pooling.py @@ -9,194 +9,203 @@ import platform import sys -from test.base_test import create_connection, conf +from test.base_test import create_connection, conf, is_skysql, is_maxscale @unittest.skipIf(platform.python_implementation() == "PyPy", "skip pooling tests for PyPy") class TestPooling(unittest.TestCase): - - def setUp(self): - pass -# self.connection = create_connection() -# self.connection.autocommit = False - - def tearDown(self): - pass -# del self.connection - - def test_connection_pools(self): - pool= mariadb.ConnectionPool(pool_name="test_connection") - self.assertEqual(mariadb._CONNECTION_POOLS["test_connection"], pool) - pool.close() - self.assertEqual(mariadb._CONNECTION_POOLS, {}) - - def test_conpy39(self): - try: - pool= mariadb.ConnectionPool() - except mariadb.ProgrammingError: - pass - - def test_connection_pool_conf(self): - pool= mariadb.ConnectionPool(pool_name="test_conf") - default_conf= conf() - conn= create_connection() - try: - pool.add_connection(conn) - except mariadb.PoolError: - pass - try: - pool.set_config(**default_conf) - except: - pool.close() - raise - - pool.add_connection(conn) - c= pool.get_connection() - self.assertEqual(c, conn) - pool.close() - - def test_connection_pool_maxconn(self): - default_conf= conf() - pool= mariadb.ConnectionPool(pool_name="test_max_size", **default_conf) - connections= [] - for i in range(1, 6): + + def setUp(self): + pass + + # self.connection = create_connection() + # self.connection.autocommit = False + + def tearDown(self): + pass + + # del self.connection + + def test_connection_pools(self): + pool = mariadb.ConnectionPool(pool_name="test_connection") + self.assertEqual(mariadb._CONNECTION_POOLS["test_connection"], pool) + pool.close() + self.assertEqual(mariadb._CONNECTION_POOLS, {}) + + def test_conpy39(self): + try: + pool = mariadb.ConnectionPool() + except mariadb.ProgrammingError: + pass + + def test_connection_pool_conf(self): + pool = mariadb.ConnectionPool(pool_name="test_conf") + default_conf = conf() + conn = create_connection() + try: + pool.add_connection(conn) + except mariadb.PoolError: + pass + try: + pool.set_config(**default_conf) + except: + pool.close() + raise + + pool.add_connection(conn) + c = pool.get_connection() + self.assertEqual(c, conn) + pool.close() + + def test_connection_pool_maxconn(self): + default_conf = conf() + pool = mariadb.ConnectionPool(pool_name="test_max_size", **default_conf) + connections = [] + for i in range(1, 6): connections.append(pool.get_connection()) - try: - x= pool.get_connection() - except mariadb.PoolError: - pass - for c in connections: - c.close() - x= pool.get_connection() - pool.close() - - def test_connection_pool_add(self): - default_conf= conf() - pool= mariadb.ConnectionPool(pool_name="test_connection_pool_add") - try: - pool.set_config(**default_conf) - except: - pool.close() - raise - - for i in range(1,6): - pool.add_connection() - try: - pool.add_connection() - except mariadb.PoolError: - pass - pool.close() - - def test_conpy69(self): - conn= create_connection() - conn.autocommit= True - cursor1= conn.cursor() - cursor1.execute("CREATE SCHEMA IF NOT EXISTS 中文考试") - cursor1.execute("COMMIT"); - default_conf= conf() - default_conf["database"]= "中文考试" - pool= mariadb.ConnectionPool(pool_name="test_conpy69") - try: - pool.set_config(**default_conf) - except: - pool.close() - raise - - for i in range(1,6): - pool.add_connection() - conn= mariadb.connect(pool_name="test_conpy69") - conn.autocommit= True - cursor= conn.cursor() - cursor.execute("select database()") - row= cursor.fetchone() - self.assertEqual(row[0], "中文考试") - cursor.execute("CREATE TABLE t1 (a varchar(255)) character set utf8mb4") - cursor.execute("insert into t1 values (?)", ("123.45 中文考试",)) - cursor.execute("select a from t1", buffered=True) - row= cursor.fetchone() - self.assertEqual(row[0], "123.45 中文考试") - cursor1.execute("DROP SCHEMA 中文考试") - pool.close() - - def test__CONNECTION_POOLS(self): - default_conf= conf() - pool= mariadb.ConnectionPool(pool_name="test_use", **default_conf) - conn= mariadb.connect(pool_name="test_use") - cursor= conn.cursor() - cursor.execute("SELECT 1") - row= cursor.fetchone() - self.assertEqual(row[0], 1) - del cursor - pool.close() - - def test_create_pool_from_conn(self): - default_conf= conf() - key= "t1" - conn= mariadb.connect(pool_name=key, **default_conf) - cursor=conn.cursor() - del mariadb._CONNECTION_POOLS["t1"] - self.assertEqual(mariadb._CONNECTION_POOLS, {}) - try: - cursor.execute("SELECT 1") - except mariadb.ProgrammingError: - pass - - def test_pool_getter(self): - default_conf= conf() - conn= mariadb.connect(pool_name="getter_test", pool_size=4, **default_conf) - p= mariadb._CONNECTION_POOLS["getter_test"] - self.assertEqual(p.pool_name, "getter_test") - self.assertEqual(p.pool_size, 4) - if "pool_reset_connection" in default_conf: - self.assertEqual(p.pool_reset_connection, default_conf["pool_reset_connection"]) - else: - self.assertEqual(p.pool_reset_connection, True) - self.assertEqual(p.max_size, 64) - mariadb._CONNECTION_POOLS["getter_test"].close() - - def test_pool_connection_reset(self): - default_conf= conf() - conn= mariadb.connect(pool_name="reset_test", pool_size=1, **default_conf) - cursor= conn.cursor() - cursor.execute("SELECT 1") - cursor.close() - conn.close() - conn= mariadb.connect(pool_name="reset_test") - cursor= conn.cursor() - cursor.execute("SELECT 2") - row= cursor.fetchone() - self.assertEqual(row[0], 2) - mariadb._CONNECTION_POOLS["reset_test"].close() - - def test_conpy40(self): - default_conf= conf() - pool = mariadb.ConnectionPool(pool_name = 'test_conpy40') - - try: - pool.set_config(pool_size = 3) - except mariadb.PoolError: - pass - - try: - pool.set_config(**default_conf) - except: - pool.close() - raise - - for j in range(3): - c = mariadb.connect(**default_conf) - pool.add_connection(c) - pool.close() - - def test_pool_add(self): - default_conf= conf() - pool= mariadb.ConnectionPool(pool_name="test_pool_add") - try: - mariadb.ConnectionPool(pool_name="test_pool_add") - except mariadb.ProgrammingError as e: - pass - pool.close() - self.assertEqual(mariadb._CONNECTION_POOLS, {}) - + try: + x = pool.get_connection() + except mariadb.PoolError: + pass + for c in connections: + c.close() + x = pool.get_connection() + pool.close() + + def test_connection_pool_add(self): + default_conf = conf() + pool = mariadb.ConnectionPool(pool_name="test_connection_pool_add") + try: + pool.set_config(**default_conf) + except: + pool.close() + raise + + for i in range(1, 6): + pool.add_connection() + try: + pool.add_connection() + except mariadb.PoolError: + pass + pool.close() + + def test_conpy69(self): + if is_skysql(): + self.skipTest("skipping on SkySQL") + if is_maxscale(): + self.skipTest("skipping on Maxscale: bug https://jira.mariadb.org/browse/MXS-3921") + conn = create_connection() + conn.autocommit = True + cursor1 = conn.cursor() + cursor1.execute("CREATE DATABASE IF NOT EXISTS `中文考试` CHARACTER SET 'utf8mb4'") + cursor1.execute("COMMIT") + default_conf = conf() + default_conf["database"] = "中文考试" + pool = mariadb.ConnectionPool(pool_name="test_conpy69") + try: + pool.set_config(**default_conf) + except: + pool.close() + raise + + try: + for i in range(1, 6): + pool.add_connection() + conn = mariadb.connect(pool_name="test_conpy69") + conn.autocommit = True + cursor = conn.cursor() + cursor.execute("select database()") + row = cursor.fetchone() + self.assertEqual(row[0], "中文考试") + cursor.execute("CREATE TABLE t1 (a varchar(255)) character set utf8mb4") + cursor.execute("insert into t1 values (?)", ("123.45 中文考试",)) + cursor.execute("select a from t1", buffered=True) + row = cursor.fetchone() + self.assertEqual(row[0], "123.45 中文考试") + cursor1.execute("DROP SCHEMA 中文考试") + finally: + pool.close() + + def test__CONNECTION_POOLS(self): + default_conf = conf() + pool = mariadb.ConnectionPool(pool_name="test_use", **default_conf) + conn = mariadb.connect(pool_name="test_use") + cursor = conn.cursor() + cursor.execute("SELECT 1") + row = cursor.fetchone() + self.assertEqual(row[0], 1) + del cursor + pool.close() + + def test_create_pool_from_conn(self): + default_conf = conf() + key = "t1" + conn = mariadb.connect(pool_name=key, **default_conf) + cursor = conn.cursor() + del mariadb._CONNECTION_POOLS["t1"] + self.assertEqual(mariadb._CONNECTION_POOLS, {}) + try: + cursor.execute("SELECT 1") + except mariadb.ProgrammingError: + pass + + def test_pool_getter(self): + default_conf = conf() + conn = mariadb.connect(pool_name="getter_test", pool_size=4, **default_conf) + p = mariadb._CONNECTION_POOLS["getter_test"] + self.assertEqual(p.pool_name, "getter_test") + self.assertEqual(p.pool_size, 4) + if "pool_reset_connection" in default_conf: + self.assertEqual(p.pool_reset_connection, default_conf["pool_reset_connection"]) + else: + self.assertEqual(p.pool_reset_connection, True) + self.assertEqual(p.max_size, 64) + mariadb._CONNECTION_POOLS["getter_test"].close() + + def test_pool_connection_reset(self): + default_conf = conf() + conn = mariadb.connect(pool_name="reset_test", pool_size=1, **default_conf) + cursor = conn.cursor() + cursor.execute("SELECT 1") + cursor.close() + conn.close() + conn = mariadb.connect(pool_name="reset_test") + cursor = conn.cursor() + cursor.execute("SELECT 2") + row = cursor.fetchone() + self.assertEqual(row[0], 2) + mariadb._CONNECTION_POOLS["reset_test"].close() + + def test_conpy40(self): + default_conf = conf() + pool = mariadb.ConnectionPool(pool_name='test_conpy40') + + try: + pool.set_config(pool_size=3) + except mariadb.PoolError: + pass + + try: + pool.set_config(**default_conf) + except: + pool.close() + raise + + for j in range(3): + c = mariadb.connect(**default_conf) + pool.add_connection(c) + pool.close() + + def test_pool_add(self): + default_conf = conf() + pool = mariadb.ConnectionPool(pool_name="test_pool_add") + try: + mariadb.ConnectionPool(pool_name="test_pool_add") + except mariadb.ProgrammingError as e: + pass + pool.close() + self.assertEqual(mariadb._CONNECTION_POOLS, {}) + + if __name__ == '__main__': - unittest.main() + unittest.main()