public void should_create_subscription_by_example() { var subscription = Subscription.ByExample(x => new FakeRoutableCommand(12, "name")); subscription.MessageTypeId.ShouldEqual(new MessageTypeId(typeof(FakeRoutableCommand))); subscription.BindingKey.ShouldEqual(BindingKey.Split("12.name.*")); }
public void should_create_subscription_by_example_with_placeholder() { var subscription = Subscription.ByExample(x => new FakeRoutableCommand(x.Any <decimal>(), "name")); subscription.MessageTypeId.ShouldEqual(new MessageTypeId(typeof(FakeRoutableCommand))); subscription.BindingKey.ShouldEqual(BindingKey.Split("*.name.*")); }
public void MeasurePerformance(string routingKey, string bindingKey) { var subscription = CreateSubscription(bindingKey); var key = BindingKey.Split(routingKey); Measure.Execution(x => { x.Iteration = 1000000; x.WarmUpIteration = 1000; x.Action = _ => subscription.Matches(key); }); }
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 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 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 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 should_not_match_binding_key(string routingKey, string bindingKey) { var subscription = CreateSubscription(bindingKey); subscription.Matches(BindingKey.Split(routingKey)).ShouldBeFalse(); }
public void exact_same_routing_key_should_match_binding_key() { var subscription = CreateSubscription("a.b.c"); subscription.Matches(BindingKey.Split("a.b.c")).ShouldBeTrue(); }
public void binding_key_with_dashr_should_match_routing_key(string bindingKey) { var subscription = CreateSubscription(bindingKey); subscription.Matches(BindingKey.Split("a.b.c")).ShouldBeTrue(); }
public void stars_should_always_match_if_same_number_of_parts(string routingKey) { var subscription = CreateSubscription("*.*.*"); subscription.Matches(BindingKey.Split(routingKey)).ShouldBeTrue(); }
public void empty_bindingkey_should_always_match(string routingKey) { var subscription = new Subscription(new MessageTypeId(typeof(FakeCommand)), BindingKey.Empty); subscription.Matches(BindingKey.Split(routingKey)).ShouldBeTrue(); }
public void single_dash_should_always_match(string routingKey) { var subscription = CreateSubscription("#"); subscription.Matches(BindingKey.Split(routingKey)).ShouldBeTrue(); }
private Subscription CreateSubscription(string bindingKey) { return(new Subscription(new MessageTypeId(typeof(FakeCommand)), BindingKey.Split(bindingKey))); }