Skip to content

Commit

Permalink
chore: restructure before extending (#16)
Browse files Browse the repository at this point in the history
* update running and tests for the different variations
* restructure for extending to more implementations
  • Loading branch information
pvlugter authored Jan 6, 2025
1 parent 3673e30 commit 0406e0e
Show file tree
Hide file tree
Showing 32 changed files with 683 additions and 404 deletions.
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 logs
88 changes: 43 additions & 45 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,49 @@ 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: Cache Coursier cache
# https://github.com/coursier/cache-action/releases
# v6.4.5
uses: coursier/cache-action@1ff273bff02a8787bc9f1877d347948af647956d
- name: Run integration test
uses: ./.github/actions/integration-test
with:
docker-compose: r2dbc-postgres
test-config: local-r2dbc

- name: Set up JDK 21
# https://github.com/coursier/setup-action/releases
# v1.3.5
uses: coursier/setup-action@7bde40eee928896f074dbb76d22dd772eed5c65f
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:
jvm: temurin:1.21
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

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

- name: Test (R2DBC)
run: |-
cp .jvmopts-ci .jvmopts
sbt test
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: After failure - docker logs
if: ${{ failure() }}
run: docker compose logs
- 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
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.

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
File renamed without changes.
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
create table if not exists events (
name varchar(256),
projection_id BIGINT,
event varchar(256),
primary key ((name, projection_id) HASH, event)
name varchar(256),
projection_id BIGINT,
event varchar(256),
primary key ((name, projection_id) HASH, 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(
slice INT NOT NULL,
entity_type VARCHAR(255) NOT NULL,
Expand Down
11 changes: 0 additions & 11 deletions src/main/resources/create_tables_yugabyte.sql

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/resources/local-cassandra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "cassandra"
include "local-shared"
2 changes: 2 additions & 0 deletions src/main/resources/local-jdbc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "jdbc"
include "local-shared"
2 changes: 2 additions & 0 deletions src/main/resources/local-r2dbc.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include "r2dbc"
include "local-shared"
19 changes: 19 additions & 0 deletions src/main/resources/local-shared.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
akka {
cluster {
seed-nodes = [
"akka://[email protected]:2551",
"akka://[email protected]:2552"
]

roles = ["write-model", "read-model"]
}

# For the sample, just bind to loopback and do not allow access from the network
# the port is overridden by the logic in main class
remote.artery {
canonical.port = 0
canonical.hostname = 127.0.0.1
}
}

akka.management.http.hostname = "127.0.0.1"
Loading

0 comments on commit 0406e0e

Please sign in to comment.