public void MeasureDynamicSubscriptionsPerformance(string routingKey) { var subscriptions = GenerateSubscriptions().ToList(); Console.WriteLine("{0} subscriptions", subscriptions.Count); Console.WriteLine(); var subscriptionList = new PeerSubscriptionList(); var subscriptionTree = new PeerSubscriptionTree(); foreach (var peerSubscription in subscriptions) { subscriptionList.Add(peerSubscription.Item1, peerSubscription.Item2); subscriptionTree.Add(peerSubscription.Item1, peerSubscription.Item2.BindingKey); } var bindingKey = BindingKey.Split(routingKey); Console.WriteLine("{0} test -------------", subscriptionList.GetType().Name); Console.WriteLine(); Measure.Execution(x => { x.Iteration = 10000; x.WarmUpIteration = 1000; x.Action = _ => subscriptionList.GetPeers(bindingKey); }); Console.WriteLine(); Console.WriteLine("{0} test -------------", subscriptionTree.GetType().Name); Console.WriteLine(); Measure.Execution(x => { x.Iteration = 10000; x.WarmUpIteration = 1000; x.Action = _ => subscriptionTree.GetPeers(bindingKey); }); }
public void simple_subscription_key_should_simple_routing_key() { var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("Abc.Testing.0"), "tcp://test:123"); peerSubscriptionTree.Add(peer, new BindingKey("a")); var matchingPeer = peerSubscriptionTree.GetPeers(new BindingKey("a")).ExpectedSingle(); matchingPeer.Id.ShouldEqual(peer.Id); }
public void empty_subscription_key_should_match_empty_routing_key() { var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("Abc.Testing.0"), "tcp://test:123"); peerSubscriptionTree.Add(peer, BindingKey.Empty); var matchingPeer = peerSubscriptionTree.GetPeers(BindingKey.Empty).ExpectedSingle(); matchingPeer.Id.ShouldEqual(peer.Id); }
public void empty_bindingkey_should_always_match(string routingKey) { // Arrange var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("jesuistonpeer"), "endpoint"); peerSubscriptionTree.Add(peer, BindingKey.Empty); // Act var matchingPeers = peerSubscriptionTree.GetPeers(BindingKey.Split(routingKey)); // Assert matchingPeers.Single().ShouldEqual(peer); }
public void stars_should_always_match_if_same_number_of_parts(string routingKey) { // Arrange var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("jesuistonpeer"), "endpoint"); var subscription = BindingKey.Split("*.*.*"); peerSubscriptionTree.Add(peer, subscription); // Act var matchingPeers = peerSubscriptionTree.GetPeers(BindingKey.Split(routingKey)); // Assert matchingPeers.Single().ShouldEqual(peer); }
public void MeasureStaticSubscriptionsPerformance() { var peers = Enumerable.Range(0, 100).Select(x => new Peer(new PeerId("Abc.Testing" + x), "tcp://testing:" + x)).ToList(); Console.WriteLine("{0} peers", peers.Count); Console.WriteLine(); var subscriptionList = new PeerSubscriptionList(); var subscriptionTree = new PeerSubscriptionTree(); foreach (var peer in peers) { subscriptionList.Add(peer, Subscription.Any<FakeEvent>()); subscriptionTree.Add(peer, BindingKey.Empty); } Console.WriteLine("{0} test -------------", subscriptionList.GetType().Name); Console.WriteLine(); Measure.Execution(x => { x.Iteration = 100000; x.WarmUpIteration = 1000; x.Action = _ => subscriptionList.GetPeers(BindingKey.Empty); }); Console.WriteLine(); Console.WriteLine("{0} test -------------", subscriptionTree.GetType().Name); Console.WriteLine(); Measure.Execution(x => { x.Iteration = 100000; x.WarmUpIteration = 1000; x.Action = _ => subscriptionTree.GetPeers(BindingKey.Empty); }); }
public void binding_key_with_star_should_match_routing_key(string subscriptionKey) { // Arrange var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("jesuistonpeer"), "endpoint"); var subscription = BindingKey.Split(subscriptionKey); peerSubscriptionTree.Add(peer, subscription); // Act var matchingPeers = peerSubscriptionTree.GetPeers(new BindingKey("a", "b", "c")); // Assert matchingPeers.Single().ShouldEqual(peer); }
public void invalid_subscription_should_not_match_routing_key(string subscriptionKey, string routingKey) { // Arrange var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("jesuistonpeer"), "endpoint"); var subscription = BindingKey.Split(subscriptionKey); peerSubscriptionTree.Add(peer, subscription); // Act var matchingPeers = peerSubscriptionTree.GetPeers(BindingKey.Split(routingKey)); // Assert matchingPeers.ShouldBeEmpty(); }
public void roundtrip_test() { // Arrange var peerSubscriptionTree = new PeerSubscriptionTree(); var peer1 = new Peer(new PeerId("1"), "endpoint"); var peer2 = new Peer(new PeerId("2"), "endpoint"); var peer3 = new Peer(new PeerId("3"), "endpoint"); var peer4 = new Peer(new PeerId("4"), "endpoint"); var peer5 = new Peer(new PeerId("5"), "endpoint"); var peer6 = new Peer(new PeerId("6"), "endpoint"); var peer7 = new Peer(new PeerId("7"), "endpoint"); var peer8 = new Peer(new PeerId("8"), "endpoint"); var peer9 = new Peer(new PeerId("9"), "endpoint"); var peer0 = new Peer(new PeerId("0"), "endpoint"); peerSubscriptionTree.Add(peer1, BindingKey.Split("#")); peerSubscriptionTree.Add(peer2, BindingKey.Split("a.b")); peerSubscriptionTree.Add(peer3, BindingKey.Split("a.*")); peerSubscriptionTree.Add(peer4, BindingKey.Split("b.*.c")); peerSubscriptionTree.Add(peer5, BindingKey.Split("b.*.f")); peerSubscriptionTree.Add(peer6, BindingKey.Split("d.*.c")); peerSubscriptionTree.Add(peer7, BindingKey.Split("a")); peerSubscriptionTree.Add(peer8, BindingKey.Split("*.*")); peerSubscriptionTree.Add(peer9, BindingKey.Split("a.#")); peerSubscriptionTree.Add(peer0, BindingKey.Split("*")); // Act - Assert var peers = peerSubscriptionTree.GetPeers(BindingKey.Split("b.1.c")); peers.Count.ShouldEqual(2); peers.ShouldContain(peer1); peers.ShouldContain(peer4); peers = peerSubscriptionTree.GetPeers(BindingKey.Split("a.1")); peers.Count.ShouldEqual(4); peers.ShouldContain(peer1); peers.ShouldContain(peer3); peers.ShouldContain(peer8); peers.ShouldContain(peer9); peers = peerSubscriptionTree.GetPeers(BindingKey.Split("a")); peers.Count.ShouldEqual(3); peers.ShouldContain(peer1); peers.ShouldContain(peer7); peers.ShouldContain(peer0); }
public void should_ignore_duplicates() { var peerSubscriptionTree = new PeerSubscriptionTree(); var peer = new Peer(new PeerId("1"), "endpoint"); peerSubscriptionTree.Add(peer, BindingKey.Empty); peerSubscriptionTree.Add(peer, BindingKey.Empty); peerSubscriptionTree.Add(peer, new BindingKey("123")); peerSubscriptionTree.Add(peer, new BindingKey("123")); peerSubscriptionTree.Add(peer, new BindingKey("123.456")); peerSubscriptionTree.Add(peer, new BindingKey("123.456")); var peers = peerSubscriptionTree.GetPeers(BindingKey.Empty); peers.Count.ShouldEqual(1); peerSubscriptionTree.Remove(peer, BindingKey.Empty); peerSubscriptionTree.IsEmpty.ShouldBeFalse(); peerSubscriptionTree.Remove(peer, new BindingKey("123")); peerSubscriptionTree.IsEmpty.ShouldBeFalse(); peerSubscriptionTree.Remove(peer, new BindingKey("123.456")); peerSubscriptionTree.IsEmpty.ShouldBeTrue(); }