public async Task WriteAsync_should_forward_event_to_registered_subscriber(IEvent evt) { if (evt is null) { throw new ArgumentNullException(nameof(evt)); } var pattern = new PatternBuilder().FromTopic(evt.Topic).Build(); var subscription = new FakeSubscription(pattern); await subscription.EnableAsync() .ConfigureAwait(false); using var bus = new Bus(); await bus.RunAsync() .ConfigureAwait(false); bus.Subscribe(subscription); await bus.WriteAsync(evt) .ConfigureAwait(false); await subscription.WaitUntilWrite(this.waitTimeout) .ConfigureAwait(false); Assert.Collection(subscription.ReceivedEvents, e => Assert.Equal(evt, e)); }
public async Task WriteAsync_should_retry_failed_event(IEvent evt) { if (evt is null) { throw new ArgumentNullException(nameof(evt)); } var pattern = new PatternBuilder().FromTopic(evt.Topic).Build(); var blockingSubscription = new FakeSubscription(pattern, block: true); await blockingSubscription.EnableAsync().ConfigureAwait(false); using var bus = new Bus(); await bus.RunAsync().ConfigureAwait(false); bus.Subscribe(blockingSubscription); await bus.WriteAsync(evt).ConfigureAwait(false); // wait for internal cancellation Thread.Sleep(100); blockingSubscription.UnBlockWrite(); await blockingSubscription.WaitUntilWrite(this.waitTimeout).ConfigureAwait(false); Assert.Single(blockingSubscription.ReceivedEvents, evt); }
public async Task WriteAsync_should_forward_event_to_subscribers_if_first_subscriber_is_blocking(IEvent evt) { if (evt is null) { throw new ArgumentNullException(nameof(evt)); } var pattern = new PatternBuilder().FromTopic(evt.Topic).Build(); var blockingSubscription = new FakeSubscription(pattern, block: true); await blockingSubscription.EnableAsync().ConfigureAwait(false); var subscription = new FakeSubscription(pattern); await subscription.EnableAsync().ConfigureAwait(false); using var bus = new Bus(); await bus.RunAsync().ConfigureAwait(false); bus.Subscribe(blockingSubscription); bus.Subscribe(subscription); await bus.WriteAsync(evt).ConfigureAwait(false); await subscription.WaitUntilWrite(this.waitTimeout).ConfigureAwait(false); Assert.Single(subscription.ReceivedEvents, evt); Assert.Empty(blockingSubscription.ReceivedEvents); }
public async Task WriteAsync_should_forward_multiple_events_to_registered_subscriber(Topic topic, IEnumerable <IEvent> events) { if (topic is null) { throw new ArgumentNullException(nameof(topic)); } if (events is null) { throw new ArgumentNullException(nameof(events)); } var pattern = new PatternBuilder().FromTopic(topic).Build(); var subscription = new FakeSubscription(pattern); using var bus = new Bus(); await bus.RunAsync().ConfigureAwait(false); bus.Subscribe(subscription); foreach (var evt in events) { await bus.WriteAsync(evt).ConfigureAwait(false); await subscription.WaitUntilWrite(this.waitTimeout).ConfigureAwait(false); } Assert.All(events, e => Assert.Contains(subscription.ReceivedEvents, r => r.Id == e.Id)); }
public async Task WriteAsync_should_increment_processed_event_count_to_input_event_count(Topic topic, IEnumerable <IEvent> events) { if (topic is null) { throw new ArgumentNullException(nameof(topic)); } if (events is null) { throw new ArgumentNullException(nameof(events)); } var pattern = new PatternBuilder().FromTopic(topic).Build(); var subscription = new FakeSubscription(pattern); using var bus = new Bus(); await bus.RunAsync().ConfigureAwait(false); bus.Subscribe(subscription); foreach (var evt in events) { await bus.WriteAsync(evt).ConfigureAwait(false); await subscription.WaitUntilWrite(this.waitTimeout).ConfigureAwait(false); } var metrics = bus.GetMetrics(); var metric = Assert.Single(metrics, m => m.Name == Metrics.Bus.ProcessedEvents); Assert.Equal(events.LongCount(), metric.Value); }
public async Task WriteAsync_should_increment_processed_event_count_to_one(IEvent evt) { if (evt is null) { throw new ArgumentNullException(nameof(evt)); } var pattern = new PatternBuilder().FromTopic(evt.Topic).Build(); var subscription = new FakeSubscription(pattern); await subscription.EnableAsync().ConfigureAwait(false); using var bus = new Bus(); await bus.RunAsync().ConfigureAwait(false); bus.Subscribe(subscription); await bus.WriteAsync(evt).ConfigureAwait(false); await subscription.WaitUntilWrite(this.waitTimeout).ConfigureAwait(false); var metrics = bus.GetMetrics(); var metric = Assert.Single(metrics, m => m.Name == Metrics.Bus.ProcessedEvents); Assert.Equal(1L, metric.Value); }