From 9552ee8b9b81a45e8237b8d075847d03911d329e Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Wed, 1 Sep 2021 08:17:14 +0200 Subject: [PATCH 1/4] Do not enforce previous_source_ids --- RELEASE_NOTES.md | 2 + .../EventFlow/Snapshots/SnapshotMetadata.cs | 44 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e79d630dc..012bcc374 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,6 +4,8 @@ ```csharp eventFlowOptions.UseHangfireJobScheduler(o => o.UseQueueName("myqueue")) ``` +* Fixed: Do not throw `MetadataKeyNotFoundException` if there is no meta data on + `previous_source_ids` in snapshots ### New in 0.82.4684 (released 2021-08-31) diff --git a/Source/EventFlow/Snapshots/SnapshotMetadata.cs b/Source/EventFlow/Snapshots/SnapshotMetadata.cs index 3004fbe1e..5026d41fc 100644 --- a/Source/EventFlow/Snapshots/SnapshotMetadata.cs +++ b/Source/EventFlow/Snapshots/SnapshotMetadata.cs @@ -56,36 +56,36 @@ public SnapshotMetadata(params KeyValuePair[] keyValuePairs) [JsonIgnore] public string AggregateId { - get { return GetMetadataValue(SnapshotMetadataKeys.AggregateId); } - set { Add(SnapshotMetadataKeys.AggregateId, value); } + get => GetMetadataValue(SnapshotMetadataKeys.AggregateId); + set => Add(SnapshotMetadataKeys.AggregateId, value); } [JsonIgnore] public string AggregateName { - get { return GetMetadataValue(SnapshotMetadataKeys.AggregateName); } - set { Add(SnapshotMetadataKeys.AggregateName, value); } + get => GetMetadataValue(SnapshotMetadataKeys.AggregateName); + set => Add(SnapshotMetadataKeys.AggregateName, value); } [JsonIgnore] public int AggregateSequenceNumber { - get { return GetMetadataValue(SnapshotMetadataKeys.AggregateSequenceNumber, int.Parse); } - set { Add(SnapshotMetadataKeys.AggregateSequenceNumber, value.ToString(CultureInfo.InvariantCulture)); } + get => GetMetadataValue(SnapshotMetadataKeys.AggregateSequenceNumber, int.Parse); + set => Add(SnapshotMetadataKeys.AggregateSequenceNumber, value.ToString(CultureInfo.InvariantCulture)); } [JsonIgnore] public string SnapshotName { - get { return GetMetadataValue(SnapshotMetadataKeys.SnapshotName); } - set { Add(SnapshotMetadataKeys.SnapshotName, value); } + get => GetMetadataValue(SnapshotMetadataKeys.SnapshotName); + set => Add(SnapshotMetadataKeys.SnapshotName, value); } [JsonIgnore] public int SnapshotVersion { - get { return GetMetadataValue(SnapshotMetadataKeys.SnapshotVersion, int.Parse); } - set { Add(SnapshotMetadataKeys.SnapshotVersion, value.ToString(CultureInfo.InvariantCulture)); } + get => GetMetadataValue(SnapshotMetadataKeys.SnapshotVersion, int.Parse); + set => Add(SnapshotMetadataKeys.SnapshotVersion, value.ToString(CultureInfo.InvariantCulture)); } [JsonIgnore] @@ -93,18 +93,18 @@ public IReadOnlyCollection PreviousSourceIds { get { - return GetMetadataValue(SnapshotMetadataKeys.PreviousSourceIds, (json) => - string.IsNullOrWhiteSpace(json) ? - Empty : - json - .Split(SourceIdSeparators, StringSplitOptions.RemoveEmptyEntries) - .Select(sourceId => new SourceId(sourceId)) - .ToList().AsReadOnly()); + if (!TryGetValue(SnapshotMetadataKeys.PreviousSourceIds, out var ids) || + string.IsNullOrEmpty(ids)) + { + return Empty; + } + + return ids + .Split(SourceIdSeparators, StringSplitOptions.RemoveEmptyEntries) + .Select(sourceId => new SourceId(sourceId)) + .ToArray(); } - set { Add(SnapshotMetadataKeys.PreviousSourceIds, string.Join(",", value.Select(x => x.Value)));} + set => Add(SnapshotMetadataKeys.PreviousSourceIds, string.Join(",", value.Select(x => x.Value))); } - - - } -} \ No newline at end of file +} From 0233feb9c445e0916c9cecdd5942c71295d41181 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Tue, 7 Sep 2021 20:39:07 +0200 Subject: [PATCH 2/4] Codecov not actively used --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4740ff4b1..d33fcdde2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,9 +30,9 @@ services: - mssql2017 - postgresql101 -on_success: -- choco install codecov -- codecov -f "Build\\Reports\\opencover-results.xml" +#on_success: +#- choco install codecov +#- codecov -f "Build\\Reports\\opencover-results.xml" nuget: account_feed: false From 6e6724b8fbd2c5eac894a554c23c46ef364f52d6 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Tue, 7 Sep 2021 20:43:15 +0200 Subject: [PATCH 3/4] Test that PreviousSourceIds can be empty --- .../UnitTests/Snapshots/SnapshotMetadataTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs index 1a57e3c44..b6fcab91f 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs @@ -81,5 +81,18 @@ public void GettersAndSettersWork() deserializedSnapshotMetadata.SnapshotName.Should().Be("thingy"); deserializedSnapshotMetadata.SnapshotVersion.Should().Be(84); } + + [Test] + public void PreviousSourceIdsIsAllowedToBeEmpty() + { + // Arrange + var snapshotMetadata = new SnapshotMetadata(); + + // Act + var previousSourceIds = snapshotMetadata.PreviousSourceIds; + + // Assert + previousSourceIds.Should().BeEmpty(); + } } } \ No newline at end of file From 612cc4bac36ece17e9b444a7a377aed7570752a6 Mon Sep 17 00:00:00 2001 From: Rasmus Mikkelsen Date: Tue, 7 Sep 2021 20:46:34 +0200 Subject: [PATCH 4/4] Add missing test cases for previous_source_ids --- .../UnitTests/Snapshots/SnapshotMetadataTests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs index b6fcab91f..a25b9c1c6 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs @@ -21,6 +21,8 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +using System.Linq; +using EventFlow.Core; using EventFlow.Snapshots; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Extensions; @@ -44,6 +46,7 @@ public void DeserializesCorrectly() aggregate_sequence_number = "42", snapshot_name = "thingy", snapshot_version = "84", + previous_source_ids = "cool,magic," }.ToJson(); // Act @@ -55,6 +58,7 @@ public void DeserializesCorrectly() snapshotMetadata.AggregateSequenceNumber.Should().Be(42); snapshotMetadata.SnapshotName.Should().Be("thingy"); snapshotMetadata.SnapshotVersion.Should().Be(84); + snapshotMetadata.PreviousSourceIds.Select(s => s.Value).Should().BeEquivalentTo("cool", "magic"); } [Test] @@ -68,6 +72,11 @@ public void GettersAndSettersWork() AggregateSequenceNumber = 42, SnapshotName = "thingy", SnapshotVersion = 84, + PreviousSourceIds = new [] + { + new SourceId("cool"), + new SourceId("magic") + } }; // Act @@ -80,6 +89,7 @@ public void GettersAndSettersWork() deserializedSnapshotMetadata.AggregateSequenceNumber.Should().Be(42); deserializedSnapshotMetadata.SnapshotName.Should().Be("thingy"); deserializedSnapshotMetadata.SnapshotVersion.Should().Be(84); + deserializedSnapshotMetadata.PreviousSourceIds.Select(s => s.Value).Should().BeEquivalentTo("cool", "magic"); } [Test]