public void ShouldScopeDistributionToEndpointName() { var endpointA = "endpointA"; var policy = new DistributionPolicy(); var endpointAInstances = new[] { endpointA + "1", endpointA + "2" }; var endpointB = "endpointB"; var endpointBInstances = new[] { endpointB + "1", endpointB + "2" }; var result = new List<string>(); result.Add(InvokeDistributionStrategy(policy, endpointA, endpointAInstances)); result.Add(InvokeDistributionStrategy(policy, endpointB, endpointBInstances)); result.Add(InvokeDistributionStrategy(policy, endpointA, endpointAInstances)); result.Add(InvokeDistributionStrategy(policy, endpointB, endpointBInstances)); Assert.That(result.Count, Is.EqualTo(4)); Assert.That(result, Has.Exactly(1).EqualTo(endpointAInstances[0])); Assert.That(result, Has.Exactly(1).EqualTo(endpointAInstances[1])); Assert.That(result, Has.Exactly(1).EqualTo(endpointBInstances[0])); Assert.That(result, Has.Exactly(1).EqualTo(endpointBInstances[1])); }
public void ShouldScopeDistributionToEndpointName() { var endpointA = "endpointA"; var policy = new DistributionPolicy(); var endpointAInstances = new[] { endpointA + "1", endpointA + "2" }; var endpointB = "endpointB"; var endpointBInstances = new[] { endpointB + "1", endpointB + "2" }; var result = new List <string>(); result.Add(InvokeDistributionStrategy(policy, endpointA, endpointAInstances)); result.Add(InvokeDistributionStrategy(policy, endpointB, endpointBInstances)); result.Add(InvokeDistributionStrategy(policy, endpointA, endpointAInstances)); result.Add(InvokeDistributionStrategy(policy, endpointB, endpointBInstances)); Assert.That(result.Count, Is.EqualTo(4)); Assert.That(result, Has.Exactly(1).EqualTo(endpointAInstances[0])); Assert.That(result, Has.Exactly(1).EqualTo(endpointAInstances[1])); Assert.That(result, Has.Exactly(1).EqualTo(endpointBInstances[0])); Assert.That(result, Has.Exactly(1).EqualTo(endpointBInstances[1])); }
public DualRoutingPublishConnector(string routerAddress, DistributionPolicy distributionPolicy, MessageMetadataRegistry messageMetadataRegistry, Func <EndpointInstance, string> transportAddressTranslation, ISubscriptionStorage subscriptionStorage) { this.routerAddress = routerAddress; this.distributionPolicy = distributionPolicy; this.messageMetadataRegistry = messageMetadataRegistry; this.transportAddressTranslation = transportAddressTranslation; this.subscriptionStorage = subscriptionStorage; }
public void When_no_strategy_configured_for_endpoint_should_use_round_robbin_strategy() { IDistributionPolicy policy = new DistributionPolicy(); var result = policy.GetDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); Assert.That(result, Is.TypeOf<SingleInstanceRoundRobinDistributionStrategy>()); }
public void When_strategy_configured_for_endpoint_should_use_configured_strategy() { var p = new DistributionPolicy(); var configuredStrategy = new FakeDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); p.SetDistributionStrategy(configuredStrategy); IDistributionPolicy policy = p; var result = policy.GetDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); Assert.That(result, Is.EqualTo(configuredStrategy)); }
public void DistrubuteEvent(Event @event, DistributionPolicy distributionPolicy) { var session = _sessionProvider.GetCurrentSession(); var eventId = (int)session.Save(@event); foreach (var receiverId in distributionPolicy.ReceiverIds) { var id = session.Save(new Delivery(receiverId, eventId)); } }
public void When_multiple_strategies_configured_endpoint_should_use_last_configured_strategy() { var p = new DistributionPolicy(); var strategy1 = new FakeDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); var strategy2 = new FakeDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); p.SetDistributionStrategy(strategy1); p.SetDistributionStrategy(strategy2); IDistributionPolicy policy = p; var result = policy.GetDistributionStrategy("SomeEndpoint", DistributionStrategyScope.Send); Assert.That(result, Is.EqualTo(strategy2)); }
public DistributeRequest( int? numberOfPiles = null, int? numberOfCards = null, DistributionPolicy distributionPolicy = DistributionPolicy.Alternating, RemainderPolicy remainderPolicy = RemainderPolicy.Distribute) { numberOfPiles.ThrowIfBelowOrEqual(1, nameof(numberOfPiles)); numberOfCards.ThrowIfZeroOrLess(nameof(numberOfCards)); distributionPolicy.ThrowIfInvalid(nameof(distributionPolicy)); remainderPolicy.ThrowIfInvalid(nameof(remainderPolicy)); if ((numberOfPiles == null) == (numberOfCards == null)) throw new ArgumentException($"Must specify one of {nameof(numberOfPiles)} and {nameof(numberOfCards)}"); Piles = numberOfPiles; Cards = numberOfCards; Distribution = distributionPolicy; Remainder = remainderPolicy; }
public void EventIsStoredSuccessfully() { var provider = new DatabaseSessionProvider(); provider.OpenSession(); var repository = new EventRepository(provider); var eventInfo = new NewEmailConfirmedDeveloper(1); var @event = new Event(eventInfo); var receivers = new[] { 30, 31, 32 }; var distributionPolicy = new DistributionPolicy(receivers); repository.DistrubuteEvent(@event, distributionPolicy); var receivedEvent = repository.GetEventsByUser(receivers[0], false).Single(); Assert.AreEqual(@event.EventInfo, receivedEvent.EventInfo); Assert.AreEqual(@event.EventType, receivedEvent.EventType); }
static UnicastSendRouter CreateRouter(string instanceSpecificQueue = null, bool isSendOnly = false, UnicastRoutingTable routingTable = null, EndpointInstances instances = null, DistributionPolicy policy = null) { var table = routingTable ?? new UnicastRoutingTable(); var inst = instances ?? new EndpointInstances(); var pol = policy ?? new DistributionPolicy(); return(new UnicastSendRouter(isSendOnly, "Endpoint", instanceSpecificQueue, pol, table, inst, i => i.ToString())); }
static UnicastSendRouter CreateRouter(UnicastRoutingTable routingTable = null, EndpointInstances instances = null, DistributionPolicy policy = null) { var table = routingTable ?? new UnicastRoutingTable(); var inst = instances ?? new EndpointInstances(); var pol = policy ?? new DistributionPolicy(); return(new UnicastSendRouter(null, "Endpoint", null, null, pol, table, inst, i => i.ToString())); }