Browse Source

Add guard clause to subscriptionsForTypes handler

Kevin Lovato 10 years ago
parent
commit
da8c5758bc

+ 12 - 0
src/Abc.Zebus.Directory.Tests/Handlers/DirectoryCommandsHandlerTests.cs

@@ -317,6 +317,18 @@ namespace Abc.Zebus.Directory.Tests.Handlers
             _repositoryMock.Verify(repo => repo.RemoveDynamicSubscriptionsForTypes(peerDescriptor.PeerId, now, new[] { MessageUtil.GetTypeId(typeof(int)) }));
         }
 
+        [Test]
+        public void should_handle_null_subscriptionsByType_array()
+        {
+            var peerDescriptor = TestDataBuilder.CreatePersistentPeerDescriptor("tcp://abctest:123", typeof(FakeCommand));
+            var now = DateTime.UtcNow;
+
+            Assert.That(() => _handler.Handle(new UpdatePeerSubscriptionsForTypesCommand(peerDescriptor.PeerId, now, null)),
+                        Throws.Nothing);
+
+            _bus.ExpectNothing();
+        }
+
         [Test]
         public void should_remove_peer_subscriptions_for_a_type_if_there_are_no_binding_keys()
         {

+ 3 - 0
src/Abc.Zebus.Directory/Handlers/DirectoryCommandsHandler.cs

@@ -102,6 +102,9 @@ namespace Abc.Zebus.Directory.Handlers
 
         public void Handle(UpdatePeerSubscriptionsForTypesCommand message)
         {
+            if (message.SubscriptionsForTypes == null || message.SubscriptionsForTypes.Length == 0)
+                return;
+
             var subscriptionsToAdd = message.SubscriptionsForTypes.Where(sub => sub.BindingKeys != null && sub.BindingKeys.Any()).ToArray();
             var subscriptionsToRemove = message.SubscriptionsForTypes.Where(sub => sub.BindingKeys == null || !sub.BindingKeys.Any()).ToList();