Skip to content

Commit a96ef54

Browse files
authored
Merge pull request #8 from BinaryIgor/mysql-tests
MySQL & MariaDB support
2 parents 3d1a5a4 + c6f9c72 commit a96ef54

27 files changed

Lines changed: 401 additions & 77 deletions

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ them:
127127
```java
128128

129129
import com.binaryigor.eventsql.EventSQL;
130-
// dialect of your events backend - POSTGRES, MYSQL, MARIADB;
131-
// as of now, only POSTGRES has fully tested support, but should work on others as well
130+
// dialect of your events backend - POSTGRES, MYSQL and MARIADB are supported, as of now
132131
import com.binaryigor.eventsql.EventSQLDialect;
133132
import javax.sql.DataSource;
134133

benchmarks/app/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
<spring.openapi.version>2.2.0</spring.openapi.version>
2424
<postresql.driver.version>42.7.5</postresql.driver.version>
25+
<mysql.driver.version>9.1.0</mysql.driver.version>
26+
<mariadb.driver.version>3.5.3</mariadb.driver.version>
2527
</properties>
2628

2729

@@ -61,6 +63,16 @@
6163
<artifactId>postgresql</artifactId>
6264
<version>${postresql.driver.version}</version>
6365
</dependency>
66+
<dependency>
67+
<groupId>com.mysql</groupId>
68+
<artifactId>mysql-connector-j</artifactId>
69+
<version>${mysql.driver.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.mariadb.jdbc</groupId>
73+
<artifactId>mariadb-java-client</artifactId>
74+
<version>${mariadb.driver.version}</version>
75+
</dependency>
6476

6577
<dependency>
6678
<groupId>org.springframework.boot</groupId>

benchmarks/app/src/main/java/com/binaryigor/eventsql/benchmarks/EventSQLBenchmarksApp.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.binaryigor.eventsql.benchmarks;
22

33
import com.binaryigor.eventsql.EventSQL;
4-
import com.binaryigor.eventsql.EventSQLDialect;
54
import com.zaxxer.hikari.HikariConfig;
65
import com.zaxxer.hikari.HikariDataSource;
76
import org.springframework.boot.SpringApplication;
@@ -25,7 +24,7 @@ EventSQL eventSQL(EventsProperties eventsProperties) {
2524
.filter(EventsProperties.DataSourceProperties::enabled)
2625
.map(this::dataSource)
2726
.toList();
28-
return new EventSQL(dataSources, EventSQLDialect.POSTGRES);
27+
return new EventSQL(dataSources, eventsProperties.sqlDialect());
2928
}
3029

3130
private DataSource dataSource(EventsProperties.DataSourceProperties properties) {
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.binaryigor.eventsql.benchmarks;
22

33
import com.binaryigor.eventsql.ConsumerDefinition;
4+
import com.binaryigor.eventsql.EventSQLDialect;
45
import com.binaryigor.eventsql.TopicDefinition;
56
import org.springframework.boot.context.properties.ConfigurationProperties;
67

@@ -10,8 +11,13 @@
1011
public record EventsProperties(TopicDefinition accountCreatedTopic,
1112
TopicDefinition accountCreatedTopicDlt,
1213
List<ConsumerDefinition> accountCreatedConsumers,
13-
List<DataSourceProperties> dataSources) {
14+
List<DataSourceProperties> dataSources,
15+
EventSQLDialect sqlDialect) {
1416

15-
record DataSourceProperties(String url, String username, String password, int connections, boolean enabled) {
17+
record DataSourceProperties(String url,
18+
String username,
19+
String password,
20+
int connections,
21+
boolean enabled) {
1622
}
1723
}

benchmarks/app/src/main/resources/application.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ events:
2222
password: "${DB0_PASSWORD:events}"
2323
connections: 10
2424
enabled: ${DB0_ENABLED:true}
25-
- url: "${DB1_URL:jdbc:postgresql://localhost:5433/events}"
25+
- url: "${DB1_URL:jdbc:postgresql://localhost:5432/events}"
2626
username: "${DB1_USERNAME:events}"
2727
password: "${DB1_PASSWORD:events}"
2828
connections: 10
2929
enabled: ${DB1_ENABLED:false}
30-
- url: "${DB2_URL:jdbc:postgresql://localhost:5434/events}"
30+
- url: "${DB2_URL:jdbc:postgresql://localhost:5432/events}"
3131
username: "${DB2_USERNAME:events}"
3232
password: "${DB2_PASSWORD:events}"
3333
connections: 10
3434
enabled: ${DB2_ENABLED:false}
35+
sql-dialect: "${SQL_DIALECT:POSTGRES}"
3536
account-created-topic:
3637
name: "account_created"
3738
partitions: 10
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM mariadb:10.11
2+
COPY init_db.sql /docker-entrypoint-initdb.d/init_db.sql
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
app="events-db-mariadb"
5+
6+
tag="${TAG:-latest}"
7+
tagged_image="${app}:${tag}"
8+
volume_dir="${EVENTS_DB_VOLUME_DIR:-/home/eventsql/${app}_volume}"
9+
volume="-v $volume_dir:/var/lib/mysql"
10+
memory_limit="${MEMORY_LIMIT:-8G}"
11+
cpus_limit="${CPUS_LIMIT:-4}"
12+
13+
echo "Creating package in dist directory for $tagged_image image..."
14+
echo "Preparing dist dir..."
15+
16+
rm -r -f dist
17+
mkdir dist
18+
19+
echo "Building image..."
20+
21+
docker build . -t "$tagged_image"
22+
23+
gzipped_image_path="dist/$app.tar.gz"
24+
25+
echo "Image built, exporting it to $gzipped_image_path, this can take a while..."
26+
27+
docker save "$tagged_image" | gzip > "$gzipped_image_path"
28+
29+
echo "Image exported, preparing scripts..."
30+
31+
export app=$app
32+
export tag=$tag
33+
export run_cmd="docker run -d \\
34+
-e \"MARIADB_ROOT_PASSWORD=mariadb\" \\
35+
--memory ${memory_limit} --cpus ${cpus_limit} \
36+
--network host ${volume} --name $app $tagged_image"
37+
38+
cd ..
39+
envsubst '${app} ${tag}' < scripts/template_load_and_run_app.bash > "$app/dist/load_and_run_app.bash"
40+
envsubst '${app} ${run_cmd}' < scripts/template_run_app.bash > "$app/dist/run_app.bash"
41+
42+
echo "Package prepared."
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE DATABASE events;
2+
3+
CREATE USER 'events' IDENTIFIED BY 'events';
4+
GRANT ALL PRIVILEGES ON events.* TO 'events';
5+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM mysql:9.1
2+
COPY init_db.sql /docker-entrypoint-initdb.d/init_db.sql
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
app="events-db-mysql"
5+
6+
tag="${TAG:-latest}"
7+
tagged_image="${app}:${tag}"
8+
volume_dir="${EVENTS_DB_VOLUME_DIR:-/home/eventsql/${app}_volume}"
9+
volume="-v $volume_dir:/var/lib/mysql"
10+
memory_limit="${MEMORY_LIMIT:-8G}"
11+
cpus_limit="${CPUS_LIMIT:-4}"
12+
13+
echo "Creating package in dist directory for $tagged_image image..."
14+
echo "Preparing dist dir..."
15+
16+
rm -r -f dist
17+
mkdir dist
18+
19+
echo "Building image..."
20+
21+
docker build . -t "$tagged_image"
22+
23+
gzipped_image_path="dist/$app.tar.gz"
24+
25+
echo "Image built, exporting it to $gzipped_image_path, this can take a while..."
26+
27+
docker save "$tagged_image" | gzip > "$gzipped_image_path"
28+
29+
echo "Image exported, preparing scripts..."
30+
31+
export app=$app
32+
export tag=$tag
33+
export run_cmd="docker run -d \\
34+
-e \"MYSQL_ROOT_PASSWORD=mysql\" \\
35+
--memory ${memory_limit} --cpus ${cpus_limit} \
36+
--network host ${volume} --name $app $tagged_image"
37+
38+
cd ..
39+
envsubst '${app} ${tag}' < scripts/template_load_and_run_app.bash > "$app/dist/load_and_run_app.bash"
40+
envsubst '${app} ${run_cmd}' < scripts/template_run_app.bash > "$app/dist/run_app.bash"
41+
42+
echo "Package prepared."

0 commit comments

Comments
 (0)