Skip to content

Commit 4f36e74

Browse files
committed
refactor integration test & add e2e test
1 parent a267376 commit 4f36e74

File tree

13 files changed

+193
-68
lines changed

13 files changed

+193
-68
lines changed

ci/docker-compose.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,43 @@ services:
210210
interval: 5s
211211
timeout: 5s
212212
retries: 5
213+
214+
mongodb:
215+
image: mongo:4.4
216+
container_name: mongodb
217+
ports:
218+
- "27017:27017"
219+
command: --replSet rs0 --oplogSize 128
220+
restart: always
221+
healthcheck:
222+
test: "echo 'db.runCommand({ping: 1})' | mongo"
223+
interval: 5s
224+
timeout: 10s
225+
retries: 3
226+
227+
mongodb-setup:
228+
image: mongo:4.4
229+
container_name: mongodb-setup
230+
depends_on:
231+
- mongodb
232+
entrypoint:
233+
[
234+
"bash",
235+
"-c",
236+
"sleep 10 && mongo --host mongodb:27017 /config-replica.js && sleep 10"
237+
]
238+
restart: "no"
239+
volumes:
240+
- ./mongodb/config-replica.js:/config-replica.js
241+
242+
mongo_data_generator:
243+
build:
244+
context: .
245+
dockerfile: ./mongodb/Dockerfile.generator
246+
container_name: mongo_data_generator
247+
depends_on:
248+
- mongodb
249+
environment:
250+
MONGO_HOST: mongodb
251+
MONGO_PORT: 27017
252+
MONGO_DB_NAME: random_data

ci/mongodb/Dockerfile.generator

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.8-slim
3+
4+
# Set the working directory to /app
5+
WORKDIR /app
6+
7+
# Copy the requirements file into the container at /app
8+
COPY ./mongodb/requirements.txt /app
9+
COPY ./mongodb/app.py /app
10+
11+
# Install any needed packages specified in requirements.txt
12+
RUN pip install -r requirements.txt
13+
14+
# Make port 5000 available to the world outside this container
15+
EXPOSE 5000
16+
17+
# Define environment variables
18+
ENV MONGO_HOST mongodb
19+
ENV MONGO_PORT 27017
20+
ENV MONGO_DB_NAME random_data
21+
22+
# Run app.py when the container launches
23+
CMD ["python", "app.py"]
File renamed without changes.

ci/mongodb/config-replica.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rsconf = {
2+
_id: "rs0",
3+
members: [{ _id: 0, host: "mongodb:27017", priority: 1.0 }],
4+
};
5+
rs.initiate(rsconf);
6+
rs.status();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CDC source basic test
2+
control substitution on
3+
4+
statement ok
5+
CREATE TABLE users (_id JSONB PRIMARY KEY, payload JSONB) WITH (
6+
connector = 'mongodb-cdc',
7+
mongodb.url = 'mongodb://mongodb:27017/?replicaSet=rs0',
8+
collection.name = 'random_data.*'
9+
);
10+
11+
statement ok
12+
CREATE MATERIALIZED VIEW normalized_users AS
13+
SELECT
14+
payload ->> 'name' as name,
15+
payload ->> 'email' as email,
16+
payload ->> 'address' as address
17+
FROM
18+
users;
19+
20+
sleep 5s;
21+
22+
query I
23+
select count(*) from normalized_users;
24+
----
25+
1000

integration_tests/debezium-mongo/docker-compose.yaml

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,12 @@ services:
2828
service: message_queue
2929

3030
mongodb:
31-
image: mongo:4.4
32-
container_name: mongodb
33-
ports:
34-
- "27017:27017"
35-
command: --replSet rs0 --oplogSize 128
36-
restart: always
37-
healthcheck:
38-
test: "echo 'db.runCommand({ping: 1})' | mongo"
39-
interval: 5s
40-
timeout: 10s
41-
retries: 3
31+
extends: ../mongodb/docker-compose.yaml
32+
service: mongodb
4233

4334
mongodb-setup:
44-
image: mongo:4.4
45-
container_name: mongodb-setup
46-
depends_on:
47-
- mongodb
48-
entrypoint:
49-
[
50-
"bash",
51-
"-c",
52-
"sleep 10 && mongo --host mongodb:27017 /config-replica.js && sleep 10"
53-
]
54-
restart: "no"
55-
volumes:
56-
- ./config-replica.js:/config-replica.js
35+
extends: ../mongodb/docker-compose.yaml
36+
service: mongodb-setup
5737

5838
debezium:
5939
image: debezium/connect:1.9
@@ -78,16 +58,9 @@ services:
7858
CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://message_queue:8081
7959

8060
random_data_generator:
81-
build:
82-
context: .
83-
dockerfile: Dockerfile.generator
84-
container_name: random_data_generator
85-
depends_on:
86-
- mongodb
87-
environment:
88-
MONGO_HOST: mongodb
89-
MONGO_PORT: 27017
90-
MONGO_DB_NAME: random_data
61+
extends: ../mongodb/docker-compose.yaml
62+
service: random_data_generator
63+
9164

9265
register-mongodb-connector:
9366
image: curlimages/curl:7.79.1

integration_tests/mongodb-cdc/docker-compose.yaml

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,14 @@ version: '3.1'
22

33
services:
44
mongodb:
5-
image: mongodb/mongodb-community-server:4.4.23-ubi8
6-
container_name: mongodb
7-
ports:
8-
- "27017:27017"
9-
command: --replSet rs0 --oplogSize 128
10-
restart: always
11-
healthcheck:
12-
test: "echo 'db.runCommand({ping: 1})' | mongo"
13-
interval: 5s
14-
timeout: 10s
15-
retries: 3
5+
extends: ../mongodb/docker-compose.yaml
6+
service: mongodb
167

178
mongodb-setup:
18-
image: mongodb/mongodb-community-server:4.4.23-ubi8
19-
container_name: mongodb-setup
20-
depends_on:
21-
- mongodb
22-
entrypoint:
23-
[
24-
"bash",
25-
"-c",
26-
"sleep 10 && mongo --host mongodb:27017 /config-replica.js && sleep 10"
27-
]
28-
restart: "no"
29-
volumes:
30-
- ./config-replica.js:/config-replica.js
9+
extends: ../mongodb/docker-compose.yaml
10+
service: mongodb-setup
3111

3212
random_data_generator:
33-
build:
34-
context: .
35-
dockerfile: Dockerfile.generator
36-
container_name: random_data_generator
37-
depends_on:
38-
- mongodb
39-
environment:
40-
MONGO_HOST: mongodb
41-
MONGO_PORT: 27017
42-
MONGO_DB_NAME: random_data
13+
extends: ../mongodb/docker-compose.yaml
14+
service: random_data_generator
15+

integration_tests/mongodb/app.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
import pymongo
3+
from faker import Faker
4+
5+
# To check the data through mongosh or mongo, run the following command:
6+
# > mongosh mongodb://admin:[email protected]:27017
7+
# > rs0 [direct: primary] test> use random_data
8+
# > rs0 [direct: primary] random_data> db.users.find()
9+
# > rs0 [direct: primary] random_data> db.users.count()
10+
11+
# Connect to MongoDB
12+
mongo_host = os.environ["MONGO_HOST"]
13+
mongo_port = os.environ["MONGO_PORT"]
14+
mongo_db_name = os.environ["MONGO_DB_NAME"]
15+
16+
url = f"mongodb://{mongo_host}:{mongo_port}"
17+
client = pymongo.MongoClient(url)
18+
db = client[mongo_db_name]
19+
20+
# Generate random data
21+
fake = Faker()
22+
collection = db["users"]
23+
24+
for _ in range(1000):
25+
user_data = {
26+
"name": fake.name(),
27+
"address": fake.address(),
28+
"email": fake.email(),
29+
}
30+
collection.insert_one(user_data)
31+
32+
# Count the number of records in the collection
33+
total_records = collection.count_documents({})
34+
35+
# Close the MongoDB connection
36+
client.close()
37+
print(f"Random data generated and inserted into MongoDB: {url}")
38+
39+
# Print insertion summary
40+
print("Insertion summary:")
41+
print(f"Total records in the collection: {total_records}")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '3.1'
2+
3+
services:
4+
mongodb:
5+
image: mongo:4.4
6+
container_name: mongodb
7+
ports:
8+
- "27017:27017"
9+
command: --replSet rs0 --oplogSize 128
10+
restart: always
11+
healthcheck:
12+
test: "echo 'db.runCommand({ping: 1})' | mongo"
13+
interval: 5s
14+
timeout: 10s
15+
retries: 3
16+
17+
mongodb-setup:
18+
image: mongo:4.4
19+
container_name: mongodb-setup
20+
depends_on:
21+
- mongodb
22+
entrypoint:
23+
[
24+
"bash",
25+
"-c",
26+
"sleep 10 && mongo --host mongodb:27017 /config-replica.js && sleep 10"
27+
]
28+
restart: "no"
29+
volumes:
30+
- ./config-replica.js:/config-replica.js
31+
32+
random_data_generator:
33+
build:
34+
context: .
35+
dockerfile: Dockerfile.generator
36+
container_name: random_data_generator
37+
depends_on:
38+
- mongodb
39+
environment:
40+
MONGO_HOST: mongodb
41+
MONGO_PORT: 27017
42+
MONGO_DB_NAME: random_data
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pymongo
2+
Faker

0 commit comments

Comments
 (0)