1+ using IntegrationTests ;
2+ using JasperFx . Core ;
3+ using JasperFx . Events . Daemon ;
4+ using JasperFx . Events . Projections ;
5+ using Marten ;
6+ using Marten . Events ;
7+ using Microsoft . Extensions . Hosting ;
8+ using Shouldly ;
9+ using Wolverine ;
10+ using Wolverine . Marten ;
11+ using Wolverine . Tracking ;
12+
13+ namespace MartenTests . TestHelpers ;
14+
15+ public class catch_up_and_then_do_nothing : IAsyncLifetime
16+ {
17+ private IHost _host ;
18+
19+ public async Task InitializeAsync ( )
20+ {
21+
22+ _host = await Host . CreateDefaultBuilder ( )
23+ . UseWolverine ( opts =>
24+ {
25+ opts . Services . AddMarten ( m =>
26+ {
27+ m . DisableNpgsqlLogging = true ;
28+
29+ m . Connection ( Servers . PostgresConnectionString ) ;
30+ m . DatabaseSchemaName = "letters3" ;
31+
32+ m . Projections . Add < LetterCountsProjection > ( ProjectionLifecycle . Async ) ;
33+ } ) . AddAsyncDaemon ( DaemonMode . Solo ) . IntegrateWithWolverine ( ) ;
34+
35+ opts . Services . AddMartenStore < ILetterStore > ( m =>
36+ {
37+ m . DisableNpgsqlLogging = true ;
38+
39+ m . Connection ( Servers . PostgresConnectionString ) ;
40+ m . DatabaseSchemaName = "letters4" ;
41+
42+ m . Projections . Add < LetterCountsProjection > ( ProjectionLifecycle . Async ) ;
43+ } ) . IntegrateWithWolverine ( ) ;
44+
45+ opts . Durability . Mode = DurabilityMode . Solo ;
46+ } ) . StartAsync ( ) ;
47+ }
48+
49+ public async Task DisposeAsync ( )
50+ {
51+ await _host . StopAsync ( ) ;
52+ }
53+
54+ [ Fact ]
55+ public async Task with_main_store ( )
56+ {
57+ await _host . ResetAllMartenDataAsync ( ) ;
58+
59+ var id = Guid . NewGuid ( ) ;
60+
61+ // Setting up some other aggregates first
62+ using var session = _host . DocumentStore ( ) . LightweightSession ( ) ;
63+ session . Events . StartStream < LetterCounts > ( "AABBCCDDEE" . ToLetterEvents ( ) ) ;
64+ session . Events . StartStream < LetterCounts > ( "AABBCCDDEE" . ToLetterEvents ( ) ) ;
65+ session . Events . StartStream < LetterCounts > ( "AABBCCDDEE" . ToLetterEvents ( ) ) ;
66+ await session . SaveChangesAsync ( ) ;
67+ await _host . WaitForNonStaleProjectionDataAsync ( 5 . Seconds ( ) ) ;
68+
69+ ( await session . Query < LetterCounts > ( ) . CountAsync ( ) ) . ShouldBe ( 3 ) ;
70+
71+
72+ var tracked = await _host . TrackActivity ( )
73+ . ResetAllMartenDataFirst ( )
74+ . PauseThenCatchUpOnMartenDaemonActivity ( CatchUpMode . AndDoNothing )
75+ . InvokeMessageAndWaitAsync ( new AppendLetters ( id , [ "AAAACCCCBDEEE" , "ABCDECCC" , "BBBA" , "DDDAE" ] ) ) ;
76+
77+ // Proving that previous data was wiped out
78+
79+ var all = await session . Query < LetterCounts > ( ) . ToListAsync ( ) ;
80+ var counts = all . Single ( ) ;
81+ counts . Id . ShouldBe ( id ) ;
82+
83+ counts . ACount . ShouldBe ( 7 ) ;
84+ counts . BCount . ShouldBe ( 5 ) ;
85+ counts . CCount . ShouldBe ( 8 ) ;
86+ }
87+
88+ [ Fact ]
89+ public async Task with_ancillary_store ( )
90+ {
91+ await _host . ResetAllMartenDataAsync < ILetterStore > ( ) ;
92+
93+ var id = Guid . NewGuid ( ) ;
94+
95+ // Setting up some other aggregates first
96+ using var session = _host . DocumentStore < ILetterStore > ( ) . LightweightSession ( ) ;
97+ session . Events . StartStream < LetterCounts > ( "AABBCCDDEE" . ToLetterEvents ( ) ) ;
98+ session . Events . StartStream < LetterCounts > ( "AABBCCDDEE" . ToLetterEvents ( ) ) ;
99+ session . Events . StartStream < LetterCounts > ( "AABBCCDDEE" . ToLetterEvents ( ) ) ;
100+ await session . SaveChangesAsync ( ) ;
101+ await _host . WaitForNonStaleProjectionDataAsync < ILetterStore > ( 5 . Seconds ( ) ) ;
102+
103+ ( await session . Query < LetterCounts > ( ) . CountAsync ( ) ) . ShouldBe ( 3 ) ;
104+
105+
106+ var tracked = await _host . TrackActivity ( )
107+ . ResetAllMartenDataFirst < ILetterStore > ( )
108+ . PauseThenCatchUpOnMartenDaemonActivity < ILetterStore > ( CatchUpMode . AndDoNothing )
109+ . InvokeMessageAndWaitAsync ( new AppendLetters2 ( id , [ "AAAACCCCBDEEE" , "ABCDECCC" , "BBBA" , "DDDAE" ] ) ) ;
110+
111+ // Proving that previous data was wiped out
112+
113+ var all = await session . Query < LetterCounts > ( ) . ToListAsync ( ) ;
114+ var counts = all . Single ( ) ;
115+ counts . Id . ShouldBe ( id ) ;
116+
117+ counts . ACount . ShouldBe ( 7 ) ;
118+ counts . BCount . ShouldBe ( 5 ) ;
119+ counts . CCount . ShouldBe ( 8 ) ;
120+ }
121+ }
0 commit comments