public async Task MainAndErrorQueuesAreMonitoredAtDifferentThresholds()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "prod-pattern-queue", "prod-pattern-queue_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);


            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue", 10, false);
            VerifyQueues.EnsureOldestMessageAlarm(alarmCreator, "prod-pattern-queue", 600, false);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue_error", 1, false);
            VerifyQueues.NoOldestMessageAlarm(alarmCreator, "prod-pattern-queue_error");
        }
        public async Task QueueValuesAreUsedAsOverride()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "pattern1", "pattern1_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();
            var sqs    = config.AlertingGroups[0].Sqs;

            sqs.Errors = new ErrorQueue
            {
                LengthThreshold        = 142,
                OldestMessageThreshold = 112
            };
            sqs.Queues[0].LengthThreshold        = 42;
            sqs.Queues[0].OldestMessageThreshold = 12;

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);

            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "pattern1", 42, false);
            VerifyQueues.EnsureOldestMessageAlarm(alarmCreator, "pattern1", 12, false);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "pattern1_error", 1, false);
            VerifyQueues.NoOldestMessageAlarm(alarmCreator, "pattern1_error");
        }
        public async Task AlertingGroupThresholdsAreUsedByDefault()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "prod-pattern-queue", "prod-pattern-queue_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();
            var sqs    = config.AlertingGroups[0].Sqs;

            sqs.LengthThreshold        = 32;
            sqs.OldestMessageThreshold = 17;

            sqs.Queues[0].LengthThreshold        = null;
            sqs.Queues[0].OldestMessageThreshold = null;

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);


            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue", 32, false);
            VerifyQueues.EnsureOldestMessageAlarm(alarmCreator, "prod-pattern-queue", 17, false);
        }