From 9b57dafc88b5166f80d931415e09ae063568b69f Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Tue, 21 Jan 2025 10:58:56 +0100 Subject: [PATCH] Update bundled MySQL version to 8.0.40 (#17552) Signed-off-by: Dirkjan Bussink Signed-off-by: Florent Poinsard Signed-off-by: Harshit Gangal Co-authored-by: Florent Poinsard Co-authored-by: Harshit Gangal --- Makefile | 2 +- changelog/22.0/22.0.0/summary.md | 26 + docker/binaries/vtadmin/Dockerfile | 2 +- docker/bootstrap/CHANGELOG.md | 6 +- docker/bootstrap/Dockerfile.common | 7 +- docker/bootstrap/Dockerfile.mysql80 | 4 +- docker/bootstrap/Dockerfile.percona80 | 4 +- docker/lite/Dockerfile | 4 +- docker/lite/Dockerfile.percona80 | 4 +- docker/utils/install_dependencies.sh | 96 +--- docker/vttestserver/Dockerfile.mysql80 | 6 +- examples/operator/101_initial_cluster.yaml | 4 +- examples/operator/201_customer_tablets.yaml | 2 +- examples/operator/302_new_shards.yaml | 2 +- examples/operator/306_down_shard_0.yaml | 2 +- examples/operator/401_scheduled_backups.yaml | 2 +- go/flags/endtoend/mysqlctl.txt | 2 +- go/flags/endtoend/mysqlctld.txt | 2 +- go/flags/endtoend/vtbackup.txt | 2 +- go/flags/endtoend/vtbench.txt | 2 +- go/flags/endtoend/vtclient.txt | 2 +- go/flags/endtoend/vtcombo.txt | 2 +- go/flags/endtoend/vtctld.txt | 2 +- go/flags/endtoend/vtctldclient.txt | 2 +- go/flags/endtoend/vtexplain.txt | 2 +- go/flags/endtoend/vtgate.txt | 2 +- go/flags/endtoend/vtgateclienttest.txt | 2 +- go/flags/endtoend/vttablet.txt | 2 +- go/flags/endtoend/vttestserver.txt | 2 +- .../collations/integration/collations_test.go | 2 +- go/mysql/config/config.go | 2 +- go/vt/servenv/buildinfo_test.go | 2 +- go/vt/vtgate/semantics/info_schema.go | 2 +- java/jdbc/pom.xml | 19 - .../io/vitess/jdbc/FieldWithMetadataTest.java | 96 +--- .../io/vitess/jdbc/VitessConnectionTest.java | 16 +- .../jdbc/VitessDatabaseMetadataTest.java | 455 +----------------- .../jdbc/VitessParameterMetaDataTest.java | 29 +- .../jdbc/VitessPreparedStatementTest.java | 217 ++++----- .../io/vitess/jdbc/VitessResultSetTest.java | 231 +-------- .../io/vitess/jdbc/VitessStatementTest.java | 329 ++++++------- test.go | 2 +- test/templates/dockerfile.tpl | 2 +- 43 files changed, 379 insertions(+), 1224 deletions(-) diff --git a/Makefile b/Makefile index 7eb3c9c1d8d..378b8708be6 100644 --- a/Makefile +++ b/Makefile @@ -286,7 +286,7 @@ $(PROTO_GO_OUTS): minimaltools install_protoc-gen-go proto/*.proto # This rule builds the bootstrap images for all flavors. DOCKER_IMAGES_FOR_TEST = mysql80 percona80 DOCKER_IMAGES = common $(DOCKER_IMAGES_FOR_TEST) -BOOTSTRAP_VERSION=40 +BOOTSTRAP_VERSION=41 ensure_bootstrap_version: find docker/ -type f -exec sed -i "s/^\(ARG bootstrap_version\)=.*/\1=${BOOTSTRAP_VERSION}/" {} \; sed -i 's/\(^.*flag.String(\"bootstrap-version\",\) *\"[^\"]\+\"/\1 \"${BOOTSTRAP_VERSION}\"/' test.go diff --git a/changelog/22.0/22.0.0/summary.md b/changelog/22.0/22.0.0/summary.md index 2fb66ea8969..f96679d4aa8 100644 --- a/changelog/22.0/22.0.0/summary.md +++ b/changelog/22.0/22.0.0/summary.md @@ -13,6 +13,8 @@ - **[Support for LAST_INSERT_ID(x)](#last-insert-id)** - **[Support for Maximum Idle Connections in the Pool](#max-idle-connections)** - **[Stalled Disk Recovery in VTOrc](#stall-disk-recovery)** + - **[Update default MySQL version to 8.0.40](#mysql-8-0-40)** + - **[Update lite images to Debian Bookworm](#debian-bookworm)** - **[Minor Changes](#minor-changes)** - **[VTTablet Flags](#flags-vttablet)** - **[Topology read concurrency behaviour changes](#topo-read-concurrency-changes)** @@ -106,6 +108,30 @@ VTOrc can now identify and recover from stalled disk errors. VTTablets test whet To opt into this feature, `--enable-primary-disk-stalled-recovery` flag has to be specified on VTOrc, and `--disk-write-dir` flag has to be specified on the vttablets. `--disk-write-interval` and `--disk-write-timeout` flags can be used to configure the polling interval and timeout respectively. +### Update default MySQL version to 8.0.40 + +The default major MySQL version used by our `vitess/lite:latest` image is going from `8.0.30` to `8.0.40`. +This change was brought by [Pull Request #17552](https://github.com/vitessio/vitess/pull/17552). + +VTGate also advertises MySQL version `8.0.40` by default instead of `8.0.30` if no explicit version is set. The users can set the `mysql_server_version` flag to advertise the correct version. + +#### ⚠️Upgrading to this release with vitess-operator + +If you are using the `vitess-operator`, considering that we are bumping the patch version of MySQL 80 from `8.0.30` to `8.0.40`, you will have to manually upgrade: + +1. Add `innodb_fast_shutdown=0` to your extra cnf in your YAML file. +2. Apply this file. +3. Wait for all the pods to be healthy. +4. Then change your YAML file to use the new Docker Images (`vitess/lite:v22.0.0`). +5. Remove `innodb_fast_shutdown=0` from your extra cnf in your YAML file. +6. Apply this file. + +This is the last time this will be needed in the `8.0.x` series, as starting with MySQL `8.0.35` it is possible to upgrade and downgrade between `8.0.x` versions without needing to run `innodb_fast_shutdown=0`. + +### Update lite images to Debian Bookworm + +The base system now uses Debian Bookworm instead of Debian Bullseye for the `vitess/lite` images. This change was brought by [Pull Request #17552]. + ## Minor Changes #### VTTablet Flags diff --git a/docker/binaries/vtadmin/Dockerfile b/docker/binaries/vtadmin/Dockerfile index fe69237ea13..b700f8ab74b 100644 --- a/docker/binaries/vtadmin/Dockerfile +++ b/docker/binaries/vtadmin/Dockerfile @@ -13,7 +13,7 @@ # limitations under the License. ARG VT_BASE_VER=latest -ARG DEBIAN_VER=bullseye-slim +ARG DEBIAN_VER=bookworm-slim FROM vitess/lite:${VT_BASE_VER} AS lite diff --git a/docker/bootstrap/CHANGELOG.md b/docker/bootstrap/CHANGELOG.md index 47b7d3a7c88..f2e66566a3c 100644 --- a/docker/bootstrap/CHANGELOG.md +++ b/docker/bootstrap/CHANGELOG.md @@ -157,4 +157,8 @@ List of changes between bootstrap image versions. ## [40] - 2025-01-17 ### Changes -- Update build to golang 1.23.5 \ No newline at end of file +- Update build to golang 1.23.5 + +## [41] - 2025-01-15 +### Changes +- Update base image to bookworm diff --git a/docker/bootstrap/Dockerfile.common b/docker/bootstrap/Dockerfile.common index f449f94ab16..e0866fe4bda 100644 --- a/docker/bootstrap/Dockerfile.common +++ b/docker/bootstrap/Dockerfile.common @@ -1,4 +1,4 @@ -FROM --platform=linux/amd64 golang:1.23.5-bullseye +FROM --platform=linux/amd64 golang:1.23.5-bookworm # Install Vitess build dependencies RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ @@ -8,12 +8,13 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins chromium \ curl \ default-jdk \ - etcd \ + etcd-client \ + etcd-server \ g++ \ git \ + gnupg \ make \ maven \ - software-properties-common \ unzip \ zip \ xvfb \ diff --git a/docker/bootstrap/Dockerfile.mysql80 b/docker/bootstrap/Dockerfile.mysql80 index b4fec6b7d11..e8ca365a704 100644 --- a/docker/bootstrap/Dockerfile.mysql80 +++ b/docker/bootstrap/Dockerfile.mysql80 @@ -8,9 +8,9 @@ USER root # Install MySQL 8.0 RUN for i in $(seq 1 10); do apt-key adv --no-tty --recv-keys --keyserver keyserver.ubuntu.com 8C718D3B5072E1F5 && break; done && \ for i in $(seq 1 10); do apt-key adv --no-tty --recv-keys --keyserver keyserver.ubuntu.com A8D3785C && break; done && \ - add-apt-repository 'deb http://repo.mysql.com/apt/debian/ bullseye mysql-8.0' && \ + echo 'deb http://repo.mysql.com/apt/debian/ bookworm mysql-8.0' > /etc/apt/sources.list.d/mysql.list && \ for i in $(seq 1 10); do apt-key adv --no-tty --keyserver keyserver.ubuntu.com --recv-keys 9334A25F8507EFA5 && break; done && \ - echo 'deb http://repo.percona.com/apt bullseye main' > /etc/apt/sources.list.d/percona.list && \ + echo 'deb http://repo.percona.com/apt bookworm main' > /etc/apt/sources.list.d/percona.list && \ { \ echo debconf debconf/frontend select Noninteractive; \ echo percona-server-server-8.0 percona-server-server/root_password password 'unused'; \ diff --git a/docker/bootstrap/Dockerfile.percona80 b/docker/bootstrap/Dockerfile.percona80 index 147b988b002..53b16a8eb4b 100644 --- a/docker/bootstrap/Dockerfile.percona80 +++ b/docker/bootstrap/Dockerfile.percona80 @@ -7,7 +7,7 @@ USER root # Install Percona 8.0 RUN for i in $(seq 1 10); do apt-key adv --no-tty --keyserver keyserver.ubuntu.com --recv-keys 9334A25F8507EFA5 && break; done \ - && echo 'deb http://repo.percona.com/ps-80/apt bullseye main' > /etc/apt/sources.list.d/percona.list && \ + && echo 'deb http://repo.percona.com/ps-80/apt bookworm main' > /etc/apt/sources.list.d/percona.list && \ { \ echo debconf debconf/frontend select Noninteractive; \ echo percona-server-server-8.0 percona-server-server/root_password password 'unused'; \ @@ -23,7 +23,7 @@ RUN for i in $(seq 1 10); do apt-key adv --no-tty --keyserver keyserver.ubuntu.c rsync \ libev4 \ # && rm -f /etc/apt/sources.list.d/percona.list \ - && echo 'deb http://repo.percona.com/apt bullseye main' > /etc/apt/sources.list.d/percona.list \ + && echo 'deb http://repo.percona.com/apt bookworm main' > /etc/apt/sources.list.d/percona.list \ # { \ # echo debconf debconf/frontend select Noninteractive; \ # echo percona-server-server-8.0 percona-server-server/root_password password 'unused'; \ diff --git a/docker/lite/Dockerfile b/docker/lite/Dockerfile index 231dbb0c8aa..c75a0a5ad4c 100644 --- a/docker/lite/Dockerfile +++ b/docker/lite/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=linux/amd64 golang:1.23.5-bullseye AS builder +FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder # Allows docker builds to set the BUILD_NUMBER ARG BUILD_NUMBER @@ -31,7 +31,7 @@ COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess RUN make install PREFIX=/vt/install # Start over and build the final image. -FROM --platform=linux/amd64 debian:bullseye-slim +FROM --platform=linux/amd64 debian:bookworm-slim # Install locale required for mysqlsh RUN apt-get update && apt-get install -y locales \ diff --git a/docker/lite/Dockerfile.percona80 b/docker/lite/Dockerfile.percona80 index 106d4a0da5f..16e1da78627 100644 --- a/docker/lite/Dockerfile.percona80 +++ b/docker/lite/Dockerfile.percona80 @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=linux/amd64 golang:1.23.5-bullseye AS builder +FROM --platform=linux/amd64 golang:1.23.5-bookworm AS builder # Allows docker builds to set the BUILD_NUMBER ARG BUILD_NUMBER @@ -31,7 +31,7 @@ COPY --chown=vitess:vitess . /vt/src/vitess.io/vitess RUN make install PREFIX=/vt/install # Start over and build the final image. -FROM --platform=linux/amd64 debian:bullseye-slim +FROM --platform=linux/amd64 debian:bookworm-slim # Install dependencies COPY docker/utils/install_dependencies.sh /vt/dist/install_dependencies.sh diff --git a/docker/utils/install_dependencies.sh b/docker/utils/install_dependencies.sh index 91e6e2b8c76..64810a78d77 100755 --- a/docker/utils/install_dependencies.sh +++ b/docker/utils/install_dependencies.sh @@ -71,66 +71,33 @@ apt-get install -y --no-install-recommends "${BASE_PACKAGES[@]}" # Packages specific to certain flavors. case "${FLAVOR}" in -mysql57) - if [ -z "$VERSION" ]; then - VERSION=5.7.31 - fi - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-5.7/m/mysql-community/libmysqlclient20_${VERSION}-1debian10_amd64.deb /tmp/libmysqlclient20_${VERSION}-1debian10_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-5.7/m/mysql-community/mysql-community-client_${VERSION}-1debian10_amd64.deb /tmp/mysql-community-client_${VERSION}-1debian10_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-5.7/m/mysql-community/mysql-client_${VERSION}-1debian10_amd64.deb /tmp/mysql-client_${VERSION}-1debian10_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-5.7/m/mysql-community/mysql-community-server_${VERSION}-1debian10_amd64.deb /tmp/mysql-community-server_${VERSION}-1debian10_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-5.7/m/mysql-community/mysql-server_${VERSION}-1debian10_amd64.deb /tmp/mysql-server_${VERSION}-1debian10_amd64.deb - PACKAGES=( - /tmp/libmysqlclient20_${VERSION}-1debian10_amd64.deb - /tmp/mysql-community-client_${VERSION}-1debian10_amd64.deb - /tmp/mysql-client_${VERSION}-1debian10_amd64.deb - /tmp/mysql-community-server_${VERSION}-1debian10_amd64.deb - /tmp/mysql-server_${VERSION}-1debian10_amd64.deb - mysql-shell - percona-xtrabackup-24 - ) - ;; mysql80) if [ -z "$VERSION" ]; then - VERSION=8.0.30 + VERSION=8.0.40 fi - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-common_${VERSION}-1debian11_amd64.deb /tmp/mysql-common_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/libmysqlclient21_${VERSION}-1debian11_amd64.deb /tmp/libmysqlclient21_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client-core_${VERSION}-1debian11_amd64.deb /tmp/mysql-community-client-core_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client-plugins_${VERSION}-1debian11_amd64.deb /tmp/mysql-community-client-plugins_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client_${VERSION}-1debian11_amd64.deb /tmp/mysql-community-client_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-client_${VERSION}-1debian11_amd64.deb /tmp/mysql-client_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-server-core_${VERSION}-1debian11_amd64.deb /tmp/mysql-community-server-core_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-server_${VERSION}-1debian11_amd64.deb /tmp/mysql-community-server_${VERSION}-1debian11_amd64.deb - do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-server_${VERSION}-1debian11_amd64.deb /tmp/mysql-server_${VERSION}-1debian11_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-common_${VERSION}-1debian12_amd64.deb /tmp/mysql-common_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/libmysqlclient21_${VERSION}-1debian12_amd64.deb /tmp/libmysqlclient21_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client-core_${VERSION}-1debian12_amd64.deb /tmp/mysql-community-client-core_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client-plugins_${VERSION}-1debian12_amd64.deb /tmp/mysql-community-client-plugins_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-client_${VERSION}-1debian12_amd64.deb /tmp/mysql-community-client_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-client_${VERSION}-1debian12_amd64.deb /tmp/mysql-client_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-server-core_${VERSION}-1debian12_amd64.deb /tmp/mysql-community-server-core_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-community-server_${VERSION}-1debian12_amd64.deb /tmp/mysql-community-server_${VERSION}-1debian12_amd64.deb + do_fetch https://repo.mysql.com/apt/debian/pool/mysql-8.0/m/mysql-community/mysql-server_${VERSION}-1debian12_amd64.deb /tmp/mysql-server_${VERSION}-1debian12_amd64.deb PACKAGES=( - /tmp/mysql-common_${VERSION}-1debian11_amd64.deb - /tmp/libmysqlclient21_${VERSION}-1debian11_amd64.deb - /tmp/mysql-community-client-core_${VERSION}-1debian11_amd64.deb - /tmp/mysql-community-client-plugins_${VERSION}-1debian11_amd64.deb - /tmp/mysql-community-client_${VERSION}-1debian11_amd64.deb - /tmp/mysql-client_${VERSION}-1debian11_amd64.deb - /tmp/mysql-community-server-core_${VERSION}-1debian11_amd64.deb - /tmp/mysql-community-server_${VERSION}-1debian11_amd64.deb - /tmp/mysql-server_${VERSION}-1debian11_amd64.deb + /tmp/mysql-common_${VERSION}-1debian12_amd64.deb + /tmp/libmysqlclient21_${VERSION}-1debian12_amd64.deb + /tmp/mysql-community-client-core_${VERSION}-1debian12_amd64.deb + /tmp/mysql-community-client-plugins_${VERSION}-1debian12_amd64.deb + /tmp/mysql-community-client_${VERSION}-1debian12_amd64.deb + /tmp/mysql-client_${VERSION}-1debian12_amd64.deb + /tmp/mysql-community-server-core_${VERSION}-1debian12_amd64.deb + /tmp/mysql-community-server_${VERSION}-1debian12_amd64.deb + /tmp/mysql-server_${VERSION}-1debian12_amd64.deb mysql-shell percona-xtrabackup-80 ) ;; -percona) - PACKAGES=( - libcurl3 - percona-server-server-5.6 - percona-xtrabackup - ) - ;; -percona57) - PACKAGES=( - libperconaserverclient20 - percona-server-server-5.7 - percona-xtrabackup-24 - ) - ;; percona80) PACKAGES=( libperconaserverclient21 @@ -155,39 +122,24 @@ add_apt_key 9334A25F8507EFA5 # Add extra apt repositories for MySQL. case "${FLAVOR}" in -mysql57) - echo 'deb http://repo.mysql.com/apt/debian/ buster mysql-5.7' > /etc/apt/sources.list.d/mysql.list - ;; mysql80) - echo 'deb http://repo.mysql.com/apt/debian/ bullseye mysql-8.0' > /etc/apt/sources.list.d/mysql.list + echo 'deb http://repo.mysql.com/apt/debian/ bookworm mysql-8.0' > /etc/apt/sources.list.d/mysql.list ;; esac # Add extra apt repositories for Percona Server and/or Percona XtraBackup. case "${FLAVOR}" in -mysql57) - echo 'deb http://repo.percona.com/apt buster main' > /etc/apt/sources.list.d/percona.list - ;; -mysql80|percona57) - echo 'deb http://repo.percona.com/apt bullseye main' > /etc/apt/sources.list.d/percona.list +mysql80) + echo 'deb http://repo.percona.com/apt bookworm main' > /etc/apt/sources.list.d/percona.list ;; percona80) - echo 'deb http://repo.percona.com/apt bullseye main' > /etc/apt/sources.list.d/percona.list - echo 'deb http://repo.percona.com/ps-80/apt bullseye main' > /etc/apt/sources.list.d/percona80.list + echo 'deb http://repo.percona.com/apt bookworm main' > /etc/apt/sources.list.d/percona.list + echo 'deb http://repo.percona.com/ps-80/apt bookworm main' > /etc/apt/sources.list.d/percona80.list ;; esac # Pre-fill values for installation prompts that are normally interactive. case "${FLAVOR}" in -percona57) - debconf-set-selections < min_sequence_id, for each query, a number is generated in [min_sequence_id, max_sequence_id) and attached to the end of the bind variables. - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --parallel int DMLs only: Number of threads executing the same query in parallel. Useful for simple load testing. (default 1) --pprof strings enable profiling --pprof-http enable pprof http endpoints diff --git a/go/flags/endtoend/vtcombo.txt b/go/flags/endtoend/vtcombo.txt index 76c8e894347..25deea04548 100644 --- a/go/flags/endtoend/vtcombo.txt +++ b/go/flags/endtoend/vtcombo.txt @@ -245,7 +245,7 @@ Flags: --mysql_server_ssl_key string Path to ssl key for mysql server plugin SSL --mysql_server_ssl_server_ca string path to server CA in PEM format, which will be combine with server cert, return full certificate chain to clients --mysql_server_tls_min_version string Configures the minimal TLS version negotiated when SSL is enabled. Defaults to TLSv1.2. Options: TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3. - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --mysql_server_write_timeout duration connection write timeout --mysql_slow_connect_warn_threshold duration Warn if it takes more than the given threshold for a mysql connection to establish --mysql_tcp_version string Select tcp, tcp4, or tcp6 to control the socket type. (default "tcp") diff --git a/go/flags/endtoend/vtctld.txt b/go/flags/endtoend/vtctld.txt index c84c5fadf5f..764c07a9d69 100644 --- a/go/flags/endtoend/vtctld.txt +++ b/go/flags/endtoend/vtctld.txt @@ -98,7 +98,7 @@ Flags: --log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800) --logtostderr log to standard error instead of files --max-stack-size int configure the maximum stack size in bytes (default 67108864) - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --onclose_timeout duration wait no more than this for OnClose handlers before stopping (default 10s) --onterm_timeout duration wait no more than this for OnTermSync handlers before stopping (default 10s) --opentsdb_uri string URI of opentsdb /api/put method diff --git a/go/flags/endtoend/vtctldclient.txt b/go/flags/endtoend/vtctldclient.txt index 5ff2a7b21da..bfa50a4d98c 100644 --- a/go/flags/endtoend/vtctldclient.txt +++ b/go/flags/endtoend/vtctldclient.txt @@ -134,7 +134,7 @@ Flags: --log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800) --logbuflevel int Buffer log messages logged at this level or lower (-1 means don't buffer; 0 means buffer INFO only; ...). Has limited applicability on non-prod platforms. --logtostderr log to standard error instead of files - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --purge_logs_interval duration how often try to remove old logs (default 1h0m0s) --security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only) --server string server to use for the connection (required) diff --git a/go/flags/endtoend/vtexplain.txt b/go/flags/endtoend/vtexplain.txt index fdd289e63c7..90013fe1b98 100644 --- a/go/flags/endtoend/vtexplain.txt +++ b/go/flags/endtoend/vtexplain.txt @@ -59,7 +59,7 @@ Flags: --log_err_stacks log stack traces for errors --log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800) --logtostderr log to standard error instead of files - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --normalize Whether to enable vtgate normalization --output-mode string Output in human-friendly text or json (default "text") --planner-version string Sets the default planner to use. Valid values are: Gen4, Gen4Greedy, Gen4Left2Right diff --git a/go/flags/endtoend/vtgate.txt b/go/flags/endtoend/vtgate.txt index fde17f89c49..bfecdd07288 100644 --- a/go/flags/endtoend/vtgate.txt +++ b/go/flags/endtoend/vtgate.txt @@ -157,7 +157,7 @@ Flags: --mysql_server_ssl_key string Path to ssl key for mysql server plugin SSL --mysql_server_ssl_server_ca string path to server CA in PEM format, which will be combine with server cert, return full certificate chain to clients --mysql_server_tls_min_version string Configures the minimal TLS version negotiated when SSL is enabled. Defaults to TLSv1.2. Options: TLSv1.0, TLSv1.1, TLSv1.2, TLSv1.3. - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --mysql_server_write_timeout duration connection write timeout --mysql_slow_connect_warn_threshold duration Warn if it takes more than the given threshold for a mysql connection to establish --mysql_tcp_version string Select tcp, tcp4, or tcp6 to control the socket type. (default "tcp") diff --git a/go/flags/endtoend/vtgateclienttest.txt b/go/flags/endtoend/vtgateclienttest.txt index 8a2f18b6b5a..d5b45e57b1e 100644 --- a/go/flags/endtoend/vtgateclienttest.txt +++ b/go/flags/endtoend/vtgateclienttest.txt @@ -53,7 +53,7 @@ Flags: --log_rotate_max_size uint size in bytes at which logs are rotated (glog.MaxSize) (default 1887436800) --logtostderr log to standard error instead of files --max-stack-size int configure the maximum stack size in bytes (default 67108864) - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --onclose_timeout duration wait no more than this for OnClose handlers before stopping (default 10s) --onterm_timeout duration wait no more than this for OnTermSync handlers before stopping (default 10s) --pid_file string If set, the process will write its pid to the named file, and delete it on graceful shutdown. diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt index 955823f7322..1532bf870e0 100644 --- a/go/flags/endtoend/vttablet.txt +++ b/go/flags/endtoend/vttablet.txt @@ -247,7 +247,7 @@ Flags: --mysql-shell-should-drain decide if we should drain while taking a backup or continue to serving traffic --mysql-shell-speedup-restore speed up restore by disabling redo logging and double write buffer during the restore process --mysql-shutdown-timeout duration timeout to use when MySQL is being shut down. (default 5m0s) - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init --mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions) --onclose_timeout duration wait no more than this for OnClose handlers before stopping (default 10s) diff --git a/go/flags/endtoend/vttestserver.txt b/go/flags/endtoend/vttestserver.txt index 042ffd37643..385b7194652 100644 --- a/go/flags/endtoend/vttestserver.txt +++ b/go/flags/endtoend/vttestserver.txt @@ -96,7 +96,7 @@ Flags: --mysql-shell-speedup-restore speed up restore by disabling redo logging and double write buffer during the restore process --mysql_bind_host string which host to bind vtgate mysql listener to (default "localhost") --mysql_only If this flag is set only mysql is initialized. The rest of the vitess components are not started. Also, the output specifies the mysql unix socket instead of the vtgate port. - --mysql_server_version string MySQL server version to advertise. (default "8.0.30-Vitess") + --mysql_server_version string MySQL server version to advertise. (default "8.0.40-Vitess") --mysqlctl_mycnf_template string template file to use for generating the my.cnf file during server init --mysqlctl_socket string socket file to use for remote mysqlctl actions (empty for local actions) --no_scatter when set to true, the planner will fail instead of producing a plan that includes scatter queries diff --git a/go/mysql/collations/integration/collations_test.go b/go/mysql/collations/integration/collations_test.go index 519f4560faf..c599eceaa2e 100644 --- a/go/mysql/collations/integration/collations_test.go +++ b/go/mysql/collations/integration/collations_test.go @@ -45,7 +45,7 @@ var collationEnv *collations.Environment func init() { // We require MySQL 8.0 collations for the comparisons in the tests - collationEnv = collations.NewEnvironment("8.0.30") + collationEnv = collations.NewEnvironment("8.0.40") } func getSQLQueries(t *testing.T, testfile string) []string { diff --git a/go/mysql/config/config.go b/go/mysql/config/config.go index 6070d0d6248..4f9a8b3a734 100644 --- a/go/mysql/config/config.go +++ b/go/mysql/config/config.go @@ -1,5 +1,5 @@ package config const DefaultSQLMode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION" -const DefaultMySQLVersion = "8.0.30" +const DefaultMySQLVersion = "8.0.40" const LegacyMySQLVersion = "5.7.31" diff --git a/go/vt/servenv/buildinfo_test.go b/go/vt/servenv/buildinfo_test.go index bc972df03ea..a4a63cdb560 100644 --- a/go/vt/servenv/buildinfo_test.go +++ b/go/vt/servenv/buildinfo_test.go @@ -45,7 +45,7 @@ func TestVersionString(t *testing.T) { assert.Equal(t, "Version: v1.2.3-SNAPSHOT (Jenkins build 422) (Git revision d54b87ca0be09b678bb4490060e8f23f890ddb92 branch 'gitBranch') built on time is now by user@host using 1.20.2 amiga/amd64", v.String()) - assert.Equal(t, "8.0.30-Vitess", v.MySQLVersion()) + assert.Equal(t, "8.0.40-Vitess", v.MySQLVersion()) } func TestBuildVersionStats(t *testing.T) { diff --git a/go/vt/vtgate/semantics/info_schema.go b/go/vt/vtgate/semantics/info_schema.go index 127f4a00960..b33a20620e4 100644 --- a/go/vt/vtgate/semantics/info_schema.go +++ b/go/vt/vtgate/semantics/info_schema.go @@ -699,7 +699,7 @@ func getInfoSchema57() map[string][]vindexes.Column { // getInfoSchema80 returns a map of all information_schema tables and their columns with types // To recreate this information from MySQL, you can run the test in info_schema_gen_test.go func getInfoSchema80() map[string][]vindexes.Column { - parser, err := sqlparser.New(sqlparser.Options{MySQLServerVersion: "8.0.30"}) + parser, err := sqlparser.New(sqlparser.Options{MySQLServerVersion: "8.0.40"}) if err != nil { panic(err) } diff --git a/java/jdbc/pom.xml b/java/jdbc/pom.xml index dd554e64501..a52048576a1 100644 --- a/java/jdbc/pom.xml +++ b/java/jdbc/pom.xml @@ -57,25 +57,6 @@ 3.12.4 test - - - org.powermock - powermock-api-mockito2 - 2.0.9 - test - - - org.powermock - powermock-core - 2.0.9 - test - - - org.powermock - powermock-module-junit4 - 2.0.9 - test - diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/FieldWithMetadataTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/FieldWithMetadataTest.java index 318bf44d328..d02dd416d05 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/FieldWithMetadataTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/FieldWithMetadataTest.java @@ -28,15 +28,7 @@ import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.internal.verification.VerificationModeFactory; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@PrepareForTest(FieldWithMetadata.class) -@RunWith(PowerMockRunner.class) + public class FieldWithMetadataTest extends BaseTest { @Test @@ -492,92 +484,6 @@ public void testToString() throws SQLException { Assert.assertEquals(result, field.toString()); } - public void testCollations() throws Exception { - VitessConnection conn = getVitessConnection(); - - Query.Field raw = Query.Field.newBuilder().setTable("foo").setType(Query.Type.CHAR) - .setName("foo").setOrgName("foo").setCharset(33).build(); - - FieldWithMetadata fieldWithMetadata = PowerMockito.spy(new FieldWithMetadata(conn, raw)); - String first = fieldWithMetadata.getCollation(); - String second = fieldWithMetadata.getCollation(); - - Assert.assertEquals("utf8_general_ci", first); - Assert.assertEquals("cached response is same as first", first, second); - - PowerMockito.verifyPrivate(fieldWithMetadata, VerificationModeFactory.times(1)) - .invoke("getCollationIndex"); - - try { - raw = raw.toBuilder() - // value chosen because it's obviously out of bounds for the underlying array - .setCharset(Integer.MAX_VALUE).build(); - - fieldWithMetadata = PowerMockito.spy(new FieldWithMetadata(conn, raw)); - fieldWithMetadata.getCollation(); - Assert.fail("Should have received an array index out of bounds because " - + "charset/collationIndex of Int.MAX is well above size of charset array"); - } catch (SQLException e) { - if (e.getCause() instanceof ArrayIndexOutOfBoundsException) { - Assert.assertEquals("CollationIndex '" + Integer.MAX_VALUE + "' out of bounds for " - + "collationName lookup, should be within 0 and " - + CharsetMapping.COLLATION_INDEX_TO_COLLATION_NAME.length, e.getMessage()); - } else { - // just rethrow so we fail that way - throw e; - } - } - - PowerMockito.verifyPrivate(fieldWithMetadata, VerificationModeFactory.times(1)) - .invoke("getCollationIndex"); - //Mockito.verify(fieldWithMetadata, Mockito.times(1)).getCollationIndex(); - - conn.setIncludedFields(Query.ExecuteOptions.IncludedFields.TYPE_AND_NAME); - fieldWithMetadata = PowerMockito.spy(new FieldWithMetadata(conn, raw)); - Assert.assertEquals("null response when not including all fields", null, - fieldWithMetadata.getCollation()); - - // We should not call this at all, because we're short circuiting due to included fields - //Mockito.verify(fieldWithMetadata, Mockito.never()).getCollationIndex(); - PowerMockito.verifyPrivate(fieldWithMetadata, VerificationModeFactory.times(0)) - .invoke("getCollationIndex"); - } - - @Test - public void testMaxBytesPerChar() throws Exception { - VitessConnection conn = PowerMockito.spy(getVitessConnection()); - - Query.Field raw = Query.Field.newBuilder().setTable("foo").setType(Query.Type.CHAR) - .setName("foo").setOrgName("foo").setCharset(33).build(); - - FieldWithMetadata fieldWithMetadata = PowerMockito.spy(new FieldWithMetadata(conn, raw)); - - int first = fieldWithMetadata.getMaxBytesPerCharacter(); - int second = fieldWithMetadata.getMaxBytesPerCharacter(); - - Assert.assertEquals("cached response is same as first", first, second); - // We called getMaxBytesPerCharacter 2 times above, but should only have made 1 call to - // fieldWithMetadata.getMaxBytesPerChar: - // first - call conn - // second - return cached - Mockito.verify(fieldWithMetadata, VerificationModeFactory.times(1)) - .getMaxBytesPerChar(33, "UTF-8"); - PowerMockito.verifyPrivate(fieldWithMetadata, VerificationModeFactory.times(1)) - .invoke("getCollationIndex"); - - conn.setIncludedFields(Query.ExecuteOptions.IncludedFields.TYPE_AND_NAME); - fieldWithMetadata = PowerMockito.spy(new FieldWithMetadata(conn, raw)); - Assert.assertEquals("0 return value when not including all fields", 0, - fieldWithMetadata.getMaxBytesPerCharacter()); - - // We should not call this function because we short circuited due to not including all fields. - Mockito.verify(fieldWithMetadata, VerificationModeFactory.times(0)) - .getMaxBytesPerChar(33, "UTF-8"); - // Should not be called at all, because it's new for just this test - PowerMockito.verifyPrivate(fieldWithMetadata, VerificationModeFactory.times(0)) - .invoke("getCollationIndex"); - } - @Test public void testGetEncodingForIndex() throws SQLException { Query.Field raw = Query.Field.newBuilder().setTable("foo").setType(Query.Type.CHAR) diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessConnectionTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessConnectionTest.java index 415790ed3f4..e10c97c8636 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessConnectionTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessConnectionTest.java @@ -40,15 +40,11 @@ import java.util.Properties; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; /** * Created by harshit.gangal on 19/01/16. */ -@RunWith(PowerMockRunner.class) public class VitessConnectionTest extends BaseTest { @Test @@ -118,13 +114,13 @@ public void testDefaultSetAutoCommitForClose() throws SQLException { @Test public void testCommit() throws Exception { - VTSession mockSession = PowerMockito.mock(VTSession.class); + VTSession mockSession = Mockito.mock(VTSession.class); VitessConnection vitessConnection = getVitessConnection(); Field privateVTSessionField = VitessConnection.class.getDeclaredField("vtSession"); privateVTSessionField.setAccessible(true); privateVTSessionField.set(vitessConnection, mockSession); - PowerMockito.when(mockSession.isInTransaction()).thenReturn(false); - PowerMockito.when(mockSession.isAutoCommit()).thenReturn(false); + Mockito.when(mockSession.isInTransaction()).thenReturn(false); + Mockito.when(mockSession.isAutoCommit()).thenReturn(false); vitessConnection.commit(); } @@ -159,13 +155,13 @@ public void testClosed() throws SQLException { @Test(expected = SQLException.class) public void testClosedForException() throws Exception { - VTSession mockSession = PowerMockito.mock(VTSession.class); + VTSession mockSession = Mockito.mock(VTSession.class); VitessConnection vitessConnection = getVitessConnection(); Field privateVTSessionField = VitessConnection.class.getDeclaredField("vtSession"); privateVTSessionField.setAccessible(true); privateVTSessionField.set(vitessConnection, mockSession); - PowerMockito.when(mockSession.isInTransaction()).thenReturn(true); - PowerMockito.when(mockSession.isAutoCommit()).thenReturn(true); + Mockito.when(mockSession.isInTransaction()).thenReturn(true); + Mockito.when(mockSession.isAutoCommit()).thenReturn(true); vitessConnection.close(); } diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessDatabaseMetadataTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessDatabaseMetadataTest.java index 92d5cfede9b..e1e50e8a6e6 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessDatabaseMetadataTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessDatabaseMetadataTest.java @@ -19,37 +19,26 @@ import com.google.common.base.Charsets; import com.google.common.io.CharStreams; import com.google.protobuf.ByteString; - import io.vitess.client.cursor.Cursor; import io.vitess.client.cursor.SimpleCursor; import io.vitess.proto.Query; import io.vitess.util.Constants; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Types; +import java.sql.*; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Scanner; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - /** * Created by ashudeep.sharma on 08/03/16. */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({VitessMySQLDatabaseMetadata.class, VitessConnection.class}) public class VitessDatabaseMetadataTest extends BaseTest { private ResultSet resultSet; @@ -860,19 +849,19 @@ public void autoCommitFailureClosesAllResultSetsTest() throws SQLException { @Test public void getUrlTest() throws SQLException { String connectionUrl = "jdbc:vitess://://"; - VitessJDBCUrl mockUrl = PowerMockito.mock(VitessJDBCUrl.class); - PowerMockito.when(mockUrl.getUrl()).thenReturn(connectionUrl); + VitessJDBCUrl mockUrl = Mockito.mock(VitessJDBCUrl.class); + Mockito.when(mockUrl.getUrl()).thenReturn(connectionUrl); - VitessConnection mockConn = PowerMockito.mock(VitessConnection.class); - PowerMockito.when(mockConn.getUrl()).thenReturn(mockUrl); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + Mockito.when(mockConn.getUrl()).thenReturn(mockUrl); Assert.assertEquals(connectionUrl, mockConn.getUrl().getUrl()); } @Test public void isReadOnlyTest() throws SQLException { - VitessConnection mockConn = PowerMockito.mock(VitessConnection.class); - PowerMockito.when(mockConn.isReadOnly()).thenReturn(false); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + Mockito.when(mockConn.isReadOnly()).thenReturn(false); Assert.assertEquals(false, mockConn.isReadOnly()); } @@ -1022,74 +1011,6 @@ public void supportsStatementPooling() throws SQLException { Assert.assertEquals(false, vitessMariaDBDatabaseMetadata.supportsStatementPooling()); } - @Test - public void getCatalogsTest() throws SQLException, Exception { - String sql = "SHOW DATABASES"; - Cursor mockedCursor = new SimpleCursor(Query.QueryResult.newBuilder().addFields( - Query.Field.newBuilder().setName("TABLE_CAT").setType(Query.Type.VARCHAR).build()).addRows( - Query.Row.newBuilder().addLengths("vitessDB".length()) - .setValues(ByteString.copyFromUtf8("vitessDB"))).addRows( - Query.Row.newBuilder().addLengths("sampleDB".length()) - .setValues(ByteString.copyFromUtf8("sampleDB"))).addRows( - Query.Row.newBuilder().addLengths("testDB".length()) - .setValues(ByteString.copyFromUtf8("testDB"))).addRows( - Query.Row.newBuilder().addLengths("dummyDB".length()) - .setValues(ByteString.copyFromUtf8("dummyDB"))).build()); - - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(mockedCursor)); - - VitessDatabaseMetaData vitessDatabaseMetaData = new VitessMySQLDatabaseMetadata(null); - ResultSet resultSet = vitessDatabaseMetaData.getCatalogs(); - ArrayList resultSetList = new ArrayList(); - while (resultSet.next()) { - resultSetList.add(resultSet.getString(1)); - } - Assert.assertEquals("dummyDB", resultSetList.get(0)); - Assert.assertEquals("sampleDB", resultSetList.get(1)); - Assert.assertEquals("testDB", resultSetList.get(2)); - Assert.assertEquals("vitessDB", resultSetList.get(3)); - } - - @Test - public void getTablesTest() throws SQLException, Exception { - - String sql = "SHOW FULL TABLES FROM `vt` LIKE '%'"; - Cursor mockedCursor = getTablesCursor(); - - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(mockedCursor)); - - VitessDatabaseMetaData vitessDatabaseMetaData = new VitessMySQLDatabaseMetadata( - getVitessConnection()); - ResultSet actualResultSet = vitessDatabaseMetaData.getTables("vt", null, null, null); - ResultSet expectedResultSet = new VitessResultSet(mockedCursor); - - assertResultSetEquals(actualResultSet, expectedResultSet); - } - - @Test - public void getTablesProperResultTypeTest() throws SQLException, Exception { - - String sql = "SHOW FULL TABLES FROM `vt` LIKE '%'"; - Cursor mockedCursor = getTablesCursor(); - - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(mockedCursor)); - - VitessDatabaseMetaData vitessDatabaseMetaData = new VitessMySQLDatabaseMetadata( - getVitessConnection()); - ResultSet actualResultSet = vitessDatabaseMetaData.getTables("vt", null, null, null); - actualResultSet.next(); - Assert.assertEquals(String.class, actualResultSet.getObject("TABLE_CAT").getClass()); - } - private Cursor getTablesCursor() throws Exception { return new SimpleCursor(Query.QueryResult.newBuilder() .addFields(Query.Field.newBuilder().setName("TABLE_CAT").setType(Query.Type.VARCHAR)) @@ -1131,231 +1052,6 @@ private Cursor getTablesCursor() throws Exception { .build()); } - @Test - public void getColumnsTest() throws SQLException, Exception { - - String sql = "SHOW FULL COLUMNS FROM `sampleTable1` FROM `TestDB1` LIKE '%'"; - Cursor mockedTablecursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("TABLE_CAT").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_SCHEM").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_NAME").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_TYPE").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("REMARKS").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("TYPE_CAT").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("TYPE_SCHEM").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("TYPE_NAME").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("SELF_REFERENCING_COL_NAME") - .setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("REF_GENERATION").setType(Query.Type.VARCHAR)) - .addRows(Query.Row.newBuilder().addLengths("TestDB1".length()).addLengths("".length()) - .addLengths("sampleTable1".length()).addLengths("TABLE".length()) - .addLengths("".length()).addLengths("".length()).addLengths("".length()) - .addLengths("".length()).addLengths("".length()).addLengths("".length()) - .setValues(ByteString.copyFromUtf8("TestDB1sampleTable1TABLE"))).build()); - - Cursor actualCursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("Field").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Type").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Collation").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Null").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Key").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Default").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Extra").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Privileges").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Comment").setType(Query.Type.VARCHAR)).addRows( - Query.Row.newBuilder().addLengths("shipmentid".length()).addLengths("bigint".length()) - .addLengths("NULL".length()).addLengths("NO".length()).addLengths("PRI".length()) - .addLengths("NULL".length()).addLengths("".length()) - .addLengths("select,insert,update,references".length()).addLengths("".length()) - .setValues(ByteString - .copyFromUtf8("shipmentidbigintNULLNOPRINULLselect,insert,update,references"))) - .addRows( - Query.Row.newBuilder().addLengths("trackingid".length()).addLengths("varchar".length()) - .addLengths("utf8_general_ci".length()).addLengths("YES".length()) - .addLengths("".length()).addLengths("NULL".length()).addLengths("".length()) - .addLengths("select,insert,update,references".length()).addLengths("".length()) - .setValues(ByteString.copyFromUtf8( - "trackingidvarcharutf8_general_ciYESNULLselect,insert,update,references"))) - .build()); - Cursor expectedCursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("TABLE_CAT").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_SCHEM").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("COLUMN_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("DATA_TYPE").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("TYPE_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("COLUMN_SIZE").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("BUFFER_LENGTH").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("DECIMAL_DIGITS").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("NUM_PREC_RADIX").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("NULLABLE").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("REMARKS").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("COLUMN_DEF").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("SQL_DATA_TYPE").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("SQL_DATETIME_SUB").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("CHAR_OCTET_LENGTH").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("ORDINAL_POSITION").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("ISNULLABLE").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("SCOPE_CATALOG").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("SCOPE_SCHEMA").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("SCOPE_TABLE").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("SOURCE_DATA_TYPE").setType(Query.Type.INT16)) - .addFields(Query.Field.newBuilder().setName("IS_AUTOINCREMENT").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("IS_GENERATEDCOLUMN").setType(Query.Type.CHAR)) - .addRows(Query.Row.newBuilder().addLengths("TestDB1".length()).addLengths(-1) - .addLengths("sampleTable1".length()).addLengths("shipmentid".length()) - .addLengths("-5".length()).addLengths("BIGINT".length()).addLengths("19".length()) - .addLengths("65535".length()).addLengths("0".length()).addLengths("10".length()) - .addLengths("0".length()).addLengths("Comment".length()).addLengths("NULL".length()) - .addLengths("0".length()).addLengths("0".length()).addLengths("0".length()) - .addLengths("1".length()).addLengths("NO".length()).addLengths(-1).addLengths(-1) - .addLengths(-1).addLengths(-1).addLengths("NO".length()).addLengths("NO".length()) - .setValues(ByteString.copyFromUtf8( - "TestDB1sampleTable1shipmentid-5BIGINT19655350100CommentNULL0001NONONO"))).addRows( - Query.Row.newBuilder().addLengths("TestDB1".length()).addLengths(-1) - .addLengths("sampleTable1".length()).addLengths("trackingid".length()) - .addLengths("12".length()).addLengths("VARCHAR".length()).addLengths("255".length()) - .addLengths("65535".length()).addLengths(-1).addLengths("10".length()) - .addLengths("1".length()).addLengths("Comment".length()).addLengths("NULL".length()) - .addLengths("0".length()).addLengths("0".length()).addLengths("255".length()) - .addLengths("2".length()).addLengths("YES".length()).addLengths(-1).addLengths(-1) - .addLengths(-1).addLengths(-1).addLengths("NO".length()).addLengths("NO".length()) - .setValues(ByteString.copyFromUtf8( - "TestDB1sampleTable1trackingid12VARCHAR25565535101CommentNULL002552YESNONO"))) - .build()); - - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(actualCursor)); - - VitessDatabaseMetaData vitessDatabaseMetaData = PowerMockito - .mock(VitessMySQLDatabaseMetadata.class); - PowerMockito.doCallRealMethod().when(vitessDatabaseMetaData) - .getColumns("TestDB1", null, null, null); - PowerMockito.when(vitessDatabaseMetaData.getTables("TestDB1", null, "%", new String[0])) - .thenReturn(new VitessResultSet(mockedTablecursor)); - ResultSet actualResultSet = vitessDatabaseMetaData.getColumns("TestDB1", null, null, null); - ResultSet expectedResultSet = new VitessResultSet(expectedCursor); - - assertResultSetEquals(actualResultSet, expectedResultSet); - } - - @Test - public void getPrimaryKeysTest() throws SQLException, Exception { - - String sql = "SHOW KEYS FROM `shipment` FROM `vt`"; - Cursor mockedCursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("TABLE").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Non_unique").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Key_name").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Seq_in_index").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Column_name").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Collation").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Cardinality").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Sub_part").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Packed").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Null").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Index_type").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Comment").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Index_comment").setType(Query.Type.VARCHAR)) - .addRows(Query.Row.newBuilder().addLengths("shipment".length()).addLengths("0".length()) - .addLengths("PRIMARY".length()).addLengths("1".length()) - .addLengths("shipmentid".length()).addLengths("A".length()) - .addLengths("434880".length()).addLengths(-1).addLengths(-1).addLengths("".length()) - .addLengths("BTREE".length()).addLengths("".length()).addLengths("".length()) - .setValues(ByteString.copyFromUtf8("shipment0PRIMARY1shipmentidA434880BTREE"))) - .build()); - Cursor expectedcursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("TABLE_CAT").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_SCHEM").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("COLUMN_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("KEY_SEQ").setType(Query.Type.INT16)) - .addFields(Query.Field.newBuilder().setName("PK_NAME").setType(Query.Type.CHAR)).addRows( - Query.Row.newBuilder().addLengths("vt".length()).addLengths(-1) - .addLengths("shipment".length()).addLengths("shipmentid".length()) - .addLengths("1".length()).addLengths("PRIMARY".length()) - .setValues(ByteString.copyFromUtf8("vtshipmentshipmentid1PRIMARY"))).build()); - - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - VitessDatabaseMetaData vitessDatabaseMetaData = PowerMockito - .mock(VitessMySQLDatabaseMetadata.class); - PowerMockito.mock(VitessMySQLDatabaseMetadata.class); - PowerMockito.doCallRealMethod().when(vitessDatabaseMetaData) - .getPrimaryKeys("vt", null, "shipment"); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(mockedCursor)); - ResultSet expectedResultSet = vitessDatabaseMetaData.getPrimaryKeys("vt", null, "shipment"); - ResultSet actualResultSet = new VitessResultSet(expectedcursor); - - assertResultSetEquals(actualResultSet, expectedResultSet); - } - - @Test - public void getIndexInfoTest() throws SQLException, Exception { - - String sql = "SHOW INDEX FROM `shipment` FROM `vt`"; - Cursor mockedCursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("Table").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Non_unique").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Key_name").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Seq_in_index").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Column_name").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Collation").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Cardinality").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Sub_part").setType(Query.Type.INT64)) - .addFields(Query.Field.newBuilder().setName("Packed").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Null").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Index_type").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Comment").setType(Query.Type.VARCHAR)) - .addFields(Query.Field.newBuilder().setName("Index_comment").setType(Query.Type.VARCHAR)) - .addRows(Query.Row.newBuilder().addLengths("shipment".length()).addLengths("0".length()) - .addLengths("PRIMARY".length()).addLengths("1".length()) - .addLengths("shipmentid".length()).addLengths("A".length()) - .addLengths("434880".length()).addLengths(-1).addLengths(-1).addLengths("".length()) - .addLengths("BTREE".length()).addLengths("".length()).addLengths("".length()) - .setValues(ByteString.copyFromUtf8("shipment0PRIMARY1shipmentidA434880BTREE"))) - .build()); - - Cursor expectedcursor = new SimpleCursor(Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("TABLE_CAT").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_SCHEM").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TABLE_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("Non_unique").setType(Query.Type.BIT)) - .addFields(Query.Field.newBuilder().setName("INDEX_QUALIFIER").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("INDEX_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("TYPE").setType(Query.Type.INT16)) - .addFields(Query.Field.newBuilder().setName("ORDINAL_POSITION").setType(Query.Type.INT16)) - .addFields(Query.Field.newBuilder().setName("COLUMN_NAME").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("ASC_OR_DESC").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("CARDINALITY").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("PAGES").setType(Query.Type.INT32)) - .addFields(Query.Field.newBuilder().setName("FILTER_CONDITION").setType(Query.Type.CHAR)) - .addRows(Query.Row.newBuilder().addLengths("vt".length()).addLengths(-1) - .addLengths("shipment".length()).addLengths("false".length()).addLengths("".length()) - .addLengths("PRIMARY".length()).addLengths("3".length()).addLengths("1".length()) - .addLengths("shipmentid".length()).addLengths("A".length()) - .addLengths("434880".length()).addLengths("0".length()).addLengths(-1) - .setValues(ByteString.copyFromUtf8("vtshipmentfalsePRIMARY31shipmentidA4348800"))) - .build()); - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - VitessDatabaseMetaData vitessDatabaseMetaData = PowerMockito - .mock(VitessMySQLDatabaseMetadata.class); - PowerMockito.mock(VitessMySQLDatabaseMetadata.class); - PowerMockito.doCallRealMethod().when(vitessDatabaseMetaData) - .getIndexInfo("vt", null, "shipment", true, false); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(mockedCursor)); - ResultSet actualResultSet = vitessDatabaseMetaData - .getIndexInfo("vt", null, "shipment", true, false); - ResultSet expectedResultSet = new VitessResultSet(expectedcursor); - - assertResultSetEquals(actualResultSet, expectedResultSet); - } - private void assertResultSetEquals(ResultSet actualResultSet, ResultSet expectedResultSet) throws SQLException { ResultSetMetaData actualResultSetMetadata = actualResultSet.getMetaData(); @@ -1440,137 +1136,6 @@ public void getUserNameTest() { } } - @Test - public void testCaseSensitivityIdentifierFuncsMySql() throws Exception { - assertCaseSensitivityForDatabaseType(false); - } - - @Test - public void testCaseSensitivityIdentifierFuncsMariaDb() throws Exception { - assertCaseSensitivityForDatabaseType(true); - } - - private void assertCaseSensitivityForDatabaseType(boolean useMariaDb) throws Exception { - VitessConnection connection = new VitessConnection("jdbc:vitess://username@ip1:port1/keyspace", - null); - mockStatementForLowercaseTablesValue("0", useMariaDb); - Assert.assertEquals(true, connection.getMetaData().supportsMixedCaseIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().supportsMixedCaseQuotedIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesLowerCaseIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesMixedCaseIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesLowerCaseQuotedIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesMixedCaseQuotedIdentifiers()); - connection.close(); - - connection = new VitessConnection("jdbc:vitess://username@ip1:port1/keyspace", null); - mockStatementForLowercaseTablesValue("1", useMariaDb); - Assert.assertEquals(false, connection.getMetaData().supportsMixedCaseIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().supportsMixedCaseQuotedIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesLowerCaseIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesMixedCaseIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesLowerCaseQuotedIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesMixedCaseQuotedIdentifiers()); - connection.close(); - - connection = new VitessConnection("jdbc:vitess://username@ip1:port1/keyspace", null); - mockStatementForLowercaseTablesValue("2", useMariaDb); - Assert.assertEquals(false, connection.getMetaData().supportsMixedCaseIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().supportsMixedCaseQuotedIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesLowerCaseIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesMixedCaseIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesLowerCaseQuotedIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesMixedCaseQuotedIdentifiers()); - connection.close(); - - connection = new VitessConnection("jdbc:vitess://username@ip1:port1/keyspace", null); - mockStatementForLowercaseTablesValue("something random", useMariaDb); - Assert.assertEquals(true, connection.getMetaData().supportsMixedCaseIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().supportsMixedCaseQuotedIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesLowerCaseIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesMixedCaseIdentifiers()); - Assert.assertEquals(false, connection.getMetaData().storesLowerCaseQuotedIdentifiers()); - Assert.assertEquals(true, connection.getMetaData().storesMixedCaseQuotedIdentifiers()); - connection.close(); - } - - private void mockStatementForLowercaseTablesValue(String lcTablesValue, boolean useMariaDb) - throws Exception { - String sql = "SHOW VARIABLES WHERE VARIABLE_NAME IN (\'tx_isolation\',\'INNODB_VERSION\', " - + "\'lower_case_table_names\')"; - String versionName = "innodb_version"; - String versionValue = "5.7.16-10"; - if (useMariaDb) { - versionValue = versionValue + "-mariadb"; - } - String txIsoName = "tx_isolation"; - String txIsoValue = "REPEATABLE-READ"; - String lcTablesName = "lower_case_table_names"; - - Cursor mockedCursor = new SimpleCursor(Query.QueryResult.newBuilder().addFields( - Query.Field.newBuilder().setName("Variable_name").setType(Query.Type.VARCHAR).build()) - .addFields(Query.Field.newBuilder().setName("Value").setType(Query.Type.VARCHAR).build()) - .addRows(Query.Row.newBuilder().addLengths(versionName.length()) - .addLengths(versionValue.length()) - .setValues(ByteString.copyFromUtf8(versionName + versionValue))).addRows( - Query.Row.newBuilder().addLengths(txIsoName.length()).addLengths(txIsoValue.length()) - .setValues(ByteString.copyFromUtf8(txIsoName + txIsoValue))).addRows( - Query.Row.newBuilder().addLengths(lcTablesName.length()) - .addLengths(lcTablesValue.length()) - .setValues(ByteString.copyFromUtf8(lcTablesName + lcTablesValue))).build()); - - VitessStatement vitessStatement = PowerMockito.mock(VitessStatement.class); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.when(vitessStatement.executeQuery(sql)) - .thenReturn(new VitessResultSet(mockedCursor)); - } - - /** - * Tests that we're properly stitching together the results of SHOW CREATE TABLE. See {@link - * #extractForeignKeyForTableTest()} for more thorough testing of the actual parsing - */ - @Test - public void getImportedKeysTest() throws Exception { - try (InputStream resourceAsStream = this.getClass() - .getResourceAsStream("/getImportedKeysTestCase.sql")) { - String table = "testA"; - String showCreate = CharStreams - .toString(new InputStreamReader(resourceAsStream, Charsets.UTF_8)); - - Query.QueryResult queryResult = Query.QueryResult.newBuilder() - .addFields(Query.Field.newBuilder().setName("Table").setType(Query.Type.CHAR)) - .addFields(Query.Field.newBuilder().setName("Create Table").setType(Query.Type.CHAR)) - .addRows(Query.Row.newBuilder().addLengths(table.length()).addLengths(showCreate.length()) - .setValues(ByteString.copyFromUtf8(table + showCreate))).build(); - - String sql = "SHOW CREATE TABLE `testA`"; - VitessConnection vitessConnection = new VitessConnection( - "jdbc:vitess://username@ip1:port1/keyspace", null); - VitessStatement vitessStatement = PowerMockito.spy(new VitessStatement(vitessConnection)); - PowerMockito.whenNew(VitessStatement.class).withAnyArguments().thenReturn(vitessStatement); - PowerMockito.doReturn(new VitessResultSet(new SimpleCursor(queryResult), vitessStatement)) - .when(vitessStatement).executeQuery(sql); - - VitessDatabaseMetaData vitessDatabaseMetaData = new VitessMySQLDatabaseMetadata( - vitessConnection); - ResultSet importedKeys = vitessDatabaseMetaData.getImportedKeys("test", "test", "testA"); - importedKeys.next(); - Assert.assertEquals("test", importedKeys.getString("PKTABLE_CAT")); - Assert.assertEquals(null, importedKeys.getString("PKTABLE_SCHEM")); - Assert.assertEquals("fTable", importedKeys.getString("PKTABLE_NAME")); - Assert.assertEquals("id", importedKeys.getString("PKCOLUMN_NAME")); - Assert.assertEquals("test", importedKeys.getString("FKTABLE_CAT")); - Assert.assertEquals(null, importedKeys.getString("FKTABLE_SCHEM")); - Assert.assertEquals("testA", importedKeys.getString("FKTABLE_NAME")); - Assert.assertEquals("fIdOne", importedKeys.getString("FKCOLUMN_NAME")); - Assert.assertEquals(1, importedKeys.getInt("KEY_SEQ")); - Assert.assertEquals(3, importedKeys.getInt("UPDATE_RULE")); - Assert.assertEquals(3, importedKeys.getInt("DELETE_RULE")); - Assert.assertEquals("fk_testA", importedKeys.getString("FK_NAME")); - Assert.assertEquals(null, importedKeys.getString("PK_NAME")); - Assert.assertEquals(7, importedKeys.getInt("DEFERRABILITY")); - } - } - /** * Tests parsing all the various outputs of SHOW CREATE TABLE for the foreign key constraints. */ diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessParameterMetaDataTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessParameterMetaDataTest.java index 8916063ffaf..890212d5071 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessParameterMetaDataTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessParameterMetaDataTest.java @@ -16,20 +16,13 @@ package io.vitess.jdbc; +import org.junit.Assert; +import org.junit.Test; + import java.sql.ParameterMetaData; import java.sql.SQLException; import java.sql.Types; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.internal.verification.VerificationModeFactory; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(VitessParameterMetaData.class) public class VitessParameterMetaDataTest { @Test @@ -70,22 +63,6 @@ public void testOutOfBoundsValidation() { } } - @Test - public void testOutOfBoundCoverage() throws Exception { - int param = 2; - VitessParameterMetaData metaData = PowerMockito.spy(new VitessParameterMetaData(5)); - - metaData.getParameterType(param); - metaData.getPrecision(param); - metaData.getScale(param); - metaData.getParameterClassName(param); - metaData.getParameterTypeName(param); - metaData.isSigned(param); - - PowerMockito.verifyPrivate(metaData, VerificationModeFactory.times(6)) - .invoke("checkBounds", param); - } - @Test(expected = SQLException.class) public void testNullableNotAvailable() throws SQLException { VitessParameterMetaData metaData = new VitessParameterMetaData(5); diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessPreparedStatementTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessPreparedStatementTest.java index c5a9b4cbd33..2ebadf371ec 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessPreparedStatementTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessPreparedStatementTest.java @@ -18,12 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.nullable; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; import com.google.common.collect.ImmutableMap; @@ -59,19 +54,13 @@ import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Matchers; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * Created by harshit.gangal on 09/02/16. */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({VTGateConnection.class, Vtrpc.RPCError.class}) public class VitessPreparedStatementTest { private String sqlSelect = "select 1 from test_table"; @@ -81,7 +70,7 @@ public class VitessPreparedStatementTest { @Test public void testStatementExecute() { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessPreparedStatement preparedStatement; try { preparedStatement = new VitessPreparedStatement(mockConn, sqlShow); @@ -110,17 +99,17 @@ public void testStatementExecute() { @Test public void testExecuteQuery() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))). + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))). thenReturn(mockSqlFutureCursor); - when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); - when(mockConn.isSimpleExecute()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); VitessPreparedStatement preparedStatement; try { @@ -156,7 +145,7 @@ public void testExecuteQuery() throws SQLException { try { //when returned cursor is null - when(mockSqlFutureCursor.checkedGet()).thenReturn(null); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(null); preparedStatement.executeQuery(); fail("Should have thrown exception for cursor null"); } catch (SQLException ex) { @@ -170,19 +159,19 @@ public void testExecuteQuery() throws SQLException { @Test public void testExecuteQueryWithStream() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn .streamExecute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockCursor); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.STREAM); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.STREAM); VitessPreparedStatement preparedStatement; try { @@ -218,7 +207,7 @@ public void testExecuteQueryWithStream() throws SQLException { try { //when returned cursor is null - when(mockVtGateConn + Mockito.when(mockVtGateConn .streamExecute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(null); preparedStatement.executeQuery(); @@ -235,17 +224,17 @@ public void testExecuteQueryWithStream() throws SQLException { @Test public void testExecuteUpdate() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - List fieldList = mock(ArrayList.class); - - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + List fieldList = Mockito.mock(ArrayList.class); + + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessPreparedStatement preparedStatement; try { @@ -257,14 +246,14 @@ public void testExecuteUpdate() throws SQLException { assertEquals(0, updateCount); //tx is null & autoCommit is true - when(mockConn.getAutoCommit()).thenReturn(true); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); preparedStatement = new VitessPreparedStatement(mockConn, sqlUpdate); updateCount = preparedStatement.executeUpdate(); assertEquals(0, updateCount); //cursor fields is not null - when(mockCursor.getFields()).thenReturn(fieldList); - when(fieldList.isEmpty()).thenReturn(false); + Mockito.when(mockCursor.getFields()).thenReturn(fieldList); + Mockito.when(fieldList.isEmpty()).thenReturn(false); try { preparedStatement.executeUpdate(); fail("Should have thrown exception for field not null"); @@ -273,7 +262,7 @@ public void testExecuteUpdate() throws SQLException { } //cursor is null - when(mockSqlFutureCursor.checkedGet()).thenReturn(null); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(null); try { preparedStatement.executeUpdate(); fail("Should have thrown exception for cursor null"); @@ -282,7 +271,7 @@ public void testExecuteUpdate() throws SQLException { } //read only - when(mockConn.isReadOnly()).thenReturn(true); + Mockito.when(mockConn.isReadOnly()).thenReturn(true); try { preparedStatement.executeUpdate(); fail("Should have thrown exception for read only"); @@ -291,7 +280,7 @@ public void testExecuteUpdate() throws SQLException { } //read only - when(mockConn.isReadOnly()).thenReturn(true); + Mockito.when(mockConn.isReadOnly()).thenReturn(true); try { preparedStatement.executeBatch(); fail("Should have thrown exception for read only"); @@ -306,31 +295,31 @@ public void testExecuteUpdate() throws SQLException { @Test public void testExecute() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - List mockFieldList = PowerMockito.spy(new ArrayList<>()); - - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + List mockFieldList = Mockito.spy(new ArrayList<>()); + + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); - when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); - when(mockConn.getAutoCommit()).thenReturn(true); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(mockFieldList); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(mockFieldList); VitessPreparedStatement preparedStatement = new VitessPreparedStatement(mockConn, sqlSelect, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); try { int fieldSize = 5; - when(mockCursor.getFields()).thenReturn(mockFieldList); - PowerMockito.doReturn(fieldSize).when(mockFieldList).size(); - PowerMockito.doReturn(false).when(mockFieldList).isEmpty(); + Mockito.when(mockCursor.getFields()).thenReturn(mockFieldList); + Mockito.doReturn(fieldSize).when(mockFieldList).size(); + Mockito.doReturn(false).when(mockFieldList).isEmpty(); boolean hasResultSet = preparedStatement.execute(); Assert.assertTrue(hasResultSet); Assert.assertNotNull(preparedStatement.getResultSet()); @@ -341,9 +330,9 @@ public void testExecute() throws SQLException { Assert.assertNotNull(preparedStatement.getResultSet()); int mockUpdateCount = 10; - when(mockCursor.getFields()) + Mockito.when(mockCursor.getFields()) .thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); - when(mockCursor.getRowsAffected()).thenReturn((long) mockUpdateCount); + Mockito.when(mockCursor.getRowsAffected()).thenReturn((long) mockUpdateCount); preparedStatement = new VitessPreparedStatement(mockConn, sqlUpdate); hasResultSet = preparedStatement.execute(); Assert.assertFalse(hasResultSet); @@ -351,7 +340,7 @@ public void testExecute() throws SQLException { assertEquals(mockUpdateCount, preparedStatement.getUpdateCount()); //cursor is null - when(mockSqlFutureCursor.checkedGet()).thenReturn(null); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(null); try { preparedStatement = new VitessPreparedStatement(mockConn, sqlShow); preparedStatement.execute(); @@ -375,19 +364,19 @@ public void testExecuteFetchSizeAsStreaming() throws SQLException { private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRunExecute, boolean shouldRunStreamExecute) throws SQLException { - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); - VitessConnection mockConn = mock(VitessConnection.class); - when(mockConn.isSimpleExecute()).thenReturn(simpleExecute); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(simpleExecute); + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockVtGateConn + Mockito.when(mockVtGateConn .streamExecute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockCursor); @@ -408,32 +397,32 @@ private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRun @Test public void testGetUpdateCount() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFuture = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFuture = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFuture); - when(mockSqlFuture.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFuture.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessPreparedStatement preparedStatement = new VitessPreparedStatement(mockConn, sqlSelect); try { - when(mockCursor.getRowsAffected()).thenReturn(10L); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(10L); int updateCount = preparedStatement.executeUpdate(); assertEquals(10L, updateCount); assertEquals(10L, preparedStatement.getUpdateCount()); // Truncated Update Count - when(mockCursor.getRowsAffected()).thenReturn((long) Integer.MAX_VALUE + 10); + Mockito.when(mockCursor.getRowsAffected()).thenReturn((long) Integer.MAX_VALUE + 10); updateCount = preparedStatement.executeUpdate(); assertEquals(Integer.MAX_VALUE, updateCount); assertEquals(Integer.MAX_VALUE, preparedStatement.getUpdateCount()); - when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); preparedStatement.executeQuery(); assertEquals(-1, preparedStatement.getUpdateCount()); @@ -444,7 +433,7 @@ public void testGetUpdateCount() throws SQLException { @Test public void testSetParameters() throws Exception { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); Mockito.when(mockConn.getTreatUtilDateAsTimestamp()).thenReturn(true); VitessPreparedStatement preparedStatement = new VitessPreparedStatement(mockConn, sqlSelect); Boolean boolValue = true; @@ -565,7 +554,7 @@ public void testSetParameters() throws Exception { @Test public void testTreatUtilDateAsTimestamp() throws Exception { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessPreparedStatement preparedStatement = new VitessPreparedStatement(mockConn, sqlSelect); java.util.Date utilDateValue = new java.util.Date(System.currentTimeMillis()); @@ -593,24 +582,24 @@ public void testTreatUtilDateAsTimestamp() throws Exception { @Test public void testAutoGeneratedKeys() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); try { long expectedFirstGeneratedId = 121; long[] expectedGeneratedIds = {121, 122}; int expectedAffectedRows = 2; - when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); - when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedAffectedRows)); + Mockito.when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedAffectedRows)); //Executing Insert Statement VitessPreparedStatement preparedStatement = new VitessPreparedStatement(mockConn, sqlInsert, @@ -632,7 +621,7 @@ public void testAutoGeneratedKeys() throws SQLException { @Test public void testAddBatch() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessPreparedStatement statement = new VitessPreparedStatement(mockConn, sqlInsert); try { statement.addBatch(this.sqlInsert); @@ -656,7 +645,7 @@ public void testAddBatch() throws SQLException { @Test public void testClearBatch() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessPreparedStatement statement = new VitessPreparedStatement(mockConn, sqlInsert); statement.setString(1, "string1"); statement.addBatch(); @@ -674,25 +663,25 @@ public void testClearBatch() throws SQLException { @Test public void testExecuteBatch() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessPreparedStatement statement = new VitessPreparedStatement(mockConn, sqlInsert); int[] updateCounts = statement.executeBatch(); assertEquals(0, updateCounts.length); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockConn.getAutoCommit()).thenReturn(true); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - when(mockVtGateConn.executeBatch(nullable(Context.class), Matchers.anyList(), Matchers.anyList(), + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + Mockito.when(mockVtGateConn.executeBatch(nullable(Context.class), Matchers.anyList(), Matchers.anyList(), nullable(VTSession.class))).thenReturn(mockSqlFutureCursor); List mockCursorWithErrorList = new ArrayList<>(); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); - CursorWithError mockCursorWithError1 = mock(CursorWithError.class); - when(mockCursorWithError1.getError()).thenReturn(null); - when(mockCursorWithError1.getCursor()).thenReturn(mock(Cursor.class)); + CursorWithError mockCursorWithError1 = Mockito.mock(CursorWithError.class); + Mockito.when(mockCursorWithError1.getError()).thenReturn(null); + Mockito.when(mockCursorWithError1.getCursor()).thenReturn(Mockito.mock(Cursor.class)); mockCursorWithErrorList.add(mockCursorWithError1); statement.setString(1, "string1"); @@ -700,10 +689,10 @@ public void testExecuteBatch() throws SQLException { updateCounts = statement.executeBatch(); assertEquals(1, updateCounts.length); - CursorWithError mockCursorWithError2 = mock(CursorWithError.class); + CursorWithError mockCursorWithError2 = Mockito.mock(CursorWithError.class); Vtrpc.RPCError rpcError = Vtrpc.RPCError.newBuilder() .setMessage("preparedStatement execute batch error").build(); - when(mockCursorWithError2.getError()).thenReturn(rpcError); + Mockito.when(mockCursorWithError2.getError()).thenReturn(rpcError); mockCursorWithErrorList.add(mockCursorWithError2); statement.setString(1, "string1"); statement.addBatch(); @@ -721,7 +710,7 @@ public void testExecuteBatch() throws SQLException { @Test public void testStatementCount() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); Map testCases = ImmutableMap.builder() .put("select * from foo where a = ?", 1).put("select * from foo where a = ? and b = ?", 2) .put("select * from foo where a = ? and b = \"?\"", 1) diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessResultSetTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessResultSetTest.java index a2be875e0d0..bd753d2fcb5 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessResultSetTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessResultSetTest.java @@ -40,18 +40,13 @@ import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Matchers; +import org.mockito.Mockito; import org.mockito.internal.verification.VerificationModeFactory; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * Created by harshit.gangal on 19/01/16. */ -@RunWith(PowerMockRunner.class) -@PrepareForTest(VitessResultSet.class) public class VitessResultSetTest extends BaseTest { public Cursor getCursorWithRows() { @@ -635,230 +630,6 @@ public void testEnhancedFieldsFromCursor() throws Exception { assertEquals(cursor.getFields().size(), vitessResultSet.getFields().size()); } - @Test - public void testGetStringUsesEncoding() throws Exception { - VitessConnection conn = getVitessConnection(); - VitessResultSet resultOne = PowerMockito - .spy(new VitessResultSet(getCursorWithRows(), new VitessStatement(conn))); - resultOne.next(); - // test all ways to get to convertBytesToString - - // Verify that we're going through convertBytesToString for column types that return bytes - // (string-like), - // but not for those that return a real object - //resultOne.getString("col21"); // is a string, should go through convert bytes - //resultOne.getString("col13"); // is a datetime, should not - //PowerMockito.verifyPrivate(resultOne, VerificationModeFactory.times(1)) - // .invoke("convertBytesToString", Matchers.any(byte[].class), Matchers.anyString()); - - conn.setIncludedFields(Query.ExecuteOptions.IncludedFields.TYPE_AND_NAME); - VitessResultSet resultTwo = PowerMockito - .spy(new VitessResultSet(getCursorWithRows(), new VitessStatement(conn))); - resultTwo.next(); - - // neither of these should go through convertBytesToString, because we didn't include all fields - resultTwo.getString("col21"); - resultTwo.getString("col13"); - PowerMockito.verifyPrivate(resultTwo, VerificationModeFactory.times(0)) - .invoke("convertBytesToString", Matchers.any(byte[].class), Matchers.anyString()); - } - - @Test - public void testGetObjectForBitValues() throws Exception { - VitessConnection conn = getVitessConnection(); - - ByteString.Output value = ByteString.newOutput(); - value.write(new byte[]{1}); - value.write(new byte[]{0}); - value.write(new byte[]{1, 2, 3, 4}); - - Query.QueryResult result = Query.QueryResult.newBuilder().addFields( - Query.Field.newBuilder().setName("col1").setColumnLength(1).setType(Query.Type.BIT)) - .addFields( - Query.Field.newBuilder().setName("col2").setColumnLength(1).setType(Query.Type.BIT)) - .addFields( - Query.Field.newBuilder().setName("col3").setColumnLength(4).setType(Query.Type.BIT)) - .addRows(Query.Row.newBuilder().addLengths(1).addLengths(1).addLengths(4) - .setValues(value.toByteString())).build(); - - VitessResultSet vitessResultSet = PowerMockito - .spy(new VitessResultSet(new SimpleCursor(result), new VitessStatement(conn))); - vitessResultSet.next(); - - assertEquals(true, vitessResultSet.getObject(1)); - assertEquals(false, vitessResultSet.getObject(2)); - Assert.assertArrayEquals(new byte[]{1, 2, 3, 4}, (byte[]) vitessResultSet.getObject(3)); - - PowerMockito.verifyPrivate(vitessResultSet, VerificationModeFactory.times(3)) - .invoke("convertBytesIfPossible", Matchers.any(byte[].class), - Matchers.any(FieldWithMetadata.class)); - - conn.setIncludedFields(Query.ExecuteOptions.IncludedFields.TYPE_AND_NAME); - vitessResultSet = PowerMockito - .spy(new VitessResultSet(new SimpleCursor(result), new VitessStatement(conn))); - vitessResultSet.next(); - - Assert.assertArrayEquals(new byte[]{1}, (byte[]) vitessResultSet.getObject(1)); - Assert.assertArrayEquals(new byte[]{0}, (byte[]) vitessResultSet.getObject(2)); - Assert.assertArrayEquals(new byte[]{1, 2, 3, 4}, (byte[]) vitessResultSet.getObject(3)); - - PowerMockito.verifyPrivate(vitessResultSet, VerificationModeFactory.times(0)) - .invoke("convertBytesIfPossible", Matchers.any(byte[].class), - Matchers.any(FieldWithMetadata.class)); - } - - @Test - public void testGetObjectForVarBinLikeValues() throws Exception { - VitessConnection conn = getVitessConnection(); - - ByteString.Output value = ByteString.newOutput(); - - byte[] binary = new byte[]{1, 2, 3, 4}; - byte[] varbinary = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; - byte[] blob = new byte[MysqlDefs.LENGTH_BLOB]; - for (int i = 0; i < blob.length; i++) { - blob[i] = 1; - } - byte[] fakeGeometry = new byte[]{2, 3, 4}; - - value.write(binary); - value.write(varbinary); - value.write(blob); - value.write(fakeGeometry); - - Query.QueryResult result = Query.QueryResult.newBuilder().addFields( - Query.Field.newBuilder().setName("col1").setColumnLength(4) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_binary).setType(Query.Type.BINARY) - .setFlags(Query.MySqlFlag.BINARY_FLAG_VALUE)).addFields( - Query.Field.newBuilder().setName("col2").setColumnLength(13) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_binary).setType(Query.Type.VARBINARY) - .setFlags(Query.MySqlFlag.BINARY_FLAG_VALUE)).addFields( - Query.Field.newBuilder().setName("col3") // should go to LONGVARBINARY due to below settings - .setColumnLength(MysqlDefs.LENGTH_BLOB) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_binary) - .setFlags(Query.MySqlFlag.BINARY_FLAG_VALUE).setType(Query.Type.BLOB)).addFields( - Query.Field.newBuilder().setName("col4").setType(Query.Type.GEOMETRY) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_binary).setType(Query.Type.BINARY) - .setFlags(Query.MySqlFlag.BINARY_FLAG_VALUE)).addRows( - Query.Row.newBuilder().addLengths(4).addLengths(13).addLengths(MysqlDefs.LENGTH_BLOB) - .addLengths(3).setValues(value.toByteString())).build(); - - VitessResultSet vitessResultSet = PowerMockito - .spy(new VitessResultSet(new SimpleCursor(result), new VitessStatement(conn))); - vitessResultSet.next(); - - // All of these types should pass straight through, returning the direct bytes - Assert.assertArrayEquals(binary, (byte[]) vitessResultSet.getObject(1)); - Assert.assertArrayEquals(varbinary, (byte[]) vitessResultSet.getObject(2)); - Assert.assertArrayEquals(blob, (byte[]) vitessResultSet.getObject(3)); - Assert.assertArrayEquals(fakeGeometry, (byte[]) vitessResultSet.getObject(4)); - - // We should still call the function 4 times - PowerMockito.verifyPrivate(vitessResultSet, VerificationModeFactory.times(4)) - .invoke("convertBytesIfPossible", Matchers.any(byte[].class), - Matchers.any(FieldWithMetadata.class)); - - conn.setIncludedFields(Query.ExecuteOptions.IncludedFields.TYPE_AND_NAME); - vitessResultSet = PowerMockito - .spy(new VitessResultSet(new SimpleCursor(result), new VitessStatement(conn))); - vitessResultSet.next(); - - // Same as above since this doesn't really do much but pass right through for the varbinary type - Assert.assertArrayEquals(binary, (byte[]) vitessResultSet.getObject(1)); - Assert.assertArrayEquals(varbinary, (byte[]) vitessResultSet.getObject(2)); - Assert.assertArrayEquals(blob, (byte[]) vitessResultSet.getObject(3)); - Assert.assertArrayEquals(fakeGeometry, (byte[]) vitessResultSet.getObject(4)); - - // Never call because not including all - PowerMockito.verifyPrivate(vitessResultSet, VerificationModeFactory.times(0)) - .invoke("convertBytesIfPossible", Matchers.any(byte[].class), - Matchers.any(FieldWithMetadata.class)); - } - - @Test - public void testGetObjectForStringLikeValues() throws Exception { - ByteString.Output value = ByteString.newOutput(); - - String trimmedCharStr = "wasting space"; - String varcharStr = "i have a variable length!"; - String masqueradingBlobStr = "look at me, im a blob"; - String textStr = "an enthralling string of TEXT in some foreign language"; - String jsonStr = "{\"status\": \"ok\"}"; - - int paddedCharColLength = 20; - byte[] trimmedChar = StringUtils.getBytes(trimmedCharStr, "UTF-16"); - byte[] varchar = StringUtils.getBytes(varcharStr, "UTF-8"); - byte[] masqueradingBlob = StringUtils.getBytes(masqueradingBlobStr, "US-ASCII"); - byte[] text = StringUtils.getBytes(textStr, "ISO8859_8"); - byte[] opaqueBinary = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}; - byte[] json = StringUtils.getBytes(jsonStr, "UTF-8"); - - value.write(trimmedChar); - value.write(varchar); - value.write(opaqueBinary); - value.write(masqueradingBlob); - value.write(text); - value.write(json); - - Query.QueryResult result = Query.QueryResult.newBuilder() - // This tests CHAR - .addFields(Query.Field.newBuilder().setName("col1").setColumnLength(paddedCharColLength) - .setCharset(/* utf-16 collation index from CharsetMapping */ 54) - .setType(Query.Type.CHAR)) - // This tests VARCHAR - .addFields(Query.Field.newBuilder().setName("col2").setColumnLength(varchar.length) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_utf8).setType(Query.Type.VARCHAR)) - // This tests VARCHAR that is an opaque binary - .addFields(Query.Field.newBuilder().setName("col2").setColumnLength(opaqueBinary.length) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_binary) - .setFlags(Query.MySqlFlag.BINARY_FLAG_VALUE).setType(Query.Type.VARCHAR)) - // This tests LONGVARCHAR - .addFields(Query.Field.newBuilder().setName("col3").setColumnLength(masqueradingBlob.length) - .setCharset(/* us-ascii collation index from CharsetMapping */11) - .setType(Query.Type.BLOB)) - // This tests TEXT, which falls through the default case of the switch - .addFields(Query.Field.newBuilder().setName("col4").setColumnLength(text.length) - .setCharset(/* corresponds to greek, from CharsetMapping */25).setType(Query.Type.TEXT)) - .addFields(Query.Field.newBuilder().setName("col5").setColumnLength(json.length) - .setCharset(CharsetMapping.MYSQL_COLLATION_INDEX_utf8).setType(Query.Type.JSON)) - .addRows(Query.Row.newBuilder().addLengths(trimmedChar.length).addLengths(varchar.length) - .addLengths(opaqueBinary.length).addLengths(masqueradingBlob.length) - .addLengths(text.length).addLengths(json.length).setValues(value.toByteString())) - .build(); - - VitessConnection conn = getVitessConnection(); - VitessResultSet vitessResultSet = PowerMockito - .spy(new VitessResultSet(new SimpleCursor(result), new VitessStatement(conn))); - vitessResultSet.next(); - - assertEquals(trimmedCharStr, vitessResultSet.getObject(1)); - assertEquals(varcharStr, vitessResultSet.getObject(2)); - Assert.assertArrayEquals(opaqueBinary, (byte[]) vitessResultSet.getObject(3)); - assertEquals(masqueradingBlobStr, vitessResultSet.getObject(4)); - assertEquals(textStr, vitessResultSet.getObject(5)); - assertEquals(jsonStr, vitessResultSet.getObject(6)); - - PowerMockito.verifyPrivate(vitessResultSet, VerificationModeFactory.times(6)) - .invoke("convertBytesIfPossible", Matchers.any(byte[].class), - Matchers.any(FieldWithMetadata.class)); - - conn.setIncludedFields(Query.ExecuteOptions.IncludedFields.TYPE_AND_NAME); - vitessResultSet = PowerMockito - .spy(new VitessResultSet(new SimpleCursor(result), new VitessStatement(conn))); - vitessResultSet.next(); - - Assert.assertArrayEquals(trimmedChar, (byte[]) vitessResultSet.getObject(1)); - Assert.assertArrayEquals(varchar, (byte[]) vitessResultSet.getObject(2)); - Assert.assertArrayEquals(opaqueBinary, (byte[]) vitessResultSet.getObject(3)); - Assert.assertArrayEquals(masqueradingBlob, (byte[]) vitessResultSet.getObject(4)); - Assert.assertArrayEquals(text, (byte[]) vitessResultSet.getObject(5)); - Assert.assertArrayEquals(json, (byte[]) vitessResultSet.getObject(6)); - - PowerMockito.verifyPrivate(vitessResultSet, VerificationModeFactory.times(0)) - .invoke("convertBytesIfPossible", Matchers.any(byte[].class), - Matchers.any(FieldWithMetadata.class)); - } - @Test public void testGetClob() throws SQLException { VitessResultSet vitessResultSet = new VitessResultSet(new String[]{"clob"}, diff --git a/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java b/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java index 3f4bb39a44c..b641cafdefb 100644 --- a/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java +++ b/java/jdbc/src/test/java/io/vitess/jdbc/VitessStatementTest.java @@ -22,15 +22,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; import static org.mockito.Matchers.nullable; -import static org.mockito.Matchers.anyList; -import static org.mockito.Matchers.anyMap; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.doReturn; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; import io.vitess.client.Context; import io.vitess.client.SQLFuture; @@ -52,18 +45,12 @@ import java.util.Map; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; /** * Created by harshit.gangal on 19/01/16. */ -@RunWith(PowerMockRunner.class) -@PrepareForTest({VTGateConnection.class, Vtrpc.RPCError.class}) public class VitessStatementTest { private String sqlSelect = "select 1 from test_table"; @@ -76,7 +63,7 @@ public class VitessStatementTest { @Test public void testGetConnection() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(mockConn, statement.getConnection()); @@ -84,24 +71,24 @@ public void testGetConnection() throws SQLException { @Test public void testGetResultSet() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(null, statement.getResultSet()); } @Test public void testExecuteQuery() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockConn.isSimpleExecute()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessStatement statement = new VitessStatement(mockConn); //Empty Sql Statement @@ -116,13 +103,13 @@ public void testExecuteQuery() throws SQLException { assertEquals(-1, statement.getUpdateCount()); //autocommit is false and not in transaction - when(mockConn.getAutoCommit()).thenReturn(false); - when(mockConn.isInTransaction()).thenReturn(false); + Mockito.when(mockConn.getAutoCommit()).thenReturn(false); + Mockito.when(mockConn.isInTransaction()).thenReturn(false); rs = statement.executeQuery(sqlSelect); assertEquals(-1, statement.getUpdateCount()); //when returned cursor is null - when(mockSqlFutureCursor.checkedGet()).thenReturn(null); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(null); try { statement.executeQuery(sqlSelect); fail("Should have thrown exception for cursor null"); @@ -133,18 +120,18 @@ public void testExecuteQuery() throws SQLException { @Test public void testExecuteQueryWithStreamExecuteType() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn .streamExecute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockCursor); - when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.STREAM); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.STREAM); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessStatement statement = new VitessStatement(mockConn); //Empty Sql Statement @@ -164,13 +151,13 @@ public void testExecuteQueryWithStreamExecuteType() throws SQLException { assertEquals(-1, statement.getUpdateCount()); //select on primary when tx is null and autocommit is false - when(mockConn.getAutoCommit()).thenReturn(false); - when(mockConn.isInTransaction()).thenReturn(false); + Mockito.when(mockConn.getAutoCommit()).thenReturn(false); + Mockito.when(mockConn.isInTransaction()).thenReturn(false); rs = statement.executeQuery(sqlSelect); assertEquals(-1, statement.getUpdateCount()); //when returned cursor is null - when(mockVtGateConn + Mockito.when(mockVtGateConn .streamExecute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(null); try { @@ -191,19 +178,19 @@ public void testExecuteFetchSizeAsStreaming() throws SQLException { private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRunExecute, boolean shouldRunStreamExecute) throws SQLException { - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); - VitessConnection mockConn = mock(VitessConnection.class); - when(mockConn.isSimpleExecute()).thenReturn(simpleExecute); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(simpleExecute); + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockVtGateConn + Mockito.when(mockVtGateConn .streamExecute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockCursor); @@ -224,17 +211,17 @@ private void testExecute(int fetchSize, boolean simpleExecute, boolean shouldRun @Test public void testExecuteUpdate() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - List fieldList = mock(ArrayList.class); - - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + List fieldList = Mockito.mock(ArrayList.class); + + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessStatement statement = new VitessStatement(mockConn); //executing dml on primary @@ -242,13 +229,13 @@ public void testExecuteUpdate() throws SQLException { assertEquals(0, updateCount); //tx is null & autoCommit is true - when(mockConn.getAutoCommit()).thenReturn(true); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); updateCount = statement.executeUpdate(sqlUpdate); assertEquals(0, updateCount); //cursor fields is not null - when(mockCursor.getFields()).thenReturn(fieldList); - when(fieldList.isEmpty()).thenReturn(false); + Mockito.when(mockCursor.getFields()).thenReturn(fieldList); + Mockito.when(fieldList.isEmpty()).thenReturn(false); try { statement.executeUpdate(sqlSelect); fail("Should have thrown exception for field not null"); @@ -257,7 +244,7 @@ public void testExecuteUpdate() throws SQLException { } //cursor is null - when(mockSqlFutureCursor.checkedGet()).thenReturn(null); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(null); try { statement.executeUpdate(sqlUpdate); fail("Should have thrown exception for cursor null"); @@ -266,7 +253,7 @@ public void testExecuteUpdate() throws SQLException { } //read only - when(mockConn.isReadOnly()).thenReturn(true); + Mockito.when(mockConn.isReadOnly()).thenReturn(true); try { statement.execute("UPDATE SET foo = 1 ON mytable WHERE id = 1"); fail("Should have thrown exception for read only"); @@ -275,7 +262,7 @@ public void testExecuteUpdate() throws SQLException { } //read only - when(mockConn.isReadOnly()).thenReturn(true); + Mockito.when(mockConn.isReadOnly()).thenReturn(true); try { statement.executeBatch(); fail("Should have thrown exception for read only"); @@ -286,27 +273,27 @@ public void testExecuteUpdate() throws SQLException { @Test public void testExecute() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - List mockFieldList = PowerMockito.spy(new ArrayList<>()); - - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + List mockFieldList = Mockito.spy(new ArrayList<>()); + + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockConn.getAutoCommit()).thenReturn(true); - when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); - when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); + Mockito.when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(mockFieldList); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(mockFieldList); VitessStatement statement = new VitessStatement(mockConn); int fieldSize = 5; - when(mockCursor.getFields()).thenReturn(mockFieldList); - doReturn(fieldSize).when(mockFieldList).size(); - doReturn(false).when(mockFieldList).isEmpty(); + Mockito.when(mockCursor.getFields()).thenReturn(mockFieldList); + Mockito.doReturn(fieldSize).when(mockFieldList).size(); + Mockito.doReturn(false).when(mockFieldList).isEmpty(); boolean hasResultSet = statement.execute(sqlSelect); assertTrue(hasResultSet); @@ -317,15 +304,15 @@ public void testExecute() throws SQLException { assertNotNull(statement.getResultSet()); int mockUpdateCount = 10; - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); - when(mockCursor.getRowsAffected()).thenReturn((long) mockUpdateCount); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockCursor.getRowsAffected()).thenReturn((long) mockUpdateCount); hasResultSet = statement.execute(sqlUpdate); assertFalse(hasResultSet); assertNull(statement.getResultSet()); assertEquals(mockUpdateCount, statement.getUpdateCount()); //cursor is null - when(mockSqlFutureCursor.checkedGet()).thenReturn(null); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(null); try { statement.execute(sqlUpdate); fail("Should have thrown exception for cursor null"); @@ -336,47 +323,47 @@ public void testExecute() throws SQLException { @Test public void testGetUpdateCount() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFuture = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFuture = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFuture); - when(mockSqlFuture.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFuture.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessStatement statement = new VitessStatement(mockConn); - when(mockCursor.getRowsAffected()).thenReturn(10L); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(10L); int updateCount = statement.executeUpdate(sqlUpdate); assertEquals(10L, updateCount); assertEquals(10L, statement.getUpdateCount()); // Truncated Update Count - when(mockCursor.getRowsAffected()).thenReturn((long) Integer.MAX_VALUE + 10); + Mockito.when(mockCursor.getRowsAffected()).thenReturn((long) Integer.MAX_VALUE + 10); updateCount = statement.executeUpdate(sqlUpdate); assertEquals(Integer.MAX_VALUE, updateCount); assertEquals(Integer.MAX_VALUE, statement.getUpdateCount()); - when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); statement.executeQuery(sqlSelect); assertEquals(-1, statement.getUpdateCount()); } @Test public void testClose() throws Exception { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); - when(mockConn.isSimpleExecute()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockConn.getExecuteType()).thenReturn(Constants.QueryExecuteType.SIMPLE); + Mockito.when(mockConn.isSimpleExecute()).thenReturn(true); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); VitessStatement statement = new VitessStatement(mockConn); ResultSet rs = statement.executeQuery(sqlSelect); @@ -391,7 +378,7 @@ public void testClose() throws Exception { @Test public void testGetMaxFieldSize() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(65535, statement.getMaxFieldSize()); @@ -399,7 +386,7 @@ public void testGetMaxFieldSize() throws SQLException { @Test public void testGetMaxRows() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); @@ -417,7 +404,7 @@ public void testGetMaxRows() throws SQLException { @Test public void testGetQueryTimeout() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); Mockito.when(mockConn.getTimeout()).thenReturn((long) Constants.DEFAULT_TIMEOUT); VitessStatement statement = new VitessStatement(mockConn); @@ -426,7 +413,7 @@ public void testGetQueryTimeout() throws SQLException { @Test public void testGetQueryTimeoutZeroDefault() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); Mockito.when(mockConn.getTimeout()).thenReturn(0L); VitessStatement statement = new VitessStatement(mockConn); @@ -435,7 +422,7 @@ public void testGetQueryTimeoutZeroDefault() throws SQLException { @Test public void testSetQueryTimeout() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); Mockito.when(mockConn.getTimeout()).thenReturn((long) Constants.DEFAULT_TIMEOUT); VitessStatement statement = new VitessStatement(mockConn); @@ -457,7 +444,7 @@ public void testSetQueryTimeout() throws SQLException { @Test public void testGetWarnings() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertNull(statement.getWarnings()); @@ -465,7 +452,7 @@ public void testGetWarnings() throws SQLException { @Test public void testGetFetchDirection() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(ResultSet.FETCH_FORWARD, statement.getFetchDirection()); @@ -473,7 +460,7 @@ public void testGetFetchDirection() throws SQLException { @Test public void testGetFetchSize() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(0, statement.getFetchSize()); @@ -481,7 +468,7 @@ public void testGetFetchSize() throws SQLException { @Test public void testGetResultSetConcurrency() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(ResultSet.CONCUR_READ_ONLY, statement.getResultSetConcurrency()); @@ -489,7 +476,7 @@ public void testGetResultSetConcurrency() throws SQLException { @Test public void testGetResultSetType() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertEquals(ResultSet.TYPE_FORWARD_ONLY, statement.getResultSetType()); @@ -497,7 +484,7 @@ public void testGetResultSetType() throws SQLException { @Test public void testIsClosed() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); assertFalse(statement.isClosed()); @@ -507,23 +494,23 @@ public void testIsClosed() throws SQLException { @Test public void testAutoGeneratedKeys() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockVtGateConn.execute(nullable(Context.class), nullable(String.class), nullable(Map.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); VitessStatement statement = new VitessStatement(mockConn); long expectedFirstGeneratedId = 121; long[] expectedGeneratedIds = {121, 122, 123, 124, 125}; int expectedAffectedRows = 5; - when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); - when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedAffectedRows)); + Mockito.when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedAffectedRows)); //Executing Insert Statement int updateCount = statement.executeUpdate(sqlInsert, Statement.RETURN_GENERATED_KEYS); @@ -550,7 +537,7 @@ public void testAutoGeneratedKeys() throws SQLException { //Fetching Generated Keys on update query expectedFirstGeneratedId = 0; - when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); + Mockito.when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); updateCount = statement.executeUpdate(sqlUpdate, Statement.RETURN_GENERATED_KEYS); assertEquals(expectedAffectedRows, updateCount); @@ -560,7 +547,7 @@ public void testAutoGeneratedKeys() throws SQLException { @Test public void testAddBatch() throws Exception { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); statement.addBatch(sqlInsert); Field privateStringField = VitessStatement.class.getDeclaredField("batchedArgs"); @@ -570,7 +557,7 @@ public void testAddBatch() throws Exception { @Test public void testClearBatch() throws Exception { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); statement.addBatch(sqlInsert); statement.clearBatch(); @@ -581,36 +568,36 @@ public void testClearBatch() throws Exception { @Test public void testExecuteBatch() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); int[] updateCounts = statement.executeBatch(); assertEquals(0, updateCounts.length); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockConn.getAutoCommit()).thenReturn(true); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); - when( + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); + Mockito.when( mockVtGateConn.executeBatch(nullable(Context.class), nullable(List.class), nullable(List.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); List mockCursorWithErrorList = new ArrayList<>(); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); - CursorWithError mockCursorWithError1 = mock(CursorWithError.class); - when(mockCursorWithError1.getError()).thenReturn(null); - when(mockCursorWithError1.getCursor()).thenReturn(mock(Cursor.class)); + CursorWithError mockCursorWithError1 = Mockito.mock(CursorWithError.class); + Mockito.when(mockCursorWithError1.getError()).thenReturn(null); + Mockito.when(mockCursorWithError1.getCursor()).thenReturn(Mockito.mock(Cursor.class)); mockCursorWithErrorList.add(mockCursorWithError1); statement.addBatch(sqlUpdate); updateCounts = statement.executeBatch(); assertEquals(1, updateCounts.length); - CursorWithError mockCursorWithError2 = mock(CursorWithError.class); + CursorWithError mockCursorWithError2 = Mockito.mock(CursorWithError.class); Vtrpc.RPCError rpcError = Vtrpc.RPCError.newBuilder() .setMessage("statement execute batch error").build(); - when(mockCursorWithError2.getError()).thenReturn(rpcError); + Mockito.when(mockCursorWithError2.getError()).thenReturn(rpcError); mockCursorWithErrorList.add(mockCursorWithError2); statement.addBatch(sqlUpdate); statement.addBatch(sqlUpdate); @@ -627,33 +614,33 @@ public void testExecuteBatch() throws SQLException { @Test public void testBatchGeneratedKeys() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockConn.getAutoCommit()).thenReturn(true); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); - when( + Mockito.when( mockVtGateConn.executeBatch(nullable(Context.class), nullable(List.class), nullable(List.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); List mockCursorWithErrorList = new ArrayList<>(); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); - CursorWithError mockCursorWithError = mock(CursorWithError.class); - when(mockCursorWithError.getError()).thenReturn(null); - when(mockCursorWithError.getCursor()).thenReturn(mockCursor); + CursorWithError mockCursorWithError = Mockito.mock(CursorWithError.class); + Mockito.when(mockCursorWithError.getError()).thenReturn(null); + Mockito.when(mockCursorWithError.getCursor()).thenReturn(mockCursor); mockCursorWithErrorList.add(mockCursorWithError); long expectedFirstGeneratedId = 121; long[] expectedGeneratedIds = {121, 122, 123, 124, 125}; - when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); - when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedGeneratedIds.length)); + Mockito.when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedGeneratedIds.length)); statement.addBatch(sqlInsert); statement.executeBatch(); @@ -668,33 +655,33 @@ public void testBatchGeneratedKeys() throws SQLException { @Test public void testBatchUpsertGeneratedKeys() throws SQLException { - VitessConnection mockConn = mock(VitessConnection.class); + VitessConnection mockConn = Mockito.mock(VitessConnection.class); VitessStatement statement = new VitessStatement(mockConn); - Cursor mockCursor = mock(Cursor.class); - SQLFuture mockSqlFutureCursor = mock(SQLFuture.class); + Cursor mockCursor = Mockito.mock(Cursor.class); + SQLFuture mockSqlFutureCursor = Mockito.mock(SQLFuture.class); - VTGateConnection mockVtGateConn = mock(VTGateConnection.class); - when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); - when(mockConn.getAutoCommit()).thenReturn(true); + VTGateConnection mockVtGateConn = Mockito.mock(VTGateConnection.class); + Mockito.when(mockConn.getVtGateConn()).thenReturn(mockVtGateConn); + Mockito.when(mockConn.getAutoCommit()).thenReturn(true); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); - when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursor); + Mockito.when(mockCursor.getFields()).thenReturn(Query.QueryResult.getDefaultInstance().getFieldsList()); - when( + Mockito.when( mockVtGateConn.executeBatch(nullable(Context.class), nullable(List.class), nullable(List.class), nullable(VTSession.class))) .thenReturn(mockSqlFutureCursor); List mockCursorWithErrorList = new ArrayList<>(); - when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); + Mockito.when(mockSqlFutureCursor.checkedGet()).thenReturn(mockCursorWithErrorList); - CursorWithError mockCursorWithError = mock(CursorWithError.class); - when(mockCursorWithError.getError()).thenReturn(null); - when(mockCursorWithError.getCursor()).thenReturn(mockCursor); + CursorWithError mockCursorWithError = Mockito.mock(CursorWithError.class); + Mockito.when(mockCursorWithError.getError()).thenReturn(null); + Mockito.when(mockCursorWithError.getCursor()).thenReturn(mockCursor); mockCursorWithErrorList.add(mockCursorWithError); long expectedFirstGeneratedId = 121; long[] expectedGeneratedIds = {121, 122}; - when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); - when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedGeneratedIds.length)); + Mockito.when(mockCursor.getInsertId()).thenReturn(expectedFirstGeneratedId); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(Long.valueOf(expectedGeneratedIds.length)); statement.addBatch(sqlUpsert); statement.executeBatch(); @@ -709,8 +696,8 @@ public void testBatchUpsertGeneratedKeys() throws SQLException { } VitessStatement noUpdate = new VitessStatement(mockConn); - when(mockCursor.getInsertId()).thenReturn(0L); - when(mockCursor.getRowsAffected()).thenReturn(1L); + Mockito.when(mockCursor.getInsertId()).thenReturn(0L); + Mockito.when(mockCursor.getRowsAffected()).thenReturn(1L); noUpdate.addBatch(sqlUpsert); noUpdate.executeBatch(); diff --git a/test.go b/test.go index 4922f4f88f1..ebe0d2ded2d 100755 --- a/test.go +++ b/test.go @@ -77,7 +77,7 @@ For example: // Flags var ( flavor = flag.String("flavor", "mysql80", "comma-separated bootstrap flavor(s) to run against (when using Docker mode). Available flavors: all,"+flavors) - bootstrapVersion = flag.String("bootstrap-version", "40", "the version identifier to use for the docker images") + bootstrapVersion = flag.String("bootstrap-version", "41", "the version identifier to use for the docker images") runCount = flag.Int("runs", 1, "run each test this many times") retryMax = flag.Int("retry", 3, "max number of retries, to detect flaky tests") logPass = flag.Bool("log-pass", false, "log test output even if it passes") diff --git a/test/templates/dockerfile.tpl b/test/templates/dockerfile.tpl index 84f084e41e1..733377418f8 100644 --- a/test/templates/dockerfile.tpl +++ b/test/templates/dockerfile.tpl @@ -1,4 +1,4 @@ -ARG bootstrap_version=40 +ARG bootstrap_version=41 ARG image="vitess/bootstrap:${bootstrap_version}-{{.Platform}}" FROM "${image}"