Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/integration-tests-r2dbc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,112 @@ jobs:
- name: Print logs on failure
if: ${{ failure() }}
run: find . -name "*.log" -exec ./scripts/cat-log.sh {} \;

mariadb-test:
name: Build and Test Integration for R2DBC with MariaDB
runs-on: ubuntu-22.04
if: github.repository == 'apache/pekko-projection'
strategy:
fail-fast: false
matrix:
include:
- { java-version: 17, scala-version: 2.13, sbt-opts: '' }
- { java-version: 17, scala-version: next, sbt-opts: '' }

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
fetch-tags: true

- name: Checkout GitHub merge
if: github.event.pull_request
run: |-
git fetch origin pull/${{ github.event.pull_request.number }}/merge:scratch
git checkout scratch

- name: Cache Coursier cache
uses: coursier/cache-action@057d08c2f9a2c4e7a4d33df3aae657b7db88b8cc # v8.2.0

- name: Setup JDK ${{ matrix.java-version }}
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
java-version: ${{ matrix.java-version }}
distribution: temurin

- name: Install sbt
uses: sbt/setup-sbt@ecad189dd245444b9ae0a0cd5922fd938b88906f # v1.5.12

- name: Start MariaDB
run: |-
docker compose -f docker-files/docker-compose-mariadb.yml up -d --wait
# loop to wait for the DB to be ready
for i in {1..8}; do
if docker exec -i docker-mariadb-db-1 mariadb \
-h 127.0.0.1 --user=root --password=root --database=mysql -e 'SELECT 1;' 2>/dev/null; then
break
fi
echo "Retry $i: SQL check failed, waiting before retry..."
sleep $((i * 2))
done
docker exec -i docker-mariadb-db-1 mariadb -h 127.0.0.1 --user=root --password=root --database=mysql < r2dbc-int-test/ddl-scripts/create_tables_mysql.sql
docker exec -i docker-mariadb-db-1 mariadb -h 127.0.0.1 --user=root --password=root -e 'CREATE SCHEMA database1;'
docker exec -i docker-mariadb-db-1 mariadb -h 127.0.0.1 --user=root --password=root --database=database1 < r2dbc-int-test/ddl-scripts/create_tables_mysql.sql
docker exec -i docker-mariadb-db-1 mariadb -h 127.0.0.1 --user=root --password=root -e 'CREATE SCHEMA database2;'
docker exec -i docker-mariadb-db-1 mariadb -h 127.0.0.1 --user=root --password=root --database=database2 < r2dbc-int-test/ddl-scripts/create_tables_mysql.sql

- name: test
run: |-
scala_version="$(bash .github/scripts/resolve-scala-version.sh "${{ matrix.scala-version }}")"
sbt -Dpekko.persistence.r2dbc.dialect=mariadb -Dpekko.projection.r2dbc.dialect=mariadb "++${scala_version}!" "r2dbc-int-test/test" ${{ matrix.sbt-opts }}

- name: Print logs on failure
if: ${{ failure() }}
run: find . -name "*.log" -exec ./scripts/cat-log.sh {} \;

h2-test:
name: Build and Test Integration for R2DBC with H2
runs-on: ubuntu-22.04
if: github.repository == 'apache/pekko-projection'
strategy:
fail-fast: false
matrix:
include:
- { java-version: 17, scala-version: 2.13, sbt-opts: '' }
- { java-version: 17, scala-version: next, sbt-opts: '' }

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
fetch-tags: true

- name: Checkout GitHub merge
if: github.event.pull_request
run: |-
git fetch origin pull/${{ github.event.pull_request.number }}/merge:scratch
git checkout scratch

- name: Cache Coursier cache
uses: coursier/cache-action@057d08c2f9a2c4e7a4d33df3aae657b7db88b8cc # v8.2.0

- name: Setup JDK ${{ matrix.java-version }}
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
java-version: ${{ matrix.java-version }}
distribution: temurin

- name: Install sbt
uses: sbt/setup-sbt@ecad189dd245444b9ae0a0cd5922fd938b88906f # v1.5.12

# H2 runs in the test JVM and the projection creates its tables, no database container or schema script
- name: test
run: |-
scala_version="$(bash .github/scripts/resolve-scala-version.sh "${{ matrix.scala-version }}")"
sbt -Dpekko.persistence.r2dbc.dialect=h2 -Dpekko.projection.r2dbc.dialect=h2 "++${scala_version}!" "r2dbc-int-test/test" ${{ matrix.sbt-opts }}

- name: Print logs on failure
if: ${{ failure() }}
run: find . -name "*.log" -exec ./scripts/cat-log.sh {} \;
32 changes: 32 additions & 0 deletions docker-files/docker-compose-mariadb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

services:
mariadb-db:
image: mariadb:12.3.3
container_name: docker-mariadb-db-1
ports:
- 3306:3306
environment:
MARIADB_ROOT_PASSWORD: root
# a server time zone with daylight saving time, so that the tests verify that timestamps are stored in UTC
TZ: America/New_York
healthcheck:
test: [ "CMD", "healthcheck.sh", "--connect", "--innodb_initialized" ]
interval: 1s
timeout: 1s
retries: 60
30 changes: 30 additions & 0 deletions docs/src/main/paradox/r2dbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,36 @@ YugaByte
MySQL
: @@snip [MySQL Schema](/r2dbc-int-test/ddl-scripts/create_tables_mysql.sql)

MariaDB
: @@snip [MySQL Schema](/r2dbc-int-test/ddl-scripts/create_tables_mysql.sql)

H2
: The tables are created automatically, see @ref:[H2](#h2).

### MariaDB

MariaDB 10.11 or later is supported with the `mariadb` dialect and the `org.mariadb:r2dbc-mariadb` driver, see
@extref:[MariaDB in Apache Pekko Persistence R2DBC](pekko-persistence-r2dbc:getting-started.html#mariadb) for how to
configure the connection and the driver dependency.

The offset store uses the same tables as MySQL. The MariaDB driver doesn't support `java.time.Instant`, so the
connection factory of Apache Pekko Persistence R2DBC binds and reads timestamps as `LocalDateTime` in UTC, with a UTC
database session. The same applies to the statements of an `R2dbcHandler` that run on the `R2dbcSession`.

### H2

With the `h2` dialect the database runs in the same JVM process, see
@extref:[H2 in Apache Pekko Persistence R2DBC](pekko-persistence-r2dbc:getting-started.html#h2) for how to configure the
connection and the H2 dependencies.

Like the persistence plugins, a projection creates the offset store tables of its own `offset-store` settings when it is
first used, so no schema script is needed. That includes the `schema` and table names of the projection settings and a
separate `use-connection-factory`. The `projection_offset_store` table is not created when `offset-table` is set to
`""`. The tables are not created when the connection is configured with an H2 `url`.

The database calls of the projection run on the `h2.use-dispatcher` of the connection factory, since the H2 driver
blocks.

## Configuration

By default, `pekko-projection-r2dbc` uses the same connection pool and `dialect` as `pekko-persistence-r2dbc`, see
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.apache.pekko
import pekko.actor.typed.ActorSystem
import pekko.persistence.Persistence
import pekko.persistence.r2dbc.ConnectionFactoryProvider
import pekko.persistence.r2dbc.ConnectionFactorySettings
import pekko.persistence.r2dbc.JournalSettings
import pekko.persistence.r2dbc.internal.R2dbcExecutor
import pekko.projection.r2dbc.R2dbcProjectionSettings
Expand All @@ -40,7 +41,11 @@ trait TestDbLifecycle extends BeforeAndAfterAll { this: Suite =>
new R2dbcExecutor(
ConnectionFactoryProvider(typedSystem).connectionFactoryFor(r2dbcProjectionSettings.useConnectionFactory),
LoggerFactory.getLogger(getClass),
r2dbcProjectionSettings.logDbCallsExceeding)(typedSystem.executionContext, typedSystem)
r2dbcProjectionSettings.logDbCallsExceeding,
ConnectionFactorySettings.closeCallsExceeding(
typedSystem.settings.config.getConfig(r2dbcProjectionSettings.useConnectionFactory)))(
typedSystem.executionContext,
typedSystem)
}

lazy val persistenceExt: Persistence = Persistence(typedSystem)
Expand Down
11 changes: 11 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ object Dependencies {
val r2dbcPool = "io.r2dbc" % "r2dbc-pool" % "1.0.2.RELEASE"
val r2dbcPostgres = "org.postgresql" % "r2dbc-postgresql" % "1.1.3.RELEASE"
val r2dbcMysql = "io.asyncer" % "r2dbc-mysql" % "1.4.3"
// the version that pekko-persistence-r2dbc is built against
val r2dbcMariadb = "org.mariadb" % "r2dbc-mariadb" % "1.3.2" // ApacheV2
val r2dbcH2 = "io.r2dbc" % "r2dbc-h2" % "1.1.0.RELEASE" // ApacheV2
// the H2 version that pekko-persistence-r2dbc is built against
val h2R2dbc = "com.h2database" % "h2" % "2.5.252" // EPL 1.0 or MPL 2.0
}

object Test {
Expand Down Expand Up @@ -114,6 +119,9 @@ object Dependencies {

val r2dbcPostgres = Compile.r2dbcPostgres % "test"
val r2dbcMysql = Compile.r2dbcMysql % "test"
val r2dbcMariadb = Compile.r2dbcMariadb % "test"
val r2dbcH2 = Compile.r2dbcH2 % "test"
val h2R2dbc = Compile.h2R2dbc % "test"
}

object Examples {
Expand Down Expand Up @@ -276,6 +284,9 @@ object Dependencies {
Compile.r2dbcPool,
Test.r2dbcPostgres,
Test.r2dbcMysql,
Test.r2dbcMariadb,
Test.r2dbcH2,
Test.h2R2dbc,
Test.pekkoSerializationJackson,
Test.pekkoDiscovery,
Test.pekkoDistributedData,
Expand Down
2 changes: 1 addition & 1 deletion project/PekkoPersistenceR2DBCDependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import com.github.pjfanning.pekkobuild.PekkoDependency
object PekkoPersistenceR2DBCDependency extends PekkoDependency {
override val checkProject: String = "pekko-persistence-r2dbc"
override val module: Option[String] = None
override val currentVersion: String = "2.0.0-M1"
override val currentVersion: String = "2.0.0-M1+120-5a212bab-SNAPSHOT"
}
Loading
Loading