public void ShouldRetrieveClients() { var logger = new MockLogger(); var directoryClient = new PeerDirectoryClient(logger); var messageParisKo = new DatabaseStatus() { DatacenterName = "Paris", Status = "Ko" }; var messageParisOk = new DatabaseStatus() { DatacenterName = "Paris", Status = "Ok" }; var messageLondonKo = new DatabaseStatus() { DatacenterName = "London", Status = "Ko" }; var messageLondonOk = new DatabaseStatus() { DatacenterName = "London", Status = "Ok" }; var peer1 = new Peer(new PeerId("Abc.Testing." + Guid.NewGuid()), "tcp://localhost:8080"); var peer2 = new Peer(new PeerId("Abc.Testing." + Guid.NewGuid()), "tcp://localhost:8181"); var allParisKo = Subscription.Matching <DatabaseStatus>(x => x.DatacenterName == "Paris" && x.Status == "Ko"); var allParis = Subscription.Matching <DatabaseStatus>(x => x.DatacenterName == "Paris"); var allKo = Subscription.Matching <DatabaseStatus>(x => x.Status == "Ko"); var peer1Descriptor = new PeerDescriptor(peer1.Id, peer1.EndPoint, false, true, DateTime.Now, allParisKo, allParis); var peer2Descriptor = new PeerDescriptor(peer2.Id, peer2.EndPoint, false, true, DateTime.Now, allKo); directoryClient.Handle(new PeerActivated(peer1Descriptor)); directoryClient.Handle(new PeerActivated(peer2Descriptor)); var peers = directoryClient.GetPeersHandlingMessage(messageParisKo); Assert.AreEqual(2, peers.Count()); peers = directoryClient.GetPeersHandlingMessage(messageParisOk); Assert.AreEqual(1, peers.Count()); peers = directoryClient.GetPeersHandlingMessage(messageLondonKo); Assert.AreEqual(1, peers.Count()); peers = directoryClient.GetPeersHandlingMessage(messageLondonOk); Assert.AreEqual(0, peers.Count()); }
public void MeasureUpdatePerformance() { var subscriptions = new List <Subscription>(); for (var typeIdIndex = 0; typeIdIndex < 20; ++typeIdIndex) { var typeId = new MessageTypeId("Abc.Foo.Events.FakeEvent" + typeIdIndex); for (var routingIndex = 0; routingIndex < 500; ++routingIndex) { subscriptions.Add(new Subscription(typeId, new BindingKey(routingIndex.ToString()))); } } var subscriptionsByTypeId = subscriptions.GroupBy(x => x.MessageTypeId).ToDictionary(x => x.Key, x => x.Select(s => s.BindingKey).ToArray()); _directory = new PeerDirectoryClient(_configurationMock.Object); _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false))); Console.WriteLine("Snapshot updates (add)"); using (Measure.Throughput(subscriptions.Count)) { for (var subscriptionCount = 1; subscriptionCount <= subscriptions.Count; ++subscriptionCount) { _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount)))); } } Console.WriteLine("Snapshot updates (remove)"); using (Measure.Throughput(subscriptions.Count)) { for (var subscriptionCount = subscriptions.Count; subscriptionCount >= 1; --subscriptionCount) { _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount)))); } } _directory = new PeerDirectoryClient(_configurationMock.Object); _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false))); Console.WriteLine("Snapshot updates per message type id (add)"); using (Measure.Throughput(subscriptions.Count)) { foreach (var subscriptionGroup in subscriptionsByTypeId) { _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key, subscriptionGroup.Value)); } } Console.WriteLine("Snapshot updates per message type id (remove)"); using (Measure.Throughput(subscriptions.Count)) { foreach (var subscriptionGroup in subscriptionsByTypeId) { _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key)); } } }
public void MeasureUpdatePerformance() { var subscriptions = new List<Subscription>(); for (var typeIdIndex = 0; typeIdIndex < 20; ++typeIdIndex) { var typeId = new MessageTypeId("Abc.Foo.Events.FakeEvent" + typeIdIndex); for (var routingIndex = 0; routingIndex < 500; ++routingIndex) { subscriptions.Add(new Subscription(typeId, new BindingKey(routingIndex.ToString()))); } } var subscriptionsByTypeId = subscriptions.GroupBy(x => x.MessageTypeId).ToDictionary(x => x.Key, x => x.Select(s=>s.BindingKey).ToArray()); _directory = new PeerDirectoryClient(_configurationMock.Object); _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false))); Console.WriteLine("Snapshot updates (add)"); using (Measure.Throughput(subscriptions.Count)) { for (var subscriptionCount = 1; subscriptionCount <= subscriptions.Count; ++subscriptionCount) { _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount)))); } } Console.WriteLine("Snapshot updates (remove)"); using (Measure.Throughput(subscriptions.Count)) { for (var subscriptionCount = subscriptions.Count; subscriptionCount >= 1; --subscriptionCount) { _directory.Handle(new PeerSubscriptionsUpdated(_otherPeer.ToPeerDescriptor(false, subscriptions.Take(subscriptionCount)))); } } _directory = new PeerDirectoryClient(_configurationMock.Object); _directory.Handle(new PeerStarted(_otherPeer.ToPeerDescriptor(false))); Console.WriteLine("Snapshot updates per message type id (add)"); using (Measure.Throughput(subscriptions.Count)) { foreach (var subscriptionGroup in subscriptionsByTypeId) { _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key, subscriptionGroup.Value)); } } Console.WriteLine("Snapshot updates per message type id (remove)"); using (Measure.Throughput(subscriptions.Count)) { foreach (var subscriptionGroup in subscriptionsByTypeId) { _directory.Handle(new PeerSubscriptionsForTypesUpdated(_otherPeer.Id, DateTime.UtcNow, subscriptionGroup.Key)); } } }
public void Setup() { _configurationMock = new Mock <IBusConfiguration>(); _configurationMock.SetupGet(x => x.DirectoryServiceEndPoints).Returns(new[] { "tcp://main-directory:777", "tcp://backup-directory:777" }); _configurationMock.SetupGet(x => x.RegistrationTimeout).Returns(500.Milliseconds()); _configurationMock.SetupGet(x => x.IsDirectoryPickedRandomly).Returns(false); _directory = new PeerDirectoryClient(_configurationMock.Object); _bus = new TestBus(); _self = new Peer(new PeerId("Abc.Testing.0"), "tcp://abctest:123"); _otherPeer = new Peer(new PeerId("Abc.Testing.1"), "tcp://abctest:789"); }
public void Setup() { _configurationMock = new Mock<IBusConfiguration>(); _configurationMock.SetupGet(x => x.DirectoryServiceEndPoints).Returns(new[] { "tcp://main-directory:777", "tcp://backup-directory:777" }); _configurationMock.SetupGet(x => x.RegistrationTimeout).Returns(100.Milliseconds()); _configurationMock.SetupGet(x => x.IsDirectoryPickedRandomly).Returns(false); _directory = new PeerDirectoryClient(_configurationMock.Object); _bus = new TestBus(); _self = new Peer(new PeerId("Abc.Testing.0"), "tcp://abctest:123"); _otherPeer = new Peer(new PeerId("Abc.Testing.1"), "tcp://abctest:789"); }