-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Namespaces, Async Publish, AllPresistenceIdsProjection
- Loading branch information
Showing
18 changed files
with
177 additions
and
45 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 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 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 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
6 changes: 3 additions & 3 deletions
6
EventSourced.Example/ReadModel/CounterCurrentValuesReadModelBuilder.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
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; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using SqlStreamStore; | ||
using SqlStreamStore.Streams; | ||
using SqlStreamStore.Subscriptions; | ||
|
||
namespace EventSourced.Framework { | ||
|
||
public class AllPersistenceIdsProjection : IAllPersistenceIdsProjection | ||
{ | ||
private readonly IStreamStore streamStore; | ||
private HashSet<StreamId> streamIds; | ||
private bool hasCaughtUp; | ||
private long lastPosition; | ||
|
||
public AllPersistenceIdsProjection(IStreamStore streamStore) | ||
{ | ||
this.streamIds = new HashSet<StreamId>(); | ||
this.streamStore = streamStore; | ||
|
||
this.streamStore.SubscribeToAll(null, NotifAllStreamMessageReceived, NotifAllSubscriptionDropped, NotifyHasCaughtUp); | ||
} | ||
|
||
public bool IsUpToDate => hasCaughtUp && lastPosition == streamStore.ReadHeadPosition().Result; | ||
|
||
public ReadOnlyCollection<StreamId> StreamIds => new ReadOnlyCollection<StreamId>(streamIds.ToList()); | ||
|
||
public async Task WaitUntilIsUpToDate() | ||
{ | ||
while (!IsUpToDate) | ||
await Task.Delay(10); | ||
} | ||
|
||
private async Task NotifAllStreamMessageReceived(IAllStreamSubscription subscription, StreamMessage streamMessage, CancellationToken cancellationToken) | ||
{ | ||
streamIds.Add(new StreamId(streamMessage.StreamId)); | ||
lastPosition = streamMessage.Position; | ||
} | ||
|
||
private void NotifyHasCaughtUp(bool hasCaughtUp) => this.hasCaughtUp = hasCaughtUp; | ||
|
||
private void NotifAllSubscriptionDropped(IAllStreamSubscription subscription, SubscriptionDroppedReason reason, Exception exception = null) | ||
{ | ||
} | ||
|
||
} | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
EventSourced.Framework/EventSourced.cs → EventSourced.Framework/EventSourcedBase.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
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 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,16 @@ | ||
using System.Collections.ObjectModel; | ||
using System.Threading.Tasks; | ||
using SqlStreamStore.Streams; | ||
|
||
namespace EventSourced.Framework | ||
{ | ||
public interface IAllPersistenceIdsProjection | ||
{ | ||
|
||
bool IsUpToDate { get; } | ||
|
||
ReadOnlyCollection<StreamId> StreamIds { get; } | ||
|
||
Task WaitUntilIsUpToDate(); | ||
} | ||
} |
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 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,57 @@ | ||
using System; | ||
using Xunit; | ||
using SqlStreamStore; | ||
using SqlStreamStore.Streams; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using SqlStreamStore.Subscriptions; | ||
using EventSourced.Framework; | ||
|
||
namespace EventSourced.Tests | ||
{ | ||
public class AllPersistenceIdsProjectionTests | ||
{ | ||
|
||
[Fact] | ||
public async Task GivenExistingEventStore_CanBuildAllPersistenceIdsProjection() | ||
{ | ||
var streamStore = new InMemoryStreamStore(); | ||
|
||
var stream1 = new StreamId("test1"); | ||
var message1 = new NewStreamMessage(Guid.NewGuid(), "Test1", @"{ 'Hello': 'World1' }"); | ||
await streamStore.AppendToStream(stream1, ExpectedVersion.Any, message1); | ||
|
||
var stream2 = new StreamId("test2"); | ||
var message2 = new NewStreamMessage(Guid.NewGuid(), "Test2", @"{ 'Hello': 'World2' }"); | ||
await streamStore.AppendToStream(stream2, ExpectedVersion.Any, message2); | ||
|
||
var allPersistenceIdsProjection = new AllPersistenceIdsProjection(streamStore); | ||
|
||
await allPersistenceIdsProjection.WaitUntilIsUpToDate(); | ||
|
||
Assert.Equal(2, allPersistenceIdsProjection.StreamIds.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task GivenExistingEventStore_WhenAddingAnEventToTheStore_AllPersistenceIdsProjectionIsUpdated() | ||
{ | ||
var streamStore = new InMemoryStreamStore(); | ||
|
||
var stream1 = new StreamId("test1"); | ||
var message1 = new NewStreamMessage(Guid.NewGuid(), "Test1", @"{ 'Hello': 'World1' }"); | ||
await streamStore.AppendToStream(stream1, ExpectedVersion.Any, message1); | ||
|
||
var allPersistenceIdsProjection = new AllPersistenceIdsProjection(streamStore); | ||
|
||
await allPersistenceIdsProjection.WaitUntilIsUpToDate(); | ||
Assert.Equal(1, allPersistenceIdsProjection.StreamIds.Count); | ||
|
||
var stream2 = new StreamId("test2"); | ||
var message2 = new NewStreamMessage(Guid.NewGuid(), "Test2", @"{ 'Hello': 'World2' }"); | ||
await streamStore.AppendToStream(stream2, ExpectedVersion.Any, message2); | ||
|
||
await allPersistenceIdsProjection.WaitUntilIsUpToDate(); | ||
Assert.Equal(2, allPersistenceIdsProjection.StreamIds.Count); | ||
} | ||
} | ||
} |
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