|
| 1 | +// These Tests have to be back ported to NEventStore core because they test the IPersistStreams interface |
| 2 | +// You can safely remove them once we update NEventStore. |
| 3 | + |
| 4 | +#pragma warning disable 169 // ReSharper disable InconsistentNaming |
| 5 | +#pragma warning disable IDE1006 // Naming Styles |
| 6 | + |
| 7 | +using NEventStore.Persistence.AcceptanceTests.BDD; |
| 8 | +using FluentAssertions; |
| 9 | +#if MSTEST |
| 10 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 11 | +#endif |
| 12 | +#if NUNIT |
| 13 | +using NUnit.Framework; |
| 14 | +#endif |
| 15 | +#if XUNIT |
| 16 | +using Xunit; |
| 17 | +using Xunit.Should; |
| 18 | +#endif |
| 19 | + |
| 20 | +namespace NEventStore.Persistence.AcceptanceTests.Async |
| 21 | +{ |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// <para> |
| 25 | + /// NEventStore.Persistence.Sql issue #54 |
| 26 | + /// GetStreamsToSnapshot fails when number of streams exceeds PageSize. |
| 27 | + /// </para> |
| 28 | + /// <para> |
| 29 | + /// Query implementation was wrong: checking how the query and the pagination were implemented |
| 30 | + /// it was lacking to check for C.StreamId > @StreamId. |
| 31 | + /// which is needed to page through the results (similar to @Coalesce in GetCommitsFromStartingRevision) |
| 32 | + /// </para> |
| 33 | + /// </summary> |
| 34 | +#if MSTEST |
| 35 | + [TestClass] |
| 36 | +#endif |
| 37 | + public class when_getting_streams_to_snapshot_amount_exceeds_PageSize : PersistenceEngineConcernAsync |
| 38 | + { |
| 39 | + private int _moreThanPageSize; |
| 40 | + private Guid _lastStreamId; |
| 41 | + |
| 42 | + protected override async Task BecauseAsync() |
| 43 | + { |
| 44 | + _moreThanPageSize = ConfiguredPageSizeForTesting + 1; |
| 45 | + var eventStore = new OptimisticEventStore(Persistence, null, null); |
| 46 | + for (int i = 0; i < _moreThanPageSize; i++) |
| 47 | + { |
| 48 | + _lastStreamId = Guid.NewGuid(); |
| 49 | + using IEventStream stream = await eventStore.OpenStreamAsync(_lastStreamId).ConfigureAwait(false); |
| 50 | + stream.Add(new EventMessage { Body = new TestEvent() { S = "Hi " + i } }); |
| 51 | + await stream.CommitChangesAsync(Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false); |
| 52 | + stream.Add(new EventMessage { Body = new TestEvent() { S = "Hi " + i } }); |
| 53 | + await stream.CommitChangesAsync(Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false); |
| 54 | + stream.Add(new EventMessage { Body = new TestEvent() { S = "Hi " + i } }); |
| 55 | + await stream.CommitChangesAsync(Guid.NewGuid(), CancellationToken.None).ConfigureAwait(false); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void GetStreamsToSnapshot_does_not_crash_and_returns_all_the_streams() |
| 61 | + { |
| 62 | + Assert.DoesNotThrowAsync(async () => |
| 63 | + { |
| 64 | + var observer = new StreamHeadObserver(); |
| 65 | + await Persistence.GetStreamsToSnapshotAsync(0, observer, CancellationToken.None).ConfigureAwait(false); |
| 66 | + observer.StreamHeads.Count.Should().Be(_moreThanPageSize); |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + public void GetFrom_does_not_crash_and_returns_all_the_streams() |
| 72 | + { |
| 73 | + Assert.DoesNotThrowAsync(async () => |
| 74 | + { |
| 75 | + var observer = new CommitStreamObserver(); |
| 76 | + await Persistence.GetFromAsync(Bucket.Default, _lastStreamId.ToString(), 0, int.MaxValue, observer, CancellationToken.None).ConfigureAwait(false); |
| 77 | + observer.Commits.Count.Should().Be(3); |
| 78 | + }); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | +} |
| 83 | + |
| 84 | +#pragma warning restore 169 // ReSharper disable InconsistentNaming |
| 85 | +#pragma warning restore IDE1006 // Naming Styles |
0 commit comments