Skip to content

Commit ba43a9f

Browse files
committed
Add docker-compose
1 parent f780759 commit ba43a9f

File tree

3 files changed

+108
-4
lines changed

3 files changed

+108
-4
lines changed

docker-compose/docker-compose.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
version: '3'
2+
3+
services:
4+
mongo:
5+
image: 'mongo:4.2.16-bionic'
6+
ports:
7+
- "27017:27017"
8+
environment:
9+
MONGO_INITDB_DATABASE: oauth2
10+
MONGO_INITDB_ROOT_USERNAME: admin
11+
MONGO_INITDB_ROOT_PASSWORD: password
12+
volumes:
13+
- ./db-oauth/mongo-single/:/data/db
14+
15+
#version: '3.9'
16+
#
17+
## if mongo V4, at the first deploy, log into a node and run manually run this
18+
## rs.initiate( {
19+
## _id : "myReplicaSet",
20+
## members: [
21+
## { _id: 0, host: "mongo1:27017", priority: 2 },
22+
## { _id: 1, host: "mongo2:27017", priority: 1 },
23+
## { _id: 2, host: "mongo3:27017", priority: 1 }
24+
## ]
25+
## })
26+
#
27+
## for linux, in /etc/hosts add 127.0.0.1 localhost mongo1 mongo2 mongo3
28+
#
29+
## optional: for 2 secondary nodes
30+
## run this in case you log into a secondary node and want to access the collections
31+
## rs.secondaryOk()
32+
#
33+
#services:
34+
# mongo1:
35+
# image: mongo:4.2
36+
# # image: mongo:5
37+
# hostname: mongo1
38+
# ports:
39+
# - "27017:27017"
40+
# environment:
41+
# MONGO_INITDB_DATABASE: oauth2
42+
# # MONGO_INITDB_ROOT_USERNAME: admin
43+
# # MONGO_INITDB_ROOT_PASSWORD: password
44+
# volumes:
45+
# - ./db-oauth/mongo1/:/data/db
46+
# healthcheck:
47+
# test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/admin --quiet
48+
# interval: 2s
49+
# timeout: 3s
50+
# retries: 5
51+
# entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "myReplicaSet" ]
52+
#
53+
# mongo2:
54+
# image: mongo:4.2
55+
# # image: mongo:5
56+
# hostname: mongo2
57+
# ports:
58+
# - "28017:27017"
59+
# environment:
60+
# MONGO_INITDB_DATABASE: oauth2
61+
# volumes:
62+
# - ./db-oauth/mongo2/:/data/db
63+
# healthcheck:
64+
# test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/admin --quiet
65+
# interval: 2s
66+
# timeout: 3s
67+
# retries: 5
68+
# entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "myReplicaSet" ]
69+
#
70+
# mongo3:
71+
# image: mongo:4.2
72+
# # image: mongo:5
73+
# hostname: mongo3
74+
# ports:
75+
# - "29017:27017"
76+
# environment:
77+
# MONGO_INITDB_DATABASE: oauth2
78+
# depends_on:
79+
# mongo1:
80+
# condition: service_healthy
81+
# mongo2:
82+
# condition: service_healthy
83+
# volumes:
84+
# - ./db-oauth/mongo3/:/data/db
85+
# - ./scripts/init.js:/scripts/init.js
86+
# entrypoint:
87+
# - bash
88+
# - "-c"
89+
# - |
90+
# /usr/bin/mongod --bind_ip_all --replSet myReplicaSet &&
91+
# sleep 5 &&
92+
# mongo --host mongo1:27017 /scripts/init.js
93+

docker-compose/scripts/init.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// for mongo v4
2+
rs.initiate( {
3+
_id : "myReplicaSet",
4+
members: [
5+
{ _id: 0, host: "mongo1:27017", priority: 2 },
6+
{ _id: 1, host: "mongo2:27017", priority: 1 },
7+
{ _id: 2, host: "mongo3:27017", priority: 1 }
8+
]
9+
})
10+
11+
12+

transaction_handler_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ func TestTransaction(t *testing.T) {
4444

4545
storeConfig := NewStoreConfig(1, 5)
4646

47-
var store *TokenStore
48-
if !isReplicaSet {
49-
store = NewTokenStore(NewConfigNonReplicaSet(url, dbName, username, password, service), storeConfig)
50-
} else {
47+
if isReplicaSet {
5148
t.Skip("Skipping the test as it is a replica set.")
5249
}
5350

51+
store := NewTokenStore(NewConfigNonReplicaSet(url, dbName, username, password, service), storeConfig)
52+
5453
store.txnHandler.tw = &mockTransactionWorker{}
5554

5655
Convey("Test mongodb token store", t, func() {

0 commit comments

Comments
 (0)