-
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Quick" Append Events. Closes GH-3138
Docs on the quick append option Few more tests for metadata on the new quick append mode. More tests on the quick append First end to end runs of the quick append mechanism Roughed in QuickEventAppender and configuration logic for switching append modes First successful pass at code generation for the quick append function Lot more preparatory work for "quick append". Put back the old AppendEventFunction Refactored on the code generation for append event operations in preparation for the quick append Roughed in IncrementStreamVersionBy*** for later
- Loading branch information
1 parent
4300ac2
commit ff5dc73
Showing
44 changed files
with
2,864 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Threading.Tasks; | ||
using Marten; | ||
using Marten.Events; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace EventSourcingTests.QuickAppend; | ||
|
||
public class Examples | ||
{ | ||
public static async Task configure() | ||
{ | ||
#region sample_configuring_event_append_mode | ||
|
||
var builder = Host.CreateApplicationBuilder(); | ||
builder.Services.AddMarten(opts => | ||
{ | ||
// This is the default Marten behavior from 4.0 on | ||
opts.Events.AppendMode = EventAppendMode.Rich; | ||
|
||
// Lighter weight mode that should result in better | ||
// performance, but with a loss of available metadata | ||
// within inline projections | ||
opts.Events.AppendMode = EventAppendMode.Quick; | ||
}) | ||
.UseNpgsqlDataSource(); | ||
|
||
#endregion | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/EventSourcingTests/QuickAppend/QuestPartyWithStringIdentifier.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using JasperFx.Core; | ||
|
||
namespace EventSourcingTests.QuickAppend; | ||
|
||
public class QuestPartyWithStringIdentifier | ||
{ | ||
private readonly IList<string> _members = new List<string>(); | ||
|
||
public string[] Members | ||
{ | ||
get | ||
{ | ||
return _members.ToArray(); | ||
} | ||
set | ||
{ | ||
_members.Clear(); | ||
_members.AddRange(value); | ||
} | ||
} | ||
|
||
public IList<string> Slayed { get; } = new List<string>(); | ||
|
||
public void Apply(MembersJoined joined) | ||
{ | ||
if (joined.Members != null) | ||
_members.Fill(joined.Members); | ||
} | ||
|
||
public void Apply(MembersDeparted departed) | ||
{ | ||
_members.RemoveAll(x => departed.Members.Contains(x)); | ||
} | ||
|
||
public void Apply(QuestStarted started) | ||
{ | ||
Name = started.Name; | ||
} | ||
|
||
public string Key { get; set; } | ||
|
||
public string Name { get; set; } | ||
|
||
public string Id { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"Quest party '{Name}' is {Members.Join(", ")}"; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/EventSourcingTests/QuickAppend/StringIdentifiedStreamsCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Xunit; | ||
|
||
namespace EventSourcingTests.QuickAppend; | ||
|
||
[CollectionDefinition("quick_string_identified_streams")] | ||
public class StringIdentifiedStreamsCollection: ICollectionFixture<StringIdentifiedStreamsFixture> | ||
{ | ||
} |
19 changes: 19 additions & 0 deletions
19
src/EventSourcingTests/QuickAppend/StringIdentifiedStreamsFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Marten.Events; | ||
using Marten.Events.Projections; | ||
using Marten.Testing.Harness; | ||
|
||
namespace EventSourcingTests.QuickAppend; | ||
|
||
public class StringIdentifiedStreamsFixture: StoreFixture | ||
{ | ||
public StringIdentifiedStreamsFixture(): base("quick_string_identified_streams") | ||
{ | ||
Options.Events.AppendMode = EventAppendMode.Quick; | ||
Options.Events.StreamIdentity = StreamIdentity.AsString; | ||
Options.Projections.Snapshot<QuestPartyWithStringIdentifier>(SnapshotLifecycle.Inline); | ||
|
||
Options.Events.AddEventType(typeof(MembersJoined)); | ||
Options.Events.AddEventType(typeof(MembersDeparted)); | ||
Options.Events.AddEventType(typeof(QuestStarted)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/EventSourcingTests/QuickAppend/quick_append_end_to_end.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Threading.Tasks; | ||
using Marten.Events; | ||
using Marten.Testing.Harness; | ||
using Xunit; | ||
using Shouldly; | ||
|
||
namespace EventSourcingTests.QuickAppend; | ||
|
||
public class quick_append_end_to_end : OneOffConfigurationsContext | ||
{ | ||
public quick_append_end_to_end() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Events.AppendMode = EventAppendMode.Quick; | ||
opts.Events.MetadataConfig.CausationIdEnabled = true; | ||
opts.Events.MetadataConfig.CorrelationIdEnabled = true; | ||
opts.Events.MetadataConfig.HeadersEnabled = true; | ||
}); | ||
} | ||
|
||
[Fact] | ||
public async Task append_with_metadata_using_function() | ||
{ | ||
theSession.CorrelationId = "lotr"; | ||
theSession.CausationId = "fellowship"; | ||
theSession.SetHeader("color", "blue"); | ||
|
||
var streamId = | ||
theSession.Events.StartStream<Quest>(new QuestStarted(), new MembersJoined(1, "Hobbiton", "Frodo", "Sam")).Id; | ||
await theSession.SaveChangesAsync(); | ||
|
||
var events = await theSession.Events.FetchStreamAsync(streamId); | ||
|
||
foreach (var e in events) | ||
{ | ||
e.Sequence.ShouldBeGreaterThan(0); | ||
e.Version.ShouldBeGreaterThan(0); | ||
|
||
e.CorrelationId.ShouldBe(theSession.CorrelationId); | ||
e.CausationId.ShouldBe(theSession.CausationId); | ||
e.Headers["color"].ShouldBe("blue"); | ||
} | ||
} | ||
} |
Oops, something went wrong.