Skip to content

Commit

Permalink
Merge pull request #896 from eventflow/allow-no-source-ids
Browse files Browse the repository at this point in the history
Do not enforce previous source IDs
  • Loading branch information
rasmus authored Sep 7, 2021
2 parents 25b3019 + 612cc4b commit e544b76
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +46,7 @@ public void DeserializesCorrectly()
aggregate_sequence_number = "42",
snapshot_name = "thingy",
snapshot_version = "84",
previous_source_ids = "cool,magic,"
}.ToJson();

// Act
Expand All @@ -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]
Expand All @@ -68,6 +72,11 @@ public void GettersAndSettersWork()
AggregateSequenceNumber = 42,
SnapshotName = "thingy",
SnapshotVersion = 84,
PreviousSourceIds = new []
{
new SourceId("cool"),
new SourceId("magic")
}
};

// Act
Expand All @@ -80,6 +89,20 @@ 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]
public void PreviousSourceIdsIsAllowedToBeEmpty()
{
// Arrange
var snapshotMetadata = new SnapshotMetadata();

// Act
var previousSourceIds = snapshotMetadata.PreviousSourceIds;

// Assert
previousSourceIds.Should().BeEmpty();
}
}
}
44 changes: 22 additions & 22 deletions Source/EventFlow/Snapshots/SnapshotMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,55 +56,55 @@ public SnapshotMetadata(params KeyValuePair<string, string>[] 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]
public IReadOnlyCollection<ISourceId> 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)));
}



}
}
}
6 changes: 3 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e544b76

Please sign in to comment.