public async Task When_Rabbit_Is_Not_Responding_Collector_Retries_And_Recovers() { var moqLogger = new Mock <ILogger <RabbitMqMetricsConsumer> >(); var serviceProvider = InitServiceProvider(5, 2); var publisher = new TestPublisher(); var processor = new DefaultMetricProcessor(new RabbitMqMetricsConsumer(RabbitMqMetricsConsumer.QueuePath, new RabbitMetricsConfiguration(), moqLogger.Object, new QueueValueConverter(), serviceProvider.GetService <IHttpClientFactory>()), publisher); var mre = new ManualResetEvent(false); publisher.MetricsPublished += (c) => { mre.Set(); }; await RabbitMqTestFixture.RabbitTestContainer.StopAsync(); var processTask = processor.ProcessAsync(); await WaitForCondition.AssertAsync(() => moqLogger.Invocations.FirstOrDefault(x => x.Method.Name == nameof(Microsoft.Extensions.Logging.ILogger.Log) && x.Arguments?.FirstOrDefault(x => x != null && x.ToString().StartsWith("Failed to download metrics.")) != null) != null, "retry performed", pollingInterval : 2000); // verify that there was nothing published Assert.False(mre.WaitOne(1)); // start the container await RabbitMqTestFixture.RabbitTestContainer.StartAsync(); // now the processor should recover Assert.True(mre.WaitOne(60_000)); }
public override IResult Parse(object source) { WorkFlowManagerWebPart workflowManagerWebPart = source as WorkFlowManagerWebPart; if (null == workflowManagerWebPart) { throw new ArgumentException("source is not a WorkFlowManagerWebPart"); } IConfiguration configuration = workflowManagerWebPart.Configuration; if (null == configuration) { throw new ArgumentException("source does not have a configuration"); } WebPartManager Manager = WebPartManager.GetCurrentWebPartManager(workflowManagerWebPart.Page); if (configuration.Sections.ContainsKey("flows")) { WorkFlow.WorkFlow flow = new WorkFlow.WorkFlow(); flow.Monitor = workflowManagerWebPart.Monitor; flow.Title = "screen flow"; IConfigurationSection flowsSection = configuration.GetConfigurationSectionReference("flows"); foreach (IConfigurationElement flowElement in flowsSection.Elements.Values) { Job job = new Job(); job.Monitor = workflowManagerWebPart.Monitor; job.Title = flowElement.ConfigKey; if (flowElement.Elements.ContainsKey("conditions")) { foreach (IConfigurationElement conditionElement in flowElement.Elements["conditions"].Elements.Values) { if (flowElement.Elements["conditions"].Attributes.ContainsKey("type")) { ReflectionServices.SetValue(job.Conditions, "Type", flowElement.Elements["conditions"].GetAttributeReference("type").Value.ToString()); } if (conditionElement.Attributes.ContainsKey("waitfor") && !("waitfor" == conditionElement.GetAttributeReference("type").Value.ToString())) { throw new InvalidOperationException("Unknown condition type " + conditionElement.GetAttributeReference("type").Value.ToString()); } WaitForCondition condition = new WaitForCondition(); condition.Monitor = workflowManagerWebPart.Monitor; if (conditionElement.Attributes.ContainsKey("milestone")) { condition.Milestone = conditionElement.GetAttributeReference("milestone").Value.ToString(); } if (conditionElement.Attributes.ContainsKey("sender")) { condition.Chronicler = (ReflectionServices.FindControlEx(conditionElement.GetAttributeReference("sender").Value.ToString(), Manager) as IChronicler); } condition.Target = job; job.Conditions.Add(condition); if (conditionElement.Elements.ContainsKey("expression")) { IConfigurationElement expressionElement = conditionElement.GetElementReference("expression"); IExpression expression = workflowManagerWebPart.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null != expression) { expression.Make(expressionElement, workflowManagerWebPart.ExpressionsManager); condition.Expression = expression; } } } } if (flowElement.Elements.ContainsKey("transits")) { foreach (IConfigurationElement transitElement in flowElement.GetElementReference("transits").Elements.Values) { if (transitElement.Attributes.ContainsKey("key")) { Transit transit = new Transit(); transit.Monitor = workflowManagerWebPart.Monitor; transit.Title = transitElement.ConfigKey; transit.Key = transitElement.GetAttributeReference("key").Value.ToString(); transit.Storage = workflowManagerWebPart.StatePersistence; if (transitElement.Elements.ContainsKey("expression")) { IConfigurationElement expressionElement = transitElement.GetElementReference("expression"); IExpression expression = workflowManagerWebPart.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null == expression) { throw new InvalidOperationException("Token is not an IExpression"); } expression.Make(expressionElement, workflowManagerWebPart.ExpressionsManager); transit.Expression = expression; } if (transitElement.Elements.ContainsKey("source")) { transit.Source = this.CreateTransitPoint(Manager, transitElement.GetElementReference("source"), workflowManagerWebPart.ExpressionsManager); } if (transitElement.Elements.ContainsKey("destination")) { transit.Destination = this.CreateTransitPoint(Manager, transitElement.GetElementReference("destination"), workflowManagerWebPart.ExpressionsManager); } if (transitElement.Attributes.ContainsKey("persistent")) { transit.IsPersistent = bool.Parse(transitElement.GetAttributeReference("persistent").Value.ToString()); } job.Transits.Add(transit); } } } flow.Jobs.Add(job); } workflowManagerWebPart.WorkFlows.Add(flow); } return(null); }