public async Task Should_trigger_circuit_breaker() { var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); var container = new TransportPartsContainer(); var fakeTopologyOperator = new FakeTopologyOperator(); container.Register <IOperateTopology>(() => fakeTopologyOperator); var settings = new SettingsHolder(); settings.Set("NServiceBus.SharedQueue", "sales"); new DefaultConfigurationValues().Apply(settings); container.Register <ReadOnlySettings>(() => settings); Exception exceptionReceivedByCircuitBreaker = null; var criticalErrorWasRaised = false; var tcs = new TaskCompletionSource <object>(); cts.Token.Register(() => tcs.TrySetCanceled()); // setup critical error action to capture exception thrown by message pump var criticalError = new FakeCriticalError(ctx => { criticalErrorWasRaised = true; exceptionReceivedByCircuitBreaker = ctx.Exception; tcs.TrySetResult(null); return(TaskEx.Completed); }); var pump = new MessagePump(new FakeTopology(), container, settings, TimeSpan.FromSeconds(1)); await pump.Init(context => TaskEx.Completed, null, criticalError, new PushSettings("sales", "error", false, TransportTransactionMode.ReceiveOnly)); pump.Start(new PushRuntimeSettings(1)); await fakeTopologyOperator.onIncomingMessage(new IncomingMessageDetails("id", new Dictionary <string, string>(), new byte[0]), new FakeReceiveContext()); var exceptionThrownByMessagePump = new Exception("kaboom"); await fakeTopologyOperator.onError(exceptionThrownByMessagePump); await tcs.Task; // let circuit breaker kick in // validate Assert.IsTrue(criticalErrorWasRaised, "Expected critical error to be raised, but it wasn't"); Assert.AreEqual(exceptionThrownByMessagePump, exceptionReceivedByCircuitBreaker, "Exception circuit breaker got should be the same as the one raised by message pump"); }
public void Determines_there_should_be_a_topic_bundle_created() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring); var topology = new ForwardingTopology(container); topology.Initialize(settings); var sectionManager = container.Resolve <ITopologySectionManager>(); var definition = sectionManager.DetermineResourcesToCreate(new QueueBindings()); var result = definition.Entities.Where(ei => ei.Type == EntityType.Topic && ei.Namespace.ConnectionString == Connectionstring && ei.Path.StartsWith("bundle-")); Assert.That(result.Count(), Is.EqualTo(2)); Assert.That(result, Has.Exactly(1).Matches <EntityInfo>(x => x.Path == "bundle-1")); Assert.That(result, Has.Exactly(1).Matches <EntityInfo>(x => x.Path == "bundle-2")); }
public void Creates_subscription_on_each_topic_in_bundle() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.UseForwardingTopology().NamespacePartitioning().AddNamespace(Name, Connectionstring); var topology = new ForwardingTopology(container); topology.Initialize(settings); var sectionManager = container.Resolve <ITopologySectionManager>(); sectionManager.DetermineResourcesToCreate(new QueueBindings()); var section = sectionManager.DetermineResourcesToSubscribeTo(typeof(SomeTestEvent)); Assert.That(section.Entities.Count(), Is.EqualTo(2)); // TODO: need to verify that subscription is done on each topic }
public void Should_throw() { var container = new TransportPartsContainer(); container.Register <TopologyOperator>(); var settings = new SettingsHolder(); settings.Set("NServiceBus.SharedQueue", "sales"); new DefaultConfigurationValues().Apply(settings); container.Register <ReadOnlySettings>(() => settings); var pump = new MessagePump(null, container, settings); var criticalError = new CriticalError(ctx => TaskEx.Completed); const bool purgeOnStartup = true; Assert.ThrowsAsync <InvalidOperationException> (async() => await pump.Init(context => TaskEx.Completed, null, criticalError, new PushSettings("sales", "error", purgeOnStartup, TransportTransactionMode.SendsAtomicWithReceive))); }
#pragma warning disable 618 ITopologySectionManager SetupForwardingTopology(TransportPartsContainer container, string enpointname) { var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", enpointname); extensions.NamespacePartitioning().AddNamespace("namespace1", AzureServiceBusConnectionString.Value); var topology = new ForwardingTopology(container); topology.Initialize(settings); return(container.Resolve <ITopologySectionManager>()); }
public void Determines_there_should_be_a_topic_with_same_name_as_endpointname_followed_by_dot_events() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); settings.Set <Conventions>(new Conventions()); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring); var definition = DetermineResourcesToCreate(settings, container); Assert.AreEqual(1, definition.Entities.Count(ei => ei.Path == "sales.events" && ei.Type == EntityType.Topic && ei.Namespace.ConnectionString == Connectionstring)); }
ITopologySectionManager SetupEndpointOrientedTopologyWithFailoverNamespace(TransportPartsContainer container, string enpointname) { var settings = new SettingsHolder(); settings.Set <Conventions>(new Conventions()); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", enpointname); extensions.NamespacePartitioning().AddNamespace("namespace1", AzureServiceBusConnectionString.Value); extensions.NamespacePartitioning().AddNamespace("namespace2", AzureServiceBusConnectionString.Fallback); extensions.NamespacePartitioning().UseStrategy <FailOverNamespacePartitioning>(); var topology = new EndpointOrientedTopology(container); topology.Initialize(settings); return(container.Resolve <ITopologySectionManager>()); }
public void Should_fail_sanitization_for_invalid_endpoint_name(string reasonToFail, string endpointName) { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", endpointName); extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring); var topology = new ForwardingTopology(container); topology.Initialize(settings); var sectionManager = container.Resolve <ITopologySectionManager>(); Assert.Throws <Exception>(() => sectionManager.DetermineResourcesToCreate(new QueueBindings()), "Was expected to fail: " + reasonToFail); }
public void Determines_the_namespace_from_partitioning_strategy() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); settings.Set <Conventions>(new Conventions()); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring); var definition = DetermineResourcesToCreate(settings, container); // ReSharper disable once RedundantArgumentDefaultValue var namespaceInfo = new RuntimeNamespaceInfo(Name, Connectionstring); Assert.IsTrue(definition.Namespaces.Any(nsi => nsi == namespaceInfo)); }
public void Determines_there_should_be_a_queue_with_same_name_as_endpointname() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring); var topology = new ForwardingTopology(container); topology.Initialize(settings); var sectionManager = container.Resolve <ITopologySectionManager>(); var definition = sectionManager.DetermineResourcesToCreate(new QueueBindings()); Assert.AreEqual(1, definition.Entities.Count(ei => ei.Path == "sales" && ei.Type == EntityType.Queue && ei.Namespace.ConnectionString == Connectionstring)); }
async Task <ITopologySectionManager> SetupEndpointOrientedTopology(TransportPartsContainer container, string endpointName, SettingsHolder settings) { container.Register(typeof(SettingsHolder), () => settings); settings.SetDefault("NServiceBus.Routing.EndpointName", endpointName); settings.Set <Conventions>(new Conventions()); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); extensions.NamespacePartitioning().AddNamespace("namespaceName", AzureServiceBusConnectionString.Value); var endpointOrientedTopology = new EndpointOrientedTopology(container); endpointOrientedTopology.Initialize(settings); // create the topologySectionManager var topologyCreator = (ICreateTopology)container.Resolve(typeof(TopologyCreator)); var sectionManager = container.Resolve <ITopologySectionManager>(); await topologyCreator.Create(sectionManager.DetermineResourcesToCreate(new QueueBindings())); container.RegisterSingleton <TopologyOperator>(); return(sectionManager); }
public void Should_creates_subscription_entities_marked_as_not_be_listened_to() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.UseForwardingTopology().NamespacePartitioning().AddNamespace(Name, Connectionstring); var topology = new ForwardingTopology(container); topology.Initialize(settings); var sectionManager = container.Resolve <ITopologySectionManager>(); sectionManager.DetermineResourcesToCreate(new QueueBindings()); var section = sectionManager.DetermineResourcesToSubscribeTo(typeof(SomeTestEvent)); Assert.IsFalse(section.Entities.Any(x => x.ShouldBeListenedTo)); }
public void Creates_subscription_path_matching_the_subscribing_endpoint_name() { var container = new TransportPartsContainer(); var settings = new SettingsHolder(); container.Register(typeof(SettingsHolder), () => settings); var extensions = new TransportExtensions <AzureServiceBusTransport>(settings); settings.SetDefault("NServiceBus.Routing.EndpointName", "sales"); extensions.UseForwardingTopology().NamespacePartitioning().AddNamespace(Name, Connectionstring); var topology = new ForwardingTopology(container); topology.Initialize(settings); var sectionManager = container.Resolve <ITopologySectionManager>(); sectionManager.DetermineResourcesToCreate(new QueueBindings()); var section = sectionManager.DetermineResourcesToSubscribeTo(typeof(SomeTestEvent)); Assert.IsTrue(section.Entities.All(e => e.Path == "sales"), "Subscription name should be matching subscribing endpoint name, but it wasn't."); }