Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test DynamoDB projections #17

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions .github/actions/build-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Build Setup"
description: "Composite action steps for setting up builds"
runs:
using: "composite"
steps:
- name: Checkout - GitHub merge
if: github.event.pull_request
shell: bash
run: |-
git fetch origin pull/${{ github.event.pull_request.number }}/merge:scratch
git checkout scratch

- name: Cache - Coursier
# https://github.com/coursier/cache-action/releases
# v6.4.5
uses: coursier/cache-action@1ff273bff02a8787bc9f1877d347948af647956d

- name: Coursier - set up JDK 21
# https://github.com/coursier/setup-action/releases
# v1.3.5
uses: coursier/setup-action@7bde40eee928896f074dbb76d22dd772eed5c65f
with:
jvm: temurin:1.21
29 changes: 29 additions & 0 deletions .github/actions/integration-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Integration Test"
description: "Composite action steps for running an integration test"
inputs:
docker-compose:
required: true
description: "Docker compose file to use for database setup"
test-config:
required: true
description: "Test config to select for integration tests"
runs:
using: "composite"
steps:
- name: Build setup
uses: ./.github/actions/build-setup

- name: Database setup
shell: bash
run: docker compose -f docker/docker-compose-${{ inputs.docker-compose }}.yml up --wait

- name: Test
shell: bash
run: |-
cp .jvmopts-ci .jvmopts
sbt test -Dtest.config=${{ inputs.test-config }}

- name: After failure - docker logs
if: ${{ failure() }}
shell: bash
run: docker compose -f docker/docker-compose-${{ inputs.docker-compose }}.yml logs
105 changes: 61 additions & 44 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,16 @@ jobs:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- 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
# https://github.com/coursier/cache-action/releases
# v6.4.5
uses: coursier/cache-action@1ff273bff02a8787bc9f1877d347948af647956d

- name: Set up JDK 21
# https://github.com/coursier/setup-action/releases
# v1.3.5
uses: coursier/setup-action@7bde40eee928896f074dbb76d22dd772eed5c65f
with:
jvm: temurin:1.21
- name: Build setup
uses: ./.github/actions/build-setup

- name: Code style check
run: |-
cp .jvmopts-ci .jvmopts
sbt verifyCodeStyle

test:
name: Run tests
test-r2dbc:
name: Run tests - R2DBC
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-projection-testing'
steps:
Expand All @@ -54,36 +39,68 @@ jobs:
# v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- 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: Run integration test
uses: ./.github/actions/integration-test
with:
docker-compose: r2dbc-postgres
test-config: local-r2dbc

- name: Cache Coursier cache
# https://github.com/coursier/cache-action/releases
# v6.4.5
uses: coursier/cache-action@1ff273bff02a8787bc9f1877d347948af647956d
test-dynamodb:
name: Run tests - DynamoDB
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-projection-testing'
steps:
- name: Checkout
# https://github.com/actions/checkout/releases
# v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Set up JDK 21
# https://github.com/coursier/setup-action/releases
# v1.3.5
uses: coursier/setup-action@7bde40eee928896f074dbb76d22dd772eed5c65f
- name: Run integration test
uses: ./.github/actions/integration-test
with:
jvm: temurin:1.21
docker-compose: dynamodb
test-config: local-dynamodb

- name: Docker - Postgres
run: |-
docker compose -f docker/docker-compose-postgres.yml up --wait
docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
test-jdbc:
name: Run tests - JDBC
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-projection-testing'
steps:
- name: Checkout
# https://github.com/actions/checkout/releases
# v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Test (R2DBC)
run: |-
cp .jvmopts-ci .jvmopts
sbt test
- name: Run integration test
uses: ./.github/actions/integration-test
with:
docker-compose: jdbc-postgres
test-config: local-jdbc

- name: After failure - docker logs
if: ${{ failure() }}
run: docker compose logs
test-cassandra:
name: Run tests - Cassandra
runs-on: ubuntu-22.04
if: github.repository == 'akka/akka-projection-testing'
steps:
- name: Checkout
# https://github.com/actions/checkout/releases
# v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Run integration test
uses: ./.github/actions/integration-test
with:
docker-compose: cassandra-jdbc-postgres
test-config: local-cassandra
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,46 @@ It is currently support the following alternative Akka Persistence and Akka Proj

## Running a test locally

Start a local PostgresSQL server on default port 5432. Note that this is also needed when testing with Cassandra.
### R2DBC (Postgres)

Start a local PostgresSQL server on default port 5432:

```shell
docker compose -f docker/docker-compose-postgres.yml up --wait
docker compose -f docker/docker-compose-r2dbc-postgres.yml up --wait
```

For testing with R2DBC you need to create the tables with:
Adjust the includes in `local.conf` to select R2DBC.

### Cassandra and JDBC (Postgres)

For testing with Cassandra start a local Cassandra in addition to the PostgresSQL:

```shell
docker exec -i postgres-db psql -U postgres -t < ddl-scripts/create_tables_postgres.sql
docker compose -f docker/docker-compose-cassandra-jdbc-postgres.yml up --wait
```

For testing with Cassandra start a local Cassandra in addition to the PostgresSQL:
Adjust the includes in `local.conf` to select Cassandra.

### JDBC (Postgres)

Start a local PostgresSQL server on default port 5432:

```shell
docker compose -f docker/docker-compose-cassandra.yml up --wait
docker compose -f docker/docker-compose-jdbc-postgres.yml up --wait
```

Adjust the includes in `local.conf` to choose testing with Cassandra, R2DBC or JDBC.
Adjust the includes in `local.conf` to select JDBC.

### Run application

Start the application:

```shell
sbt "run 2551"
```

### Start test run

Start a test run:

```shell
Expand Down
19 changes: 11 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
val AkkaVersion = "2.10.0"
val AkkaPersistenceCassandraVersion = "1.3.0"
val AkkaHttpVersion = "10.7.0"
val AkkaProjectionVersion = "1.6.5"
val AkkaManagementVersion = "1.6.0"
val AkkaPersistenceJdbc = "5.5.0"
val AkkaPersistenceR2dbc = "1.3.0"
val AkkaPersistenceR2dbcVersion = "1.3.0"
val AkkaPersistenceDynamoDBVersion = "2.0.4"
val AkkaPersistenceJdbcVersion = "5.5.0"
val AkkaPersistenceCassandraVersion = "1.3.0"

ThisBuild / dynverSeparator := "-"

Expand All @@ -31,13 +32,15 @@ lazy val `akka-projection-testing` = project
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.typesafe.akka" %% "akka-persistence-query" % AkkaVersion,
"com.typesafe.akka" %% "akka-serialization-jackson" % AkkaVersion,
"com.typesafe.akka" %% "akka-persistence-cassandra" % AkkaPersistenceCassandraVersion,
"com.lightbend.akka" %% "akka-persistence-jdbc" % AkkaPersistenceJdbc,
"com.lightbend.akka" %% "akka-persistence-r2dbc" % AkkaPersistenceR2dbc,
"com.lightbend.akka" %% "akka-projection-r2dbc" % AkkaProjectionVersion,
"com.lightbend.akka" %% "akka-projection-eventsourced" % AkkaProjectionVersion,
"com.lightbend.akka" %% "akka-projection-cassandra" % AkkaProjectionVersion,
"com.lightbend.akka" %% "akka-persistence-r2dbc" % AkkaPersistenceR2dbcVersion,
"com.lightbend.akka" %% "akka-projection-r2dbc" % AkkaProjectionVersion,
"com.lightbend.akka" %% "akka-persistence-dynamodb" % AkkaPersistenceDynamoDBVersion,
"com.lightbend.akka" %% "akka-projection-dynamodb" % AkkaProjectionVersion,
"com.lightbend.akka" %% "akka-persistence-jdbc" % AkkaPersistenceJdbcVersion,
"com.lightbend.akka" %% "akka-projection-jdbc" % AkkaProjectionVersion,
"com.typesafe.akka" %% "akka-persistence-cassandra" % AkkaPersistenceCassandraVersion,
"com.lightbend.akka" %% "akka-projection-cassandra" % AkkaProjectionVersion,
"com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-http" % AkkaManagementVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % AkkaManagementVersion,
Expand Down
28 changes: 28 additions & 0 deletions docker/docker-compose-cassandra-jdbc-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
cassandra:
image: cassandra:3
container_name: cassandra
ports:
- "9042:9042"
healthcheck:
test: ["CMD", "cqlsh", "-e", "describe keyspaces"]
interval: 5s
timeout: 5s
retries: 60

postgres-db:
image: postgres:latest
container_name: postgres-db
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./jdbc/postgres/initdb:/docker-entrypoint-initdb.d
healthcheck:
test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"]
interval: 5s
retries: 5
start_period: 5s
timeout: 5s
11 changes: 0 additions & 11 deletions docker/docker-compose-cassandra.yml

This file was deleted.

8 changes: 8 additions & 0 deletions docker/docker-compose-dynamodb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
dynamodb-local:
command: "-jar DynamoDBLocal.jar -sharedDb -inMemory"
image: "amazon/dynamodb-local:latest"
container_name: dynamodb-local
ports:
- "8000:8000"
working_dir: /home/dynamodblocal
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ services:
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./jdbc/postgres/initdb:/docker-entrypoint-initdb.d
healthcheck:
test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"]
interval: 5s
Expand Down
17 changes: 17 additions & 0 deletions docker/docker-compose-r2dbc-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
postgres-db:
image: postgres:latest
container_name: postgres-db
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./r2dbc/postgres/initdb:/docker-entrypoint-initdb.d
healthcheck:
test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"]
interval: 5s
retries: 5
start_period: 5s
timeout: 5s
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@

create table if not exists events (
name varchar(256),
projection_id BIGINT,
event varchar(256),
constraint pkey primary key (name, projection_id, event)
name varchar(256),
projection_id BIGINT,
event varchar(256),
constraint pkey primary key (name, projection_id, event)
);

create table if not exists results (
name varchar(256) primary key,
result varchar(256)
name varchar(256) primary key,
result varchar(256)
);

CREATE TABLE IF NOT EXISTS akka_projection_offset_store (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
create table if not exists events (
name varchar(256),
projection_id BIGINT,
event varchar(256),
constraint pkey primary key (name, projection_id, event)
name varchar(256),
projection_id BIGINT,
event varchar(256),
constraint pkey primary key (name, projection_id, event)
);

create table if not exists results (
name varchar(256) primary key,
result varchar(256)
name varchar(256) primary key,
result varchar(256)
);

CREATE TABLE IF NOT EXISTS event_journal(
Expand Down
Loading