Exemple #1
0
        public void ShouldMatchSubscription()
        {
            var allowed = new DatabaseStatus()
            {
                DatacenterName = "Paris",
                FailureType    = "Oh no!"
            };

            var notAllowed = new DatabaseStatus()
            {
                DatacenterName = "London",
                FailureType    = "Oh no!"
            };

            var key = BindingKey.Create(allowed);

            var subscription = Subscription.Matching <DatabaseStatus>(x => x.DatacenterName == "Paris");

            var allowedMessageBinding    = MessageBinding.FromMessage(allowed);
            var notAllowedMessageBinding = MessageBinding.FromMessage(notAllowed);

            Assert.IsTrue(subscription.Matches(allowedMessageBinding));

            Assert.IsFalse(subscription.Matches(notAllowedMessageBinding));
        }
Exemple #2
0
        public void should_send_routing_key_exception()
        {
            var msg = new FakeRoutableCommand(0, null);

            var exception = Assert.Throws <InvalidOperationException>(() => BindingKey.Create(msg));

            exception.Message.ShouldContain(typeof(FakeRoutableCommand).Name);
            exception.Message.ShouldContain("Name");
            exception.Message.ShouldContain("can not be null");
        }
Exemple #3
0
        public void ShouldParseCommand()
        {
            var message = new DatabaseStatus()
            {
                DatacenterName = "Paris",
                FailureType    = "Oh no!"
            };

            var key = BindingKey.Create(message);

            Assert.AreEqual($"{message.DatacenterName}.{message.Status}", key.ToString());
        }
Exemple #4
0
        public void should_get_routing_key_from_message_with_properties()
        {
            var message = new FakeRoutableCommandWithProperties {
                Id = 100, FeedId = 200
            };
            var routingKey = BindingKey.Create(message);

            routingKey.PartCount.ShouldEqual(2);
            routingKey.GetPart(0).ShouldEqual("100");
            routingKey.GetPart(1).ShouldEqual("200");

            routingKey.ToString().ShouldEqual("100.200");
        }
Exemple #5
0
        public void should_get_routing_key_from_message()
        {
            using (new CultureScope(CultureInfo.GetCultureInfo("FR-fr")))
            {
                var message     = new FakeRoutableCommand(42.42m, "name", Guid.NewGuid());
                var rountingKey = BindingKey.Create(message);

                rountingKey.PartCount.ShouldEqual(3);
                rountingKey.GetPart(0).ShouldEqual("42.42");
                rountingKey.GetPart(1).ShouldEqual("name");
                rountingKey.GetPart(2).ShouldEqual(message.OtherId.ToString());
            }
        }
Exemple #6
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);
        }
Exemple #7
0
        public void MeasurePerformances()
        {
            var message = new FakeMarketDataEvent("USA", "NASDAQ", "MSFT");

            Measure.Execution(1000000, () => BindingKey.Create(message));
        }
Exemple #8
0
 public static MessageBinding FromMessage(IMessage message)
 => new MessageBinding(message.TypeId(), BindingKey.Create(message));