public void GetTopicDoesNotChangeStateWhenNotDying() { var dr = new DefaultDependencyResolver(); var configuration = dr.Resolve <IConfigurationManager>(); configuration.DisconnectTimeout = TimeSpan.FromSeconds(6); configuration.KeepAlive = null; using (var bus = new MessageBus(dr)) { bus.Subscribe(new TestSubscriber(new[] { "key" }), null, (result, state) => TaskAsyncHelper.True, 10, null); Topic topic; Assert.True(bus.Topics.TryGetValue("key", out topic)); Assert.Equal(TopicState.HasSubscriptions, topic.State); topic = bus.GetTopic("key"); Assert.Equal(TopicState.HasSubscriptions, topic.State); topic.RemoveSubscription(topic.Subscriptions.First()); Assert.Equal(TopicState.NoSubscriptions, topic.State); topic = bus.GetTopic("key"); Assert.Equal(TopicState.NoSubscriptions, topic.State); topic.State = TopicState.Dying; topic = bus.GetTopic("key"); Assert.Equal(TopicState.NoSubscriptions, topic.State); } }
public void GarbageCollectingTopicsBeforeGettingTopicSetsStateToHasSubscriptions() { var dr = new DefaultDependencyResolver(); var configuration = dr.Resolve <IConfigurationManager>(); configuration.DisconnectTimeout = TimeSpan.FromSeconds(6); configuration.KeepAlive = null; using (var bus = new MessageBus(dr)) { bus.BeforeTopicMarked = (key, t) => { bus.GarbageCollectTopics(); }; Topic topic = bus.GetTopic("key"); Assert.Equal(1, bus.Topics.Count); Assert.True(bus.Topics.TryGetValue("key", out topic)); Assert.Equal(TopicState.HasSubscriptions, topic.State); } }
public void GettingTopicAfterNoSubscriptionsStateSetsStateToHasSubscriptions() { var dr = new DefaultDependencyResolver(); var configuration = dr.Resolve <IConfigurationManager>(); configuration.DisconnectTimeout = TimeSpan.FromSeconds(6); using (var bus = new MessageBus(dr)) { var subscriber = new TestSubscriber(new[] { "key" }); // Make sure the topic is in the no subs state bus.Subscribe(subscriber, null, (result, state) => TaskAsyncHelper.True, 10, null) .Dispose(); Topic topic = bus.GetTopic("key"); Assert.Equal(1, bus.Topics.Count); Assert.True(bus.Topics.TryGetValue("key", out topic)); Assert.Equal(TopicState.HasSubscriptions, topic.State); } }