evento-sql 2.0.0-alpha.29

SQL database implementations for evento event sourcing library.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
use evento::sql::{RwSqlite, Sql};
use sqlx::{
    sqlite::{SqliteConnectOptions, SqlitePoolOptions},
    SqlitePool,
};
use std::str::FromStr;

mod pool;

fn rw_from_pools(pools: (SqlitePool, SqlitePool)) -> RwSqlite {
    let (r, w) = pools;
    (evento::Sqlite::from(r), evento::Sqlite::from(w)).into()
}

#[tokio::test]
async fn sqlite_routing_key() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("routing_key").await?;

    evento_test::routing_key(&executor).await
}

#[tokio::test]
async fn sqlite_load() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("load").await?;

    evento_test::load(&executor).await
}

#[tokio::test]
async fn sqlite_load_multiple_aggregator() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("load_multiple_aggregator").await?;

    evento_test::load_multiple_aggregator(&executor).await
}

#[tokio::test]
async fn sqlite_load_with_snapshot() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("load_with_snapshot").await?;

    evento_test::load_with_snapshot(&executor).await
}

#[tokio::test]
async fn sqlite_invalid_original_version() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("invalid_original_version").await?;

    evento_test::invalid_original_version(&executor).await
}

#[tokio::test]
async fn sqlite_subscriber_running() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscriber_running").await?;

    evento_test::subscriber_running::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe").await?;

    evento_test::subscribe::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_low_latency() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_low_latency").await?;

    // Subscription latency ≈ stable_margin + a short re-check tick (the
    // watermark gate defers events younger than the margin). The default 1s
    // margin is sized for multi-process deployments; this single-writer test
    // DB shrinks it so the sub-500ms latency assertion measures the wake path.
    let executor =
        Sql::<sqlx::Sqlite>::from(pool).stable_margin(std::time::Duration::from_millis(50));
    evento_test::subscribe_low_latency::<Sql<sqlx::Sqlite>>(&executor).await
}

#[tokio::test]
async fn sqlite_subscribe_routing_key() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_routing_key").await?;

    evento_test::subscribe_routing_key::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_default() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_default").await?;

    evento_test::subscribe_default::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_multiple_aggregator() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_multiple_aggregator").await?;

    evento_test::subscribe_multiple_aggregator::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_co_keyed_aggregator() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_co_keyed_aggregator").await?;

    evento_test::subscribe_co_keyed_aggregator::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_load_co_keyed_aggregator() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("load_co_keyed_aggregator").await?;

    evento_test::load_co_keyed_aggregator::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_routing_key_multiple_aggregator() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_routing_key_multiple_aggregator").await?;

    evento_test::subscribe_routing_key_multiple_aggregator::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_default_multiple_aggregator() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_default_multiple_aggregator").await?;

    evento_test::subscribe_default_multiple_aggregator::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_default_routing_key() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_default_routing_key").await?;

    evento_test::subscribe_default_routing_key::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn sqlite_subscribe_default_routing_key_all_isolation() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("subscribe_default_routing_key_all_isolation").await?;

    evento_test::subscribe_default_routing_key_all_isolation::<Sql<sqlx::Sqlite>>(&pool.into())
        .await
}

#[tokio::test]
async fn sqlite_all_commands() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("all_commands").await?;

    evento_test::all_commands::<Sql<sqlx::Sqlite>>(&pool.into()).await
}

#[tokio::test]
async fn rw_sqlite_routing_key() -> anyhow::Result<()> {
    let executor = create_rw_sqlite_executor("routing_key").await?;

    evento_test::routing_key(&executor).await
}

#[tokio::test]
async fn rw_sqlite_load() -> anyhow::Result<()> {
    let executor = create_rw_sqlite_executor("load").await?;

    evento_test::load(&executor).await
}

#[tokio::test]
async fn rw_sqlite_load_multiple_aggregator() -> anyhow::Result<()> {
    let executor = create_rw_sqlite_executor("load_multiple_aggregator").await?;

    evento_test::load_multiple_aggregator(&executor).await
}

#[tokio::test]
async fn rw_sqlite_load_with_snapshot() -> anyhow::Result<()> {
    let executor = create_rw_sqlite_executor("load_with_snapshot").await?;

    evento_test::load_with_snapshot(&executor).await
}

#[tokio::test]
async fn rw_sqlite_invalid_original_version() -> anyhow::Result<()> {
    let executor = create_rw_sqlite_executor("invalid_original_version").await?;

    evento_test::invalid_original_version(&executor).await
}

#[tokio::test]
async fn rw_sqlite_subscriber_running() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscriber_running").await?;

    evento_test::subscriber_running::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe").await?;

    evento_test::subscribe::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe_routing_key() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe_routing_key").await?;

    evento_test::subscribe_routing_key::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe_default() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe_default").await?;

    evento_test::subscribe_default::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe_multiple_aggregator() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe_multiple_aggregator").await?;

    evento_test::subscribe_multiple_aggregator::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe_co_keyed_aggregator() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe_co_keyed_aggregator").await?;

    evento_test::subscribe_co_keyed_aggregator::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_load_co_keyed_aggregator() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("load_co_keyed_aggregator").await?;

    evento_test::load_co_keyed_aggregator::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe_routing_key_multiple_aggregator() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe_routing_key_multiple_aggregator").await?;

    evento_test::subscribe_routing_key_multiple_aggregator::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_subscribe_default_multiple_aggregator() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("subscribe_default_multiple_aggregator").await?;

    evento_test::subscribe_default_multiple_aggregator::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn rw_sqlite_all_commands() -> anyhow::Result<()> {
    let pool = create_rw_sqlite_pool("all_commands").await?;

    evento_test::all_commands::<RwSqlite>(&rw_from_pools(pool)).await
}

#[tokio::test]
async fn sqlite_forward_asc() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("forward_asc").await?;

    pool::forward_asc(pool).await
}

#[tokio::test]
async fn sqlite_forward_desc() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("forward_desc").await?;

    pool::forward_desc(pool).await
}

#[tokio::test]
async fn sqlite_backward_asc() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("backward_asc").await?;

    pool::backward_asc(pool).await
}

#[tokio::test]
async fn sqlite_backward_desc() -> anyhow::Result<()> {
    let pool = create_sqlite_pool("backward_desc").await?;

    pool::backward_desc(pool).await
}

async fn create_rw_sqlite_executor(
    key: impl Into<String>,
) -> anyhow::Result<evento::Rw<evento::Sqlite, evento::Sqlite>> {
    let (r, w) = create_rw_sqlite_pool(key).await?;
    Ok((evento::Sqlite::from(r), evento::Sqlite::from(w)).into())
}

async fn create_sqlite_executor(key: impl Into<String>) -> anyhow::Result<evento::Evento> {
    let executor: evento::Sqlite = create_sqlite_pool(key).await?.into();

    Ok(executor.into())
}

async fn create_rw_sqlite_pool(key: impl Into<String>) -> anyhow::Result<(SqlitePool, SqlitePool)> {
    let key = key.into();
    let key = format!("rw_{key}");
    let url = format!("sqlite:../target/tmp/test_sql_{key}.db");

    let w = create_sqlite_pool(key).await?;
    sqlx::query("PRAGMA journal_mode = WAL").execute(&w).await?;
    sqlx::query("PRAGMA busy_timeout = 5000")
        .execute(&w)
        .await?;
    sqlx::query("PRAGMA synchronous = NORMAL")
        .execute(&w)
        .await?;
    sqlx::query("PRAGMA cache_size = -20000")
        .execute(&w)
        .await?;
    sqlx::query("PRAGMA foreign_keys = true")
        .execute(&w)
        .await?;
    sqlx::query("PRAGMA temp_store = memory")
        .execute(&w)
        .await?;

    let options = SqliteConnectOptions::from_str(&url)?.read_only(true);

    let r = SqlitePoolOptions::new().connect_with(options).await?;
    sqlx::query("PRAGMA journal_mode = WAL").execute(&r).await?;
    sqlx::query("PRAGMA busy_timeout = 5000")
        .execute(&r)
        .await?;
    sqlx::query("PRAGMA synchronous = NORMAL")
        .execute(&r)
        .await?;
    sqlx::query("PRAGMA cache_size = -20000")
        .execute(&r)
        .await?;
    sqlx::query("PRAGMA foreign_keys = true")
        .execute(&r)
        .await?;
    sqlx::query("PRAGMA temp_store = memory")
        .execute(&r)
        .await?;

    Ok((r, w))
}

async fn create_sqlite_pool(key: impl Into<String>) -> anyhow::Result<SqlitePool> {
    let key = key.into();
    let url = format!("sqlite:../target/tmp/test_sql_{key}.db");

    pool::create_pool(url).await
}

#[tokio::test]
async fn sqlite_read_order_timestamp() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_order_timestamp").await?;
    evento_test::read_order_timestamp(&executor).await
}

#[tokio::test]
async fn sqlite_exact_filter() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("exact_filter").await?;
    evento_test::exact_filter(&executor).await
}

#[tokio::test]
async fn sqlite_write_restamps_client_clock() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("write_restamps_client_clock").await?;
    evento_test::write_restamps_client_clock(&executor).await
}

#[tokio::test]
async fn sqlite_concurrent_append() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("concurrent_append").await?;
    evento_test::concurrent_append(&executor).await
}

#[tokio::test]
async fn sqlite_strict_unhandled() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("strict_unhandled").await?;
    evento_test::strict_unhandled(&executor).await
}

#[tokio::test]
async fn sqlite_tombstone() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("tombstone").await?;
    evento_test::tombstone(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_data() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("subscription_data").await?;
    evento_test::subscription_data(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_stop_reason() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("subscription_stop_reason").await?;
    evento_test::subscription_stop_reason(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_all_counts() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("subscription_all_counts").await?;
    evento_test::subscription_all_counts(&executor).await
}

#[tokio::test]
async fn sqlite_snapshot_revision_scope() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("snapshot_revision_scope").await?;
    evento_test::snapshot_revision_scope(&executor).await
}

#[tokio::test]
async fn sqlite_snapshot_projection_scope() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("snapshot_projection_scope").await?;
    evento_test::snapshot_projection_scope(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_load() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_load").await?;
    evento_test::upcast_load(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_nearest_target() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_nearest_target").await?;
    evento_test::upcast_nearest_target(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_explicit_wins() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_explicit_wins").await?;
    evento_test::upcast_explicit_wins(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_skip() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_skip").await?;
    evento_test::upcast_skip(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_strict_unhandled_target() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_strict_unhandled_target").await?;
    evento_test::upcast_strict_unhandled_target(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_subscription() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_subscription").await?;
    evento_test::upcast_subscription(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_projection_subscription() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_projection_subscription").await?;
    evento_test::upcast_projection_subscription(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_tombstone() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_tombstone").await?;
    evento_test::upcast_tombstone(&executor).await
}

#[tokio::test]
async fn sqlite_upcast_has_event() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("upcast_has_event").await?;
    evento_test::upcast_has_event(&executor).await
}

#[tokio::test]
async fn sqlite_read_stream() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_stream").await?;
    evento_test::read_stream(&executor).await
}

#[tokio::test]
async fn sqlite_read_drains_pages() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_drains_pages").await?;
    evento_test::read_drains_pages(&executor).await
}

#[tokio::test]
async fn sqlite_read_limit() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_limit").await?;
    evento_test::read_limit(&executor).await
}

#[tokio::test]
async fn sqlite_read_page_cursor() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_page_cursor").await?;
    evento_test::read_page_cursor(&executor).await
}

#[tokio::test]
async fn sqlite_read_decode() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_decode").await?;
    evento_test::read_decode(&executor).await
}

#[tokio::test]
async fn sqlite_read_routing_key() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("read_routing_key").await?;
    evento_test::read_routing_key(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_start_from_latest() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_start_from_latest").await?;
    evento_test::subscription_start_from_latest(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_ephemeral() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_ephemeral").await?;
    evento_test::subscription_ephemeral(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_ephemeral_start_from_latest() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_ephemeral_start_from_latest").await?;
    evento_test::subscription_ephemeral_start_from_latest(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_ephemeral_concurrent_same_key() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_ephemeral_concurrent_same_key").await?;
    evento_test::subscription_ephemeral_concurrent_same_key(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_context_stop() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_context_stop").await?;
    evento_test::subscription_context_stop(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_live() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_live").await?;
    evento_test::subscription_live(&executor).await
}

#[tokio::test]
async fn sqlite_subscription_ephemeral_run_once() -> anyhow::Result<()> {
    let executor = create_sqlite_executor("sub_ephemeral_run_once").await?;
    evento_test::subscription_ephemeral_run_once(&executor).await
}