public void TestThatFeedFeedsMultipleSubscribers() { _feed = _world.ActorFor <ISseFeed>(() => new AllSseFeedActor("all", 10, "1")); var subscriber1 = new SseSubscriber("all", _client, "ABC123", "41"); var subscriber2 = new SseSubscriber("all", _client, "ABC456", "42"); var subscriber3 = new SseSubscriber("all", _client, "ABC789", "43"); var respondWithSafely = _context.Channel.ExpectRespondWith(3); _feed.To(new List <SseSubscriber> { subscriber1, subscriber2, subscriber3 }); Assert.Equal(3, respondWithSafely.ReadFrom <int>("count")); Assert.Equal(3, _context.Channel.RespondWithCount.Get()); }
public void Unsubscribe(SseSubscriber subscriber) { if (!_actor.IsStopped) { Action <ISsePublisher> consumer = actor => actor.Unsubscribe(subscriber); if (_mailbox.IsPreallocated) { _mailbox.Send(_actor, consumer, null, UnsubscribeRepresentation2); } else { _mailbox.Send(new LocalMessage <ISsePublisher>(_actor, consumer, UnsubscribeRepresentation2)); } } else { _actor.DeadLetters?.FailedDelivery(new DeadLetter(_actor, UnsubscribeRepresentation2)); } }
public void TestThatFeedFeedsOneSubscriber() { var respondWithSafely = _context.Channel.ExpectRespondWith(1); _feed = _world.ActorFor <ISseFeed>(() => new AllSseFeedActor("all", 10, "1")); var subscriber = new SseSubscriber("all", _client, "ABC123", "42"); _feed.To(new List <SseSubscriber> { subscriber }); Assert.Equal(1, respondWithSafely.ReadFrom <int>("count")); Assert.Equal(1, _context.Channel.RespondWithCount.Get()); var eventsResponse = respondWithSafely.ReadFrom <Response>("eventsResponse"); var events = MessageEvent.From(eventsResponse); Assert.Equal(10, events.Count); }
public void TestSubscriberPropertiesBehavior() { _context.Channel.ExpectRespondWith(1); var subscriber = new SseSubscriber("all", _client, "123ABC", "42"); Assert.NotNull(subscriber.Client); Assert.Equal(_context.Id, subscriber.Id); Assert.Equal("all", subscriber.StreamName); Assert.Equal("123ABC", subscriber.CorrelationId); Assert.Equal("42", subscriber.CurrentEventId); subscriber.CurrentEventId = "4242"; Assert.Equal("4242", subscriber.CurrentEventId); Assert.True(subscriber.IsCompatibleWith("all")); Assert.False(subscriber.IsCompatibleWith("amm")); Assert.Equal(0, _context.Channel.AbandonCount.Get()); var abandonSafely = _context.Channel.ExpectAbandon(1); subscriber.Close(); Assert.Equal(1, abandonSafely.ReadFrom <int>("count")); Assert.Equal(1, _context.Channel.AbandonCount.Get()); }
public void Subscribe(SseSubscriber subscriber) => _subscribers.Add(subscriber.Id !, subscriber);