mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-05-16 01:07:12 +08:00
PMM-8575 migrate toolkit to modules (#512)
* PMM-8575 Fixed test Fixed sandbox used by go programs, updated all tests. * PMM-8575 Fixed test Fixed sandbox used by go programs, updated all tests. * Removed Gopkg * Switched to go 1.16 * Updated go.mod * Upgraded deps * Updated deps
This commit is contained in:
+3
-5
@@ -22,8 +22,8 @@ TEST_PSMDB_VERSION?=4.0
|
||||
TEST_MONGODB_FLAVOR?=percona/percona-server-mongodb
|
||||
TEST_MONGODB_ADMIN_USERNAME?=admin
|
||||
TEST_MONGODB_ADMIN_PASSWORD?=admin123456
|
||||
TEST_MONGODB_USERNAME?=test
|
||||
TEST_MONGODB_PASSWORD?=123456
|
||||
TEST_MONGODB_USERNAME?=
|
||||
TEST_MONGODB_PASSWORD?=
|
||||
|
||||
TEST_MONGODB_STANDALONE_PORT?=27017
|
||||
|
||||
@@ -103,9 +103,7 @@ env-up: env ## Start MongoDB docker containers cluster
|
||||
--detach \
|
||||
--force-recreate \
|
||||
--always-recreate-deps \
|
||||
--renew-anon-volumes \
|
||||
init
|
||||
docker/test/init-cluster-wait.sh
|
||||
--renew-anon-volumes
|
||||
|
||||
env-down: env ## Clean-up MongoDB docker containers cluster
|
||||
docker-compose down -v
|
||||
|
||||
+215
-217
@@ -1,219 +1,217 @@
|
||||
---
|
||||
version: '3'
|
||||
services:
|
||||
standalone:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: ${TEST_MONGODB_ADMIN_USERNAME}
|
||||
MONGO_INITDB_ROOT_PASSWORD: ${TEST_MONGODB_ADMIN_PASSWORD}
|
||||
command: --port=27017
|
||||
s1-mongo1:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S1_RS} --port=${TEST_MONGODB_S1_PRIMARY_PORT} --shardsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s1-mongo2:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S1_RS} --port=${TEST_MONGODB_S1_SECONDARY1_PORT} --shardsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s1-mongo3:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S1_RS} --port=${TEST_MONGODB_S1_SECONDARY2_PORT} --shardsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s2-mongo1:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S2_RS} --port=${TEST_MONGODB_S2_PRIMARY_PORT} --shardsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s2-mongo2:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S2_RS} --port=${TEST_MONGODB_S2_SECONDARY1_PORT} --shardsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s2-mongo3:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S2_RS} --port=${TEST_MONGODB_S2_SECONDARY2_PORT} --shardsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s3-mongo1:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S3_RS} --port=${TEST_MONGODB_S3_PRIMARY_PORT}
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s3-mongo2:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S3_RS} --port=${TEST_MONGODB_S3_SECONDARY1_PORT}
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
s3-mongo3:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_S3_RS} --port=${TEST_MONGODB_S3_SECONDARY2_PORT}
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
configsvr1:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --replSet=${TEST_MONGODB_CONFIGSVR_RS} --port=${TEST_MONGODB_CONFIGSVR1_PORT} --configsvr
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongod.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
# configsvr2:
|
||||
# network_mode: host
|
||||
# image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
# command: --replSet=${TEST_MONGODB_CONFIGSVR_RS} --port=${TEST_MONGODB_CONFIGSVR2_PORT} --configsvr
|
||||
# volumes:
|
||||
# - ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
# - ./docker/test/mongod.key:/mongod.key:ro
|
||||
# - ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
# - ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
# configsvr3:
|
||||
# network_mode: host
|
||||
# image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
# command: --replSet=${TEST_MONGODB_CONFIGSVR_RS} --port=${TEST_MONGODB_CONFIGSVR3_PORT} --configsvr
|
||||
# volumes:
|
||||
# - ./docker/test/entrypoint-mongod.sh:/entrypoint.sh:ro
|
||||
# - ./docker/test/mongod.key:/mongod.key:ro
|
||||
# - ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
# - ./docker/test/ssl/mongodb.pem:/mongod.pem:ro
|
||||
mongos:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
command: --port=${TEST_MONGODB_MONGOS_PORT} --configdb=${TEST_MONGODB_CONFIGSVR_RS}/127.0.0.1:${TEST_MONGODB_CONFIGSVR1_PORT}
|
||||
volumes:
|
||||
- ./docker/test/entrypoint-mongos.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/entrypoint-mongos.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongos.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/mongodb.pem:/mongos.pem:ro
|
||||
depends_on:
|
||||
- configsvr1
|
||||
# - configsvr2
|
||||
# - configsvr3
|
||||
postgres9:
|
||||
image: ${MYSQL_IMAGE:-postgres:9.6}
|
||||
container_name: go_postgres9_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_96_PORT:-6432}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
postgres10:
|
||||
image: ${POSTGRE_IMAGE:-postgres:10.7}
|
||||
container_name: go_postgres10_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_10_PORT:-6433}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
postgres11:
|
||||
image: ${POSTGRE_IMAGE:-postgres:11}
|
||||
container_name: go_postgres11_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_11_PORT:-6434}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
postgres12:
|
||||
image: ${POSTGRE_IMAGE:-postgres:12}
|
||||
container_name: go_postgres12_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_12_PORT:-6435}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
init:
|
||||
network_mode: host
|
||||
image: ${TEST_MONGODB_FLAVOR}:${TEST_PSMDB_VERSION}
|
||||
volumes:
|
||||
- ./docker/test/init-cluster.sh:/entrypoint.sh:ro
|
||||
- ./docker/test/init-cluster.sh:/usr/local/bin/docker-entrypoint.sh:ro
|
||||
- ./docker/test/mongod.key:/mongod.key:ro
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/client.pem:/client.pem:ro
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
- mongos
|
||||
- s1-mongo1
|
||||
- s1-mongo2
|
||||
- s1-mongo3
|
||||
- s2-mongo1
|
||||
- s2-mongo2
|
||||
- s2-mongo3
|
||||
- s3-mongo1
|
||||
- s3-mongo2
|
||||
- s3-mongo3
|
||||
- standalone
|
||||
- postgres9
|
||||
- postgres10
|
||||
- postgres11
|
||||
- postgres12
|
||||
test:
|
||||
build:
|
||||
dockerfile: docker/test/Dockerfile
|
||||
context: .
|
||||
args:
|
||||
- GOLANG_DOCKERHUB_TAG=${GOLANG_DOCKERHUB_TAG}
|
||||
network_mode: host
|
||||
env_file:
|
||||
- .env
|
||||
volumes:
|
||||
- ./test-out:/tmp/out
|
||||
- ./docker/test/ssl/rootCA.crt:/rootCA.crt:ro
|
||||
- ./docker/test/ssl/client.pem:/client.pem:ro
|
||||
depends_on:
|
||||
- mongos
|
||||
- s1-mongo1
|
||||
- s1-mongo2
|
||||
- s1-mongo3
|
||||
- s2-mongo1
|
||||
- s2-mongo2
|
||||
- s2-mongo3
|
||||
- init
|
||||
mongo-1-1:
|
||||
container_name: "mongo-1-1"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_S1_PRIMARY_PORT:-17001}:27017"
|
||||
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
|
||||
links:
|
||||
- mongo-1-2:mongo-1-2
|
||||
- mongo-1-3:mongo-1-3
|
||||
|
||||
mongo-1-2:
|
||||
container_name: "mongo-1-2"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_S1_SECONDARY1_PORT:-17002}:27017"
|
||||
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
|
||||
|
||||
mongo-1-3:
|
||||
container_name: "mongo-1-3"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_S1_SECONDARY2_PORT:-17003}:27017"
|
||||
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
|
||||
|
||||
mongo-rs1-setup:
|
||||
container_name: "mongo-rs1-setup"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
depends_on:
|
||||
- "mongo-1-1"
|
||||
- "mongo-1-2"
|
||||
- "mongo-1-3"
|
||||
links:
|
||||
- mongo-1-1:mongo-1-1
|
||||
- mongo-1-2:mongo-1-2
|
||||
- mongo-1-3:mongo-1-3
|
||||
volumes:
|
||||
- ./docker/scripts:/scripts
|
||||
environment:
|
||||
- MONGO1=mongo-1-1
|
||||
- MONGO2=mongo-1-2
|
||||
- MONGO3=mongo-1-3
|
||||
- RS=rs1
|
||||
entrypoint: [ "/scripts/setup.sh" ]
|
||||
|
||||
mongo-2-2:
|
||||
container_name: "mongo-2-2"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_S2_PRIMARY_PORT:-17004}:27017"
|
||||
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
|
||||
|
||||
mongo-2-3:
|
||||
container_name: "mongo-2-3"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_S2_SECONDARY1_PORT:-17005}:27017"
|
||||
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
|
||||
|
||||
mongo-2-1:
|
||||
container_name: "mongo-2-1"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_S2_SECONDARY2_PORT:-17006}:27017"
|
||||
command: mongod --replSet rs2 --shardsvr --port 27017 --oplogSize 16
|
||||
links:
|
||||
- mongo-2-2:mongo-2-2
|
||||
- mongo-2-3:mongo-2-3
|
||||
|
||||
mongo-rs2-setup:
|
||||
container_name: "mongo-rs2-setup"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
depends_on:
|
||||
- "mongo-2-1"
|
||||
- "mongo-2-2"
|
||||
- "mongo-2-3"
|
||||
links:
|
||||
- mongo-2-1:mongo-2-1
|
||||
- mongo-2-2:mongo-2-2
|
||||
- mongo-2-3:mongo-2-3
|
||||
volumes:
|
||||
- ./docker/scripts:/scripts
|
||||
environment:
|
||||
- MONGO1=mongo-2-1
|
||||
- MONGO2=mongo-2-2
|
||||
- MONGO3=mongo-2-3
|
||||
- RS=rs2
|
||||
entrypoint: [ "/scripts/setup.sh" ]
|
||||
|
||||
# Config servers
|
||||
mongo-cnf-2:
|
||||
container_name: "mongo-cnf-2"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_CONFIGSVR1_PORT:-17007}:27017"
|
||||
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
|
||||
|
||||
mongo-cnf-3:
|
||||
container_name: "mongo-cnf-3"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_CONFIGSVR2_PORT:-17008}:27017"
|
||||
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
|
||||
|
||||
mongo-cnf-1:
|
||||
container_name: "mongo-cnf-1"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_CONFIGSVR3_PORT:-17009}:27017"
|
||||
command: mongod --dbpath /data/db --replSet cnf-serv --configsvr --port 27017 --oplogSize 16
|
||||
links:
|
||||
- mongo-cnf-2:mongo-cnf-2
|
||||
- mongo-cnf-3:mongo-cnf-3
|
||||
|
||||
mongo-cnf-setup:
|
||||
container_name: "mongo-cnf-setup"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
depends_on:
|
||||
- "mongo-cnf-1"
|
||||
- "mongo-cnf-2"
|
||||
- "mongo-cnf-3"
|
||||
links:
|
||||
- mongo-cnf-1:mongo-cnf-1
|
||||
- mongo-cnf-2:mongo-cnf-2
|
||||
- mongo-cnf-3:mongo-cnf-3
|
||||
volumes:
|
||||
- ./docker/scripts:/scripts
|
||||
environment:
|
||||
- MONGO1=mongo-cnf-1
|
||||
- MONGO2=mongo-cnf-2
|
||||
- MONGO3=mongo-cnf-3
|
||||
- RS=cnf-serv
|
||||
- PORT=27017
|
||||
entrypoint: [ "/scripts/setup.sh" ]
|
||||
|
||||
mongos:
|
||||
container_name: "mongos"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_MONGOS_PORT:-17000}:27017"
|
||||
depends_on:
|
||||
- "mongo-rs1-setup"
|
||||
- "mongo-rs2-setup"
|
||||
- "mongo-cnf-setup"
|
||||
external_links:
|
||||
- mongo-cnf-1:mongo-cnf-1
|
||||
- mongo-cnf-2:mongo-cnf-2
|
||||
- mongo-cnf-3:mongo-cnf-3
|
||||
- mongo-1-1:mongo-1-1
|
||||
- mongo-1-2:mongo-1-2
|
||||
- mongo-1-3:mongo-1-3
|
||||
- mongo-2-1:mongo-2-1
|
||||
- mongo-2-2:mongo-2-2
|
||||
- mongo-2-3:mongo-2-3
|
||||
command: mongos --configdb cnf-serv/mongo-cnf-1:27017,mongo-cnf-2:27017,mongo-cnf-3:27017 --port 27017 --bind_ip 0.0.0.0
|
||||
|
||||
mongo-shard-setup:
|
||||
container_name: "mongo-shard-setup"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
depends_on:
|
||||
- "mongos"
|
||||
links:
|
||||
- mongos:mongos
|
||||
volumes:
|
||||
- ./docker/scripts:/scripts
|
||||
environment:
|
||||
- MONGOS=mongos
|
||||
- MONGO11=mongo-1-1
|
||||
- MONGO12=mongo-1-2
|
||||
- MONGO13=mongo-1-3
|
||||
- MONGO21=mongo-2-1
|
||||
- MONGO22=mongo-2-2
|
||||
- MONGO23=mongo-2-3
|
||||
- RS1=rs1
|
||||
- RS2=rs2
|
||||
- PORT=27017
|
||||
- PORT1=27017
|
||||
- PORT2=27017
|
||||
- PORT3=27017
|
||||
entrypoint: [ "/scripts/init-shard.sh" ]
|
||||
restart: on-failure:20
|
||||
|
||||
standalone:
|
||||
container_name: "standalone"
|
||||
image: ${TEST_MONGODB_IMAGE:-mongo:4.2}
|
||||
ports:
|
||||
- "${TEST_MONGODB_STANDALONE_PORT:-27017}:27017"
|
||||
command: mongod --replSet rs1 --shardsvr --port 27017 --oplogSize 16
|
||||
postgres9:
|
||||
image: ${POSTGRE_IMAGE:-postgres:9.6}
|
||||
container_name: go_postgres9_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_96_PORT:-6432}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
postgres10:
|
||||
image: ${POSTGRE_IMAGE:-postgres:10.7}
|
||||
container_name: go_postgres10_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_10_PORT:-6433}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
postgres11:
|
||||
image: ${POSTGRE_IMAGE:-postgres:11}
|
||||
container_name: go_postgres11_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_11_PORT:-6434}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
postgres12:
|
||||
image: ${POSTGRE_IMAGE:-postgres:12}
|
||||
container_name: go_postgres12_1
|
||||
ports:
|
||||
- ${POSTGRE_HOST:-127.0.0.1}:${POSTGRE_12_PORT:-6435}:5432
|
||||
environment:
|
||||
- POSTGRES_PASSWORD=root
|
||||
|
||||
Regular → Executable
Regular → Executable
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
mongodb1=`getent hosts ${MONGOS} | awk '{ print $1 }'`
|
||||
|
||||
mongodb11=`getent hosts ${MONGO11} | awk '{ print $1 }'`
|
||||
mongodb12=`getent hosts ${MONGO12} | awk '{ print $1 }'`
|
||||
mongodb13=`getent hosts ${MONGO13} | awk '{ print $1 }'`
|
||||
|
||||
mongodb21=`getent hosts ${MONGO21} | awk '{ print $1 }'`
|
||||
mongodb22=`getent hosts ${MONGO22} | awk '{ print $1 }'`
|
||||
mongodb23=`getent hosts ${MONGO23} | awk '{ print $1 }'`
|
||||
|
||||
mongodb31=`getent hosts ${MONGO31} | awk '{ print $1 }'`
|
||||
mongodb32=`getent hosts ${MONGO32} | awk '{ print $1 }'`
|
||||
mongodb33=`getent hosts ${MONGO33} | awk '{ print $1 }'`
|
||||
|
||||
port=${PORT:-27017}
|
||||
|
||||
echo "Waiting for startup.."
|
||||
until mongo --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
|
||||
printf '.'
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Started.."
|
||||
|
||||
echo init-shard.sh time now: `date +"%T" `
|
||||
mongo --host ${mongodb1}:${port} <<EOF
|
||||
sh.addShard( "${RS1}/${mongodb11}:${PORT1},${mongodb12}:${PORT2},${mongodb13}:${PORT3}" );
|
||||
sh.addShard( "${RS2}/${mongodb21}:${PORT1},${mongodb22}:${PORT2},${mongodb23}:${PORT3}" );
|
||||
sh.status();
|
||||
EOF
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
mongodb1=`getent hosts ${MONGO1} | awk '{ print $1 }'`
|
||||
mongodb2=`getent hosts ${MONGO2} | awk '{ print $1 }'`
|
||||
mongodb3=`getent hosts ${MONGO3} | awk '{ print $1 }'`
|
||||
|
||||
port=${PORT:-27017}
|
||||
|
||||
echo "Waiting for startup.."
|
||||
until mongo --host ${mongodb1}:${port} --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)' &>/dev/null; do
|
||||
printf '.'
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Started.."
|
||||
|
||||
echo setup.sh time now: `date +"%T" `
|
||||
mongo --host ${mongodb1}:${port} <<EOF
|
||||
var cfg = {
|
||||
"_id": "${RS}",
|
||||
"protocolVersion": 1,
|
||||
"members": [
|
||||
{
|
||||
"_id": 0,
|
||||
"host": "${mongodb1}:${port}"
|
||||
},
|
||||
{
|
||||
"_id": 1,
|
||||
"host": "${mongodb2}:${port}"
|
||||
},
|
||||
{
|
||||
"_id": 2,
|
||||
"host": "${mongodb3}:${port}"
|
||||
}
|
||||
]
|
||||
};
|
||||
rs.initiate(cfg, { force: true });
|
||||
rs.reconfig(cfg, { force: true });
|
||||
EOF
|
||||
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
@@ -38,8 +38,8 @@ const (
|
||||
|
||||
envMongoDBStandalonePort = "TEST_MONGODB_STANDALONE_PORT"
|
||||
//
|
||||
envMongoDBUser = "TEST_MONGODB_ADMIN_USERNAME"
|
||||
envMongoDBPassword = "TEST_MONGODB_ADMIN_PASSWORD"
|
||||
envMongoDBUser = ""
|
||||
envMongoDBPassword = ""
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -86,9 +86,9 @@ var (
|
||||
// MongoDBMongosPort mongos port
|
||||
MongoDBMongosPort = getEnvDefault(envMongoDBMongosPort, "17000")
|
||||
// MongoDBUser username for all instances
|
||||
MongoDBUser = getEnvDefault(envMongoDBUser, "admin")
|
||||
MongoDBUser = getEnvDefault(envMongoDBUser, "")
|
||||
// MongoDBPassword password for all instances
|
||||
MongoDBPassword = getEnvDefault(envMongoDBPassword, "admin123456")
|
||||
MongoDBPassword = getEnvDefault(envMongoDBPassword, "")
|
||||
// MongoDBTimeout global connection timeout
|
||||
MongoDBTimeout = time.Duration(10) * time.Second
|
||||
|
||||
@@ -196,11 +196,13 @@ func TestClient(ctx context.Context, port string) (*mongo.Client, error) {
|
||||
ConnectTimeout: &to,
|
||||
Hosts: []string{net.JoinHostPort(hostname, port)},
|
||||
Direct: &direct,
|
||||
Auth: &options.Credential{
|
||||
}
|
||||
if MongoDBUser != "" {
|
||||
co.Auth = &options.Credential{
|
||||
Username: MongoDBUser,
|
||||
Password: MongoDBPassword,
|
||||
PasswordSet: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
client, err := mongo.Connect(ctx, co)
|
||||
@@ -215,3 +217,27 @@ func TestClient(ctx context.Context, port string) (*mongo.Client, error) {
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func TestClientOptions(port string) *options.ClientOptions {
|
||||
if port == "" {
|
||||
port = MongoDBShard1PrimaryPort
|
||||
}
|
||||
|
||||
hostname := "127.0.0.1"
|
||||
direct := true
|
||||
to := time.Second
|
||||
co := &options.ClientOptions{
|
||||
ConnectTimeout: &to,
|
||||
Hosts: []string{net.JoinHostPort(hostname, port)},
|
||||
Direct: &direct,
|
||||
}
|
||||
if MongoDBUser != "" {
|
||||
co.Auth = &options.Credential{
|
||||
Username: MongoDBUser,
|
||||
Password: MongoDBPassword,
|
||||
PasswordSet: true,
|
||||
}
|
||||
}
|
||||
|
||||
return co
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package explain
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
@@ -14,8 +13,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
|
||||
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
|
||||
"github.com/percona/percona-toolkit/src/go/lib/tutil"
|
||||
@@ -42,20 +39,13 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestExplain(t *testing.T) {
|
||||
t.Skip("Will be fixed in another branch")
|
||||
t.Parallel()
|
||||
|
||||
uri := fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort)
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get a new MongoDB client: %s", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
|
||||
client, err := tu.TestClient(ctx, tu.MongoDBMongosPort)
|
||||
dir := vars.RootPath + samples + "/doc/out/"
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package profiler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -14,9 +13,8 @@ import (
|
||||
"github.com/percona/percona-toolkit/src/go/mongolib/stats"
|
||||
"github.com/percona/percona-toolkit/src/go/pt-mongodb-query-digest/filter"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -44,17 +42,9 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestRegularIterator(t *testing.T) {
|
||||
uri := fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort)
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot create a new MongoDB client: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if err := client.Connect(ctx); err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
client, err := tu.TestClient(ctx, tu.MongoDBShard1PrimaryPort)
|
||||
require.NoError(t, err)
|
||||
|
||||
database := "test"
|
||||
// Disable the profiler and drop the db. This should also remove the system.profile collection
|
||||
@@ -67,7 +57,7 @@ func TestRegularIterator(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// re-enable the profiler
|
||||
res = client.Database("admin").RunCommand(ctx, primitive.D{{"profile", 2}, {"slowms", 2}})
|
||||
res = client.Database("test").RunCommand(ctx, primitive.D{{"profile", 2}, {"slowms", 0}})
|
||||
if res.Err() != nil {
|
||||
t.Fatalf("Cannot enable profiler: %s", res.Err())
|
||||
}
|
||||
|
||||
@@ -3,110 +3,70 @@ package util
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func TestGetHostnames(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
want []string
|
||||
port string
|
||||
want int
|
||||
wantError bool
|
||||
}{
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s",
|
||||
tu.MongoDBUser,
|
||||
tu.MongoDBPassword,
|
||||
tu.MongoDBHost,
|
||||
tu.MongoDBMongosPort,
|
||||
),
|
||||
want: []string{"127.0.0.1:17001", "127.0.0.1:17002", "127.0.0.1:17004", "127.0.0.1:17005", "127.0.0.1:17007"},
|
||||
name: "from_mongos",
|
||||
port: tu.MongoDBMongosPort,
|
||||
want: 9,
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s",
|
||||
tu.MongoDBUser,
|
||||
tu.MongoDBPassword,
|
||||
tu.MongoDBHost,
|
||||
tu.MongoDBShard1PrimaryPort,
|
||||
),
|
||||
want: []string{"127.0.0.1:17001", "127.0.0.1:17002", "127.0.0.1:17003"},
|
||||
name: "from_mongod",
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
want: 3,
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s",
|
||||
tu.MongoDBUser,
|
||||
tu.MongoDBPassword,
|
||||
tu.MongoDBHost,
|
||||
tu.MongoDBShard3PrimaryPort,
|
||||
),
|
||||
want: []string{"127.0.0.1:17021", "127.0.0.1:17022", "127.0.0.1:17023"},
|
||||
wantError: false,
|
||||
},
|
||||
{
|
||||
name: "from_standalone",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s",
|
||||
tu.MongoDBUser,
|
||||
tu.MongoDBPassword,
|
||||
tu.MongoDBHost,
|
||||
tu.MongoDBStandalonePort,
|
||||
),
|
||||
want: nil,
|
||||
name: "from_standalone",
|
||||
port: tu.MongoDBStandalonePort,
|
||||
want: 0,
|
||||
wantError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
uri := test.uri
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for i, test := range testCases {
|
||||
port := test.port
|
||||
want := test.want
|
||||
wantError := test.wantError
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get a new MongoDB client: %s", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
client, err := tu.TestClient(ctx, port)
|
||||
require.NoError(t, err)
|
||||
|
||||
hostnames, err := GetHostnames(ctx, client)
|
||||
if err != nil && !wantError {
|
||||
t.Errorf("Expecting error=nil, got: %v", err)
|
||||
t.Errorf("%d) Expecting error=nil, got: %v", i, err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(hostnames, want) {
|
||||
t.Errorf("Invalid hostnames. Got: %+v, want %+v", hostnames, want)
|
||||
}
|
||||
require.Equal(t, want, len(hostnames))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServerStatus(t *testing.T) {
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://admin:admin123456@127.0.0.1:17001"))
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get a new MongoDB client: %s", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
client, err := tu.TestClient(ctx, tu.MongoDBShard1PrimaryPort)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = GetServerStatus(ctx, client)
|
||||
if err != nil {
|
||||
@@ -117,41 +77,38 @@ func TestGetServerStatus(t *testing.T) {
|
||||
func TestGetReplicasetMembers(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
port string
|
||||
want int
|
||||
wantErr bool
|
||||
}{
|
||||
/* Replication is not enabled in the current sandbox
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort),
|
||||
port: tu.MongoDBMongosPort,
|
||||
want: 7,
|
||||
wantErr: false,
|
||||
},
|
||||
*/
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort),
|
||||
want: 3,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard3PrimaryPort),
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
want: 3,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "from_standalone",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBStandalonePort),
|
||||
port: tu.MongoDBStandalonePort,
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
clientOptions := options.Client().ApplyURI(test.uri)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
clientOptions := tu.TestClientOptions(test.port)
|
||||
|
||||
rsm, err := GetReplicasetMembers(ctx, clientOptions)
|
||||
if err != nil && !test.wantErr {
|
||||
@@ -167,46 +124,44 @@ func TestGetReplicasetMembers(t *testing.T) {
|
||||
func TestGetShardedHosts(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
port string
|
||||
want int
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort),
|
||||
port: tu.MongoDBMongosPort,
|
||||
want: 2,
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort),
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
want: 0,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard3PrimaryPort),
|
||||
port: tu.MongoDBShard3PrimaryPort,
|
||||
want: 0,
|
||||
err: true,
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range testCases {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
clientOptions := options.Client().ApplyURI(test.uri)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
clientOptions := tu.TestClientOptions(test.port)
|
||||
|
||||
client, err := mongo.NewClient(clientOptions)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot get a new client for host %s: %s", test.uri, err)
|
||||
}
|
||||
if client == nil {
|
||||
t.Fatalf("mongodb client is nil i: %d, uri: %s\n", i, test.uri)
|
||||
t.Errorf("Cannot get a new client for host at port %s: %s", test.port, err)
|
||||
}
|
||||
|
||||
if err := client.Connect(ctx); err != nil {
|
||||
t.Errorf("Cannot connect to host %s: %s", test.uri, err)
|
||||
t.Errorf("Cannot connect to host at port %s: %s", test.port, err)
|
||||
}
|
||||
|
||||
rsm, err := GetShardedHosts(ctx, client)
|
||||
@@ -221,6 +176,8 @@ func TestGetShardedHosts(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReplicasetConfig(t *testing.T) {
|
||||
t.Skip("current sandbox doesn't support replicasets")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
@@ -11,44 +10,35 @@ import (
|
||||
"github.com/pborman/getopt"
|
||||
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
|
||||
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func TestGetHostInfo(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
port string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort),
|
||||
port: tu.MongoDBMongosPort,
|
||||
want: []string{"127.0.0.1:17001", "127.0.0.1:17002", "127.0.0.1:17004", "127.0.0.1:17005", "127.0.0.1:17007"},
|
||||
},
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort),
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
want: []string{"127.0.0.1:17001", "127.0.0.1:17002", "127.0.0.1:17003"},
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard3PrimaryPort),
|
||||
want: []string{"127.0.0.1:17021", "127.0.0.1:17022", "127.0.0.1:17023"},
|
||||
},
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(test.uri))
|
||||
client, err := tu.TestClient(ctx, test.port)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get a new MongoDB client: %s", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
|
||||
_, err = getHostInfo(ctx, client)
|
||||
if err != nil {
|
||||
@@ -61,37 +51,30 @@ func TestGetHostInfo(t *testing.T) {
|
||||
func TestClusterWideInfo(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
port string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort),
|
||||
port: tu.MongoDBMongosPort,
|
||||
want: []string{"127.0.0.1:17001", "127.0.0.1:17002", "127.0.0.1:17004", "127.0.0.1:17005", "127.0.0.1:17007"},
|
||||
},
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort),
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
want: []string{"127.0.0.1:17001", "127.0.0.1:17002", "127.0.0.1:17003"},
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard3PrimaryPort),
|
||||
want: []string{"127.0.0.1:17021", "127.0.0.1:17022", "127.0.0.1:17023"},
|
||||
},
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(test.uri))
|
||||
client, err := tu.TestClient(ctx, test.port)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get a new MongoDB client: %s", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
|
||||
_, err = getClusterwideInfo(ctx, client)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,54 +2,42 @@ package oplog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
func TestGetOplogCollection(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
port string
|
||||
want string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort),
|
||||
port: tu.MongoDBMongosPort,
|
||||
want: "",
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort),
|
||||
want: "oplog.rs",
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard3PrimaryPort),
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
want: "oplog.rs",
|
||||
err: false,
|
||||
},
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
client, err := mongo.NewClient(options.Client().ApplyURI(test.uri))
|
||||
client, err := tu.TestClient(ctx, test.port)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get a new MongoDB client: %s", err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
err = client.Connect(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot connect to MongoDB: %s", err)
|
||||
}
|
||||
|
||||
oplogCol, err := getOplogCollection(ctx, client)
|
||||
if (err != nil) != test.err {
|
||||
@@ -65,37 +53,30 @@ func TestGetOplogCollection(t *testing.T) {
|
||||
func TestGetOplogInfo(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
uri string
|
||||
port string
|
||||
wantHost bool
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
name: "from_mongos",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBMongosPort),
|
||||
port: tu.MongoDBMongosPort,
|
||||
wantHost: false,
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
name: "from_mongod",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard1PrimaryPort),
|
||||
wantHost: true,
|
||||
err: false,
|
||||
},
|
||||
{
|
||||
name: "from_non_sharded",
|
||||
uri: fmt.Sprintf("mongodb://%s:%s@%s:%s", tu.MongoDBUser, tu.MongoDBPassword, tu.MongoDBHost, tu.MongoDBShard3PrimaryPort),
|
||||
port: tu.MongoDBShard1PrimaryPort,
|
||||
wantHost: true,
|
||||
err: false,
|
||||
},
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
clientOptions := options.Client().ApplyURI(test.uri)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
|
||||
oplogInfo, err := GetOplogInfo(ctx, clientOptions.Hosts, clientOptions)
|
||||
oplogInfo, err := GetOplogInfo(ctx, []string{"127.0.0.1:" + test.port}, tu.TestClientOptions(test.port))
|
||||
if (err != nil) != test.err {
|
||||
t.Errorf("Expected error=%v, got %v", test.err, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user