Exemple #1
0
            protected override async Task Given()
            {
                foreach (var @event in CreateTestEvents(10))
                {
                    await StreamsClient.AppendToStreamAsync("non-system-stream-" + Guid.NewGuid(),
                                                            StreamState.Any, new[] { @event });
                }

                await Client.CreateToAllAsync(Group, new PersistentSubscriptionSettings(startFrom : Position.End), TestCredentials.Root);

                _subscription = await Client.SubscribeToAllAsync(Group,
                                                                 (subscription, e, r, ct) => {
                    if (SystemStreams.IsSystemStream(e.OriginalStreamId))
                    {
                        return(Task.CompletedTask);
                    }
                    _firstNonSystemEventSource.TrySetResult(e);
                    return(Task.CompletedTask);
                }, (subscription, reason, ex) => {
                    if (reason != SubscriptionDroppedReason.Disposed)
                    {
                        _firstNonSystemEventSource.TrySetException(ex !);
                    }
                }, TestCredentials.Root);
            }
Exemple #2
0
            protected override async Task Given()
            {
                foreach (var e in _events)
                {
                    await StreamsClient.AppendToStreamAsync("test-" + Guid.NewGuid(), StreamState.Any, new[] { e });
                }

                await Client.CreateToAllAsync(Group,
                                              new PersistentSubscriptionSettings(startFrom : Position.Start, resolveLinkTos : true),
                                              TestCredentials.Root);

                _subscription = await Client.SubscribeToAllAsync(Group,
                                                                 async(subscription, e, retryCount, ct) => {
                    await subscription.Ack(e);

                    if (e.OriginalStreamId.StartsWith("test-") &&
                        Interlocked.Increment(ref _eventReceivedCount) == _events.Length)
                    {
                        _eventsReceived.TrySetResult(true);
                    }
                }, (s, r, e) => {
                    if (e != null)
                    {
                        _eventsReceived.TrySetException(e);
                    }
                },
                                                                 autoAck : false,
                                                                 bufferSize : BufferCount,
                                                                 userCredentials : TestCredentials.Root);
            }
Exemple #3
0
            protected override async Task Given()
            {
                foreach (var e in _events)
                {
                    await StreamsClient.AppendToStreamAsync(Stream, StreamState.Any, new[] { e });
                }

                await Client.CreateAsync(Stream, Group,
                                         new PersistentSubscriptionSettings(startFrom : StreamPosition.Start, resolveLinkTos : true),
                                         TestCredentials.Root);

                _subscription = await Client.SubscribeAsync(Stream, Group,
                                                            (subscription, e, retryCount, ct) => {
                    if (Interlocked.Increment(ref _eventReceivedCount) == _events.Length)
                    {
                        _eventsReceived.TrySetResult(true);
                    }

                    return(Task.CompletedTask);
                }, (s, r, e) => {
                    if (e != null)
                    {
                        _eventsReceived.TrySetException(e);
                    }
                },
                                                            bufferSize : BufferCount,
                                                            userCredentials : TestCredentials.Root);
            }
Exemple #4
0
            protected override async Task Given()
            {
                await StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, Events);

                await Client.CreateAsync(Stream, Group,
                                         new PersistentSubscriptionSettings(startFrom : StreamPosition.Start), TestCredentials.Root);

                _subscription = await Client.SubscribeAsync(Stream, Group,
                                                            async (subscription, e, r, ct) => {
                    if (r > 4)
                    {
                        _retryCountSource.TrySetResult(r.Value);
                        await subscription.Ack(e.Event.EventId);
                    }
                    else
                    {
                        await subscription.Nack(PersistentSubscriptionNakEventAction.Retry,
                                                "Not yet tried enough times", e);
                    }
                }, autoAck : false, subscriptionDropped : (subscription, reason, ex) => {
                    if (reason != SubscriptionDroppedReason.Disposed)
                    {
                        _retryCountSource.TrySetException(ex !);
                    }
                }, userCredentials : TestCredentials.TestUser1);
            }
Exemple #5
0
            protected override async Task Given()
            {
                await StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, CreateTestEvents());

                await Client.CreateAsync(Stream, Group, new PersistentSubscriptionSettings(),
                                         TestCredentials.Root);
            }
 protected override async Task When()
 {
     foreach (var e in _events)
     {
         await StreamsClient.AppendToStreamAsync(Stream, StreamState.Any, new[] { e });
     }
 }
Exemple #7
0
            protected override async Task Given()
            {
                await StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, Events);

                await Client.CreateAsync(Stream, Group,
                                         new PersistentSubscriptionSettings(startFrom : StreamPosition.End), TestCredentials.Root);
            }
Exemple #8
0
            protected override async Task Given()
            {
                await StreamsClient.AppendToStreamAsync(Guid.NewGuid().ToString(), StreamState.NoStream,
                                                        CreateTestEvents(256));

                await StreamsClient.SetStreamMetadataAsync(SystemStreams.AllStream, StreamState.Any,
                                                           new StreamMetadata(acl : new StreamAcl(SystemRoles.All)), userCredentials : TestCredentials.Root);
            }
 protected override async Task When()
 {
     foreach (var e in _events)
     {
         await StreamsClient.AppendToStreamAsync("filtered-out-stream-" + Guid.NewGuid(),
                                                 StreamState.Any, new[] { e });
     }
 }
            protected override async Task When()
            {
                await StreamsClient.AppendToStreamAsync(Stream, StreamState.Any, CreateTestEvents());

                await Client.CreateAsync(Stream, "existing",
                                         new PersistentSubscriptionSettings(), TestCredentials.Root);

                await Client.DeleteAsync(Stream, "existing",
                                         TestCredentials.Root);
            }
Exemple #11
0
            protected override async Task Given()
            {
                foreach (var @event in CreateTestEvents(10))
                {
                    await StreamsClient.AppendToStreamAsync("non-system-stream-" + Guid.NewGuid(),
                                                            StreamState.Any, new[] { @event });
                }

                await Client.CreateToAllAsync(Group,
                                              new PersistentSubscriptionSettings(startFrom : Position.End), TestCredentials.Root);
            }
Exemple #12
0
            protected override async Task Given()
            {
                //append 10 events to random streams to make sure we have at least 10 events in the transaction file
                foreach (var @event in CreateTestEvents(10))
                {
                    await StreamsClient.AppendToStreamAsync(Guid.NewGuid().ToString(), StreamState.NoStream, new [] { @event });
                }
                Events = await StreamsClient.ReadAllAsync(Direction.Forwards, Position.Start, 10, userCredentials : TestCredentials.Root).ToArrayAsync();

                await Client.CreateToAllAsync(Group,
                                              new PersistentSubscriptionSettings(startFrom : Position.Start), TestCredentials.Root);
            }
            protected override async Task When()
            {
                // Force restart of the subscription
                await Client.UpdateAsync(Stream, Group, new PersistentSubscriptionSettings(), TestCredentials.Root);

                await _droppedSource.Task.WithTimeout();

                _secondSubscription = await Client.SubscribeAsync(Stream, Group,
                                                                  eventAppeared : (s, e, r, ct) => {
                    _resumedSource.TrySetResult(e);
                    return(Task.CompletedTask);
                },
                                                                  userCredentials : TestCredentials.Root);

                await StreamsClient.AppendToStreamAsync(Stream, StreamState.Any, CreateTestEvents(1));
            }
            protected override async Task Given()
            {
                foreach (var e in _events)
                {
                    await StreamsClient.AppendToStreamAsync("test-" + Guid.NewGuid(), StreamState.Any, new[] { e });
                }

                await Client.CreateToAllAsync(Group,
                                              StreamFilter.Prefix("test"),
                                              new PersistentSubscriptionSettings(
                                                  minCheckPointCount : 5,
                                                  checkPointAfter : TimeSpan.FromSeconds(1),
                                                  startFrom : Position.Start),
                                              TestCredentials.Root);

                _checkPointSubscription = await StreamsClient.SubscribeToStreamAsync(_checkPointStream,
                                                                                     (s, e, ct) => {
                    if (_checkPoints.Count == 0)
                    {
                        _firstCheckPointSource.TrySetResult(e);
                    }
                    else
                    {
                        _secondCheckPointSource.TrySetResult(e);
                    }
                    _checkPoints.Add(e);
                    return(Task.CompletedTask);
                },
                                                                                     userCredentials : TestCredentials.Root);

                _subscription = await Client.SubscribeToAllAsync(Group,
                                                                 eventAppeared : (s, e, r, ct) => {
                    _appearedEvents.Add(e);

                    if (_appearedEvents.Count == _events.Length)
                    {
                        _appeared.TrySetResult(true);
                    }
                    return(Task.CompletedTask);
                },
                                                                 userCredentials : TestCredentials.Root);

                await Task.WhenAll(_appeared.Task, _firstCheckPointSource.Task).WithTimeout();

                FirstCheckPoint = _firstCheckPointSource.Task.Result.Event.Data.ParsePosition();
            }
            protected override async Task Given()
            {
                await StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, Events.Take(11));

                await Client.CreateAsync(Stream, Group,
                                         new PersistentSubscriptionSettings(startFrom : new StreamPosition(11)), TestCredentials.Root);

                _subscription = await Client.SubscribeAsync(Stream, Group,
                                                            (subscription, e, r, ct) => {
                    _firstEventSource.TrySetResult(e);
                    return(Task.CompletedTask);
                }, (subscription, reason, ex) => {
                    if (reason != SubscriptionDroppedReason.Disposed)
                    {
                        _firstEventSource.TrySetException(ex !);
                    }
                }, TestCredentials.TestUser1);
            }
Exemple #16
0
            protected override async Task When()
            {
                // Force restart of the subscription
                await Client.UpdateToAllAsync(Group, new PersistentSubscriptionSettings(), TestCredentials.Root);

                await _droppedSource.Task.WithTimeout();

                _secondSubscription = await Client.SubscribeToAllAsync(Group,
                                                                       eventAppeared : (s, e, r, ct) => {
                    _resumedSource.TrySetResult(e);
                    return(Task.CompletedTask);
                },
                                                                       userCredentials : TestCredentials.Root);

                foreach (var e in _events)
                {
                    await StreamsClient.AppendToStreamAsync("test-" + Guid.NewGuid(), StreamState.Any, new[] { e });
                }
            }
Exemple #17
0
            protected override async Task Given()
            {
                foreach (var e in _events)
                {
                    await StreamsClient.AppendToStreamAsync("test-" + Guid.NewGuid(), StreamState.Any, new[] { e });
                }

                await Client.CreateToAllAsync(Group,
                                              new PersistentSubscriptionSettings(
                                                  minCheckPointCount : 5,
                                                  checkPointAfter : TimeSpan.FromSeconds(1),
                                                  startFrom : Position.Start),
                                              TestCredentials.Root);

                var checkPointStream = $"$persistentsubscription-$all::{Group}-checkpoint";

                _checkPointSubscription = await StreamsClient.SubscribeToStreamAsync(checkPointStream,
                                                                                     (s, e, ct) => {
                    _checkPointSource.TrySetResult(e);
                    return(Task.CompletedTask);
                },
                                                                                     userCredentials : TestCredentials.Root);

                _firstSubscription = await Client.SubscribeToAllAsync(Group,
                                                                      eventAppeared : (s, e, r, ct) => {
                    _appearedEvents.Add(e);

                    if (_appearedEvents.Count == _events.Length)
                    {
                        _appeared.TrySetResult(true);
                    }
                    return(Task.CompletedTask);
                },
                                                                      (subscription, reason, ex) => _droppedSource.TrySetResult((reason, ex)),
                                                                      TestCredentials.Root);

                await Task.WhenAll(_appeared.Task, _checkPointSource.Task).WithTimeout();

                CheckPoint = _checkPointSource.Task.Result.Event.Data.ParsePosition();
            }
Exemple #18
0
 protected override Task When() => StreamsClient.AppendToStreamAsync(nameof(get_state), StreamState.NoStream,
                                                                     CreateTestEvents());
 protected override Task When() =>
 StreamsClient.AppendToStreamAsync(Stream, new StreamRevision(10), Events.Skip(11));
Exemple #20
0
 protected override Task When() =>
 StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, Events);
 protected override async Task When()
 {
     await StreamsClient.AppendToStreamAsync(nameof(get_result), StreamState.NoStream,
                                             CreateTestEvents());
 }
 protected override async Task When() =>
 await StreamsClient.AppendToStreamAsync(Stream, StreamState.Any, CreateTestEvents());
Exemple #23
0
 protected override async Task When()
 {
     await StreamsClient.AppendToStreamAsync(ExpectedStreamId, StreamState.NoStream, new [] { ExpectedEvent });
 }