|
1 | 1 | package dev.helight.krescent.bookstore |
2 | 2 |
|
| 3 | +import dev.helight.krescent.checkpoint.AlwaysCheckpointStrategy |
| 4 | +import dev.helight.krescent.checkpoint.impl.InMemoryCheckpointStorage |
3 | 5 | import dev.helight.krescent.event.Event |
4 | 6 | import dev.helight.krescent.model.EventModelBase.Extension.withConfiguration |
5 | 7 | import dev.helight.krescent.model.ReadModelBase.Extension.catchup |
| 8 | +import dev.helight.krescent.model.ReadModelBase.Extension.restoreOnly |
6 | 9 | import dev.helight.krescent.model.ReducingReadModel |
7 | 10 | import dev.helight.krescent.source.impl.InMemoryEventStore |
8 | 11 | import kotlinx.coroutines.runBlocking |
9 | 12 | import kotlinx.serialization.Serializable |
10 | 13 | import java.util.concurrent.atomic.AtomicInteger |
11 | 14 | import kotlin.test.Test |
| 15 | +import kotlin.test.assertEquals |
| 16 | +import kotlin.test.assertNotNull |
| 17 | +import kotlin.test.assertNull |
12 | 18 |
|
13 | 19 | class BookCountReadModelTest { |
14 | 20 |
|
15 | 21 | @Test |
16 | | - fun `Test my other model shit`() = runBlocking { |
| 22 | + fun `Test runs without exception`(): Unit = runBlocking { |
17 | 23 | BooksAvailableReadModel().withConfiguration { |
18 | 24 |
|
19 | 25 | }.catchup(InMemoryEventStore()) |
20 | 26 | } |
| 27 | + |
| 28 | + @Test |
| 29 | + fun `Test restore only operation`(): Unit = runBlocking { |
| 30 | + val source = InMemoryEventStore() |
| 31 | + val checkpointStorage = InMemoryCheckpointStorage() |
| 32 | + source.publishAll(bookstoreSimulatedEventStream) |
| 33 | + |
| 34 | + val initial = BooksAvailableReadModel().withConfiguration { |
| 35 | + useCheckpoints(checkpointStorage, AlwaysCheckpointStrategy) |
| 36 | + }.restoreOnly() |
| 37 | + assertNull(initial) |
| 38 | + |
| 39 | + val caughtUp = BooksAvailableReadModel().withConfiguration { |
| 40 | + useCheckpoints(checkpointStorage, AlwaysCheckpointStrategy) |
| 41 | + }.catchup(source) |
| 42 | + assertEquals(9, caughtUp.target["1"]) |
| 43 | + |
| 44 | + val late = BooksAvailableReadModel().withConfiguration { |
| 45 | + useCheckpoints(checkpointStorage, AlwaysCheckpointStrategy) |
| 46 | + }.restoreOnly() |
| 47 | + assertNotNull(late) |
| 48 | + assertEquals(9, late.target["1"]) |
| 49 | + } |
21 | 50 | } |
22 | 51 |
|
23 | 52 | class BooksAvailableReadModel( |
|
0 commit comments