From 0a08a489b3ecda066d8f93df5dc3c655b4f522f9 Mon Sep 17 00:00:00 2001 From: Rodolfo Date: Wed, 4 Dec 2024 19:44:14 -0300 Subject: [PATCH] cleanup --- .../kotlin/crablet/example/CrabletTest1.kt | 77 ------------------- .../kotlin/crablet/example/CrabletTest2.kt | 61 --------------- .../crablet/{example => lab}/SchemaTest.kt | 20 ++--- .../postgres/AccountTransferScenarioTest.kt | 3 + 4 files changed, 13 insertions(+), 148 deletions(-) delete mode 100644 src/test/kotlin/crablet/example/CrabletTest1.kt delete mode 100644 src/test/kotlin/crablet/example/CrabletTest2.kt rename src/test/kotlin/crablet/{example => lab}/SchemaTest.kt (86%) diff --git a/src/test/kotlin/crablet/example/CrabletTest1.kt b/src/test/kotlin/crablet/example/CrabletTest1.kt deleted file mode 100644 index 3da8c39..0000000 --- a/src/test/kotlin/crablet/example/CrabletTest1.kt +++ /dev/null @@ -1,77 +0,0 @@ -package crablet.example - -import crablet.AppendCondition -import crablet.DomainIdentifier -import crablet.EventName -import crablet.SequenceNumber -import crablet.StateId -import crablet.StateName -import crablet.StreamQuery -import crablet.postgres.CrabletEventsAppender -import crablet.postgres.CrabletStateBuilder -import io.vertx.core.json.JsonArray -import io.vertx.core.json.JsonObject -import io.vertx.pgclient.PgConnectOptions -import io.vertx.sqlclient.Pool -import io.vertx.sqlclient.PoolOptions -import java.util.* - -val connectOptions: PgConnectOptions = PgConnectOptions() - .setPort(5432) - .setHost("127.0.0.1") - .setDatabase("postgres") - .setUser("postgres") - .setPassword("postgres") - -// pool options -val poolOptions: PoolOptions = PoolOptions().setMaxSize(5) - -// create the pool from the data object -val pool: Pool = Pool.pool(connectOptions, poolOptions) - -fun main() { - - println("Vertx Pool started") - - val eventsAppender = CrabletEventsAppender(pool) - - val stateBuilder = CrabletStateBuilder( - client = pool, - initialState = JsonArray(), - evolveFunction = { state, event -> state.add(event) }) - - val domainIdentifiers = listOf( - DomainIdentifier(name = StateName("Account"), id = StateId(UUID.randomUUID().toString())) - ) - - val streamQuery = StreamQuery( - identifiers = domainIdentifiers, - eventTypes = listOf("AccountOpened", "AmountDeposited").map { EventName(it) } - ) - - val appendCondition = AppendCondition(query = streamQuery, maximumEventSequence = SequenceNumber(0)) - - val eventsToAppend: List = listOf( - JsonObject().put("type", "AccountOpened").put("id", 10), - JsonObject().put("type", "AmountDeposited").put("amount", 100) - ) - - println("Append operation") - println("--> eventsToAppend: $eventsToAppend") - println("--> appendCondition: $appendCondition ") - - // append events - eventsAppender.appendIf(eventsToAppend, appendCondition) - .compose { - // print the resulting sequenceId - println() - println("New sequence id ---> $it") - // now project a state given the past events - stateBuilder.buildFor(streamQuery) - } - .onSuccess { stateResult: Pair -> - println("New state ---> ${stateResult.first}") - } - .onFailure { it.printStackTrace() } - -} diff --git a/src/test/kotlin/crablet/example/CrabletTest2.kt b/src/test/kotlin/crablet/example/CrabletTest2.kt deleted file mode 100644 index b6447ba..0000000 --- a/src/test/kotlin/crablet/example/CrabletTest2.kt +++ /dev/null @@ -1,61 +0,0 @@ -package crablet.example - -import crablet.AppendCondition -import crablet.DomainIdentifier -import crablet.EventName -import crablet.SequenceNumber -import crablet.StateId -import crablet.StateName -import crablet.StreamQuery -import crablet.postgres.CrabletEventsAppender -import crablet.postgres.CrabletStateBuilder -import io.vertx.core.json.JsonArray -import io.vertx.core.json.JsonObject -import java.util.* - -fun main() { - - println("Vertx Pool started") - - val eventsAppender = CrabletEventsAppender(pool) - - val stateBuilder = CrabletStateBuilder( - client = pool, - initialState = JsonArray(), - evolveFunction = { state, event -> state.add(event) }) - - val domainIdentifiers = listOf( - DomainIdentifier(name = StateName("Account"), id = StateId(UUID.randomUUID().toString())) - ) - - val streamQuery = StreamQuery( - identifiers = domainIdentifiers, - eventTypes = listOf("AccountOpened", "AmountDeposited").map { EventName(it) } - ) - - val appendCondition = AppendCondition(query = streamQuery, maximumEventSequence = SequenceNumber(0)) - - val eventsToAppend: List = listOf( - JsonObject().put("type", "AccountOpened").put("id", 10), - JsonObject().put("type", "AmountDeposited").put("amount", 100) - ) - - println("Append operation") - println("--> eventsToAppend: $eventsToAppend") - println("--> appendCondition: $appendCondition ") - - // append events - eventsAppender.appendIf(eventsToAppend, appendCondition) - .compose { - // print the resulting sequenceId - println() - println("New sequence id ---> $it") - // now project a state given the past events - stateBuilder.buildFor(streamQuery) - } - .onSuccess { stateResult: Pair -> - println("New state ---> ${stateResult.first}") - } - .onFailure { it.printStackTrace() } - -} diff --git a/src/test/kotlin/crablet/example/SchemaTest.kt b/src/test/kotlin/crablet/lab/SchemaTest.kt similarity index 86% rename from src/test/kotlin/crablet/example/SchemaTest.kt rename to src/test/kotlin/crablet/lab/SchemaTest.kt index f8c566d..39fd251 100644 --- a/src/test/kotlin/crablet/example/SchemaTest.kt +++ b/src/test/kotlin/crablet/lab/SchemaTest.kt @@ -1,13 +1,13 @@ -package crablet.example - -import crablet.example.CustomerEvents.CUSTOMER_ACTIVATED -import crablet.example.CustomerEvents.CUSTOMER_DEACTIVATED -import crablet.example.CustomerEvents.CUSTOMER_REGISTERED -import crablet.example.CustomerEvents.CUSTOMER_RENAMED -import crablet.example.CustomerEventsFields.ID -import crablet.example.CustomerEventsFields.NAME -import crablet.example.CustomerEventsFields.REASON -import crablet.example.CustomerEventsFields.TYPE +package crablet.lab + +import crablet.lab.CustomerEvents.CUSTOMER_ACTIVATED +import crablet.lab.CustomerEvents.CUSTOMER_DEACTIVATED +import crablet.lab.CustomerEvents.CUSTOMER_REGISTERED +import crablet.lab.CustomerEvents.CUSTOMER_RENAMED +import crablet.lab.CustomerEventsFields.ID +import crablet.lab.CustomerEventsFields.NAME +import crablet.lab.CustomerEventsFields.REASON +import crablet.lab.CustomerEventsFields.TYPE import `fun`.gen.Gen import io.vertx.core.json.JsonObject diff --git a/src/test/kotlin/crablet/postgres/AccountTransferScenarioTest.kt b/src/test/kotlin/crablet/postgres/AccountTransferScenarioTest.kt index c0758a3..794b6f4 100644 --- a/src/test/kotlin/crablet/postgres/AccountTransferScenarioTest.kt +++ b/src/test/kotlin/crablet/postgres/AccountTransferScenarioTest.kt @@ -177,6 +177,7 @@ class AccountTransferScenarioTest : AbstractCrabletTest() { event.getInteger("amount") ) ) + event.getString("toAcct") == state.id -> state.copy( balance = state.balance.plus( event.getInteger( @@ -184,9 +185,11 @@ class AccountTransferScenarioTest : AbstractCrabletTest() { ) ) ) + else -> state } } + else -> state } })