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 should_check_for_emptyness(string subscriptionKey)
        {
            var peerSubscriptionTree = new PeerSubscriptionTree();
            var peer = new Peer(new PeerId("1"), "endpoint");

            peerSubscriptionTree.IsEmpty.ShouldBeTrue();
            peerSubscriptionTree.Add(peer, BindingKey.Split(subscriptionKey));
            var subscription = BindingKey.Split("lol");

            peerSubscriptionTree.Add(peer, subscription);
            peerSubscriptionTree.IsEmpty.ShouldBeFalse();
            peerSubscriptionTree.Remove(peer, BindingKey.Split(subscriptionKey));
            peerSubscriptionTree.IsEmpty.ShouldBeFalse();
            peerSubscriptionTree.Remove(peer, subscription);
            peerSubscriptionTree.IsEmpty.ShouldBeTrue();
        }
        public void empty_bindingkey_should_return_all_subscriptions(string routingKey)
        {
            // Arrange
            var peerSubscriptionTree = new PeerSubscriptionTree();
            var peerA = new Peer(new PeerId("a"), "endpoint");
            var peerB = new Peer(new PeerId("b"), "endpoint");

            peerSubscriptionTree.Add(peerA, BindingKeyHelper.CreateFromString(routingKey, '.'));
            peerSubscriptionTree.Add(peerB, BindingKeyHelper.CreateFromString("foo.bar", '.'));

            // Act
            var matchingPeers = peerSubscriptionTree.GetPeers(BindingKey.Empty);

            // Assert
            matchingPeers.ShouldBeEquivalentTo(peerA, peerB);
        }
        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);
        }
Beispiel #5
0
        public void ShouldBuildSubscriptionTree()
        {
            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 messageKo = new DatabaseStatus()
            {
                DatacenterName = "Paris",
                Status         = "Ko"
            };

            var messageOk = new DatabaseStatus()
            {
                DatacenterName = "Paris",
                Status         = "Ok"
            };

            var koParis = BindingKey.Create(messageKo);
            var okParis = BindingKey.Create(messageOk);

            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 subscriptionTree = new PeerSubscriptionTree();

            subscriptionTree.Add(peer1, allParisKo.BindingKey);
            subscriptionTree.Add(peer2, allParis.BindingKey);


            var matchedPeers = subscriptionTree.GetPeers(allParis.BindingKey);

            Assert.AreEqual(1, matchedPeers.Count);

            matchedPeers = subscriptionTree.GetPeers(allKo.BindingKey);

            Assert.AreEqual(0, matchedPeers.Count);

            matchedPeers = subscriptionTree.GetPeers(allParisKo.BindingKey);

            Assert.AreEqual(2, matchedPeers.Count);
        }
        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 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 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 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 single_star_should_always_match(string routingKey)
        {
            // Arrange
            var peerSubscriptionTree = new PeerSubscriptionTree();
            var peer         = new Peer(new PeerId("jesuistonpeer"), "endpoint");
            var subscription = BindingKeyHelper.CreateFromString("*", '.');

            peerSubscriptionTree.Add(peer, subscription);

            // Act
            var matchingPeers = peerSubscriptionTree.GetPeers(BindingKeyHelper.CreateFromString(routingKey, '.'));

            // Assert
            matchingPeers.Single().ShouldEqual(peer);
        }
        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 = new BindingKey(routingKey.Split('.'));

            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 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();
        }