Пример #1
0
        public void When_tasks_get_deleted_after_scheduling_System_will_not_execute_them()
        {
            var successTasks  = new[] { 0.5, 1.5, 2.5 };
            var tasksToRemove = new[] { 1.0, 2.0 };

            foreach (var task in successTasks.Concat(tasksToRemove))
            {
                var text        = task.ToString(CultureInfo.InvariantCulture);
                var testMessage = new SuccessCommand(text);
                _scheduler.Tell(new ScheduleCommand(testMessage, new ScheduleKey(Guid.Empty, text, text), CreateOptions(task, Timeout)));
            }

            var successTaskIds       = successTasks.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();
            var tasksToRemoveTaskIds = tasksToRemove.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();

            foreach (var taskId in tasksToRemoveTaskIds)
            {
                _scheduler.Tell(new Unschedule(new ScheduleKey(Guid.Empty, taskId, taskId)));
            }

            Throttle.Assert(() =>
            {
                ResultHolder.Contains(successTaskIds);
                Assert.True(tasksToRemoveTaskIds.All(x => ResultHolder.Get(x) == null));
            }, minTimeout: TimeSpan.FromSeconds(4));
        }
Пример #2
0
        public void When_some_of_scheduled_jobs_fail_System_still_executes_others()
        {
            var successTasks = new[] { 0.5, 1.5, 2.5 };
            var failTasks    = new[] { 1.0, 2.0 };

            foreach (var task in successTasks)
            {
                var text        = task.ToString(CultureInfo.InvariantCulture);
                var testCommand = new SuccessCommand(text);
                _scheduler.Tell(new ScheduleCommand(testCommand, new ScheduleKey(Guid.Empty, text, text), CreateOptions(task, Timeout)));
            }
            foreach (var failTask in failTasks)
            {
                var text            = failTask.ToString(CultureInfo.InvariantCulture);
                var failTaskCommand = new FailCommand();
                _scheduler.Tell(new ScheduleCommand(failTaskCommand, new ScheduleKey(Guid.Empty, text, text), CreateOptions(failTask, Timeout)));
            }

            var successTaskIds = successTasks.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();
            var failTaskIds    = failTasks.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();

            Throttle.Assert(() =>
            {
                ResultHolder.Contains(successTaskIds);
                Assert.True(failTaskIds.All(x => ResultHolder.Get(x) == null));
            }, minTimeout: TimeSpan.FromSeconds(3));
        }
Пример #3
0
        public void When_there_are_several_scheduled_jobs_System_executes_all_of_them()
        {
            var tasks = new[] { 0.5, 0.6, 0.7, 0.8, 1 };

            foreach (var task in tasks)
            {
                var text        = task.ToString(CultureInfo.InvariantCulture);
                var testMessage = new SuccessCommand(text);
                _scheduler.Tell(new ScheduleCommand(testMessage, new ScheduleKey(Guid.Empty, text, text), CreateOptions(task, Timeout)));
            }

            var taskIds = tasks.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();

            Throttle.Assert(() => ResultHolder.Contains(taskIds));
        }
Пример #4
0
        public async Task WhenMessageWithSlightlyDifferentStructureButWithSameTopicIsPosted_ItCanbeProcessed()
        {
            var subscriber = Resolver.Get <IQueueSubscriber>();

            subscriber.Subscribe <SlightlyDifferentTestHandler, SlightlyDifferentTestMessage>();
            var publisher = Resolver.Get <IQueuePublisher>();
            var listener  = Resolver.Get <QueueListener>();
            await listener.Start("test", CancellationToken.None);

            var testMessage = CreateMessage();

            publisher.Publish(testMessage);
            Throttle.Assert(
                () => ResultHolder.Contains(testMessage.Id) && ResultHolder.Count == 1,
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6)
                );
        }
Пример #5
0
        public async Task WhenMessageIsPosted_TargetApplicationProcessesItOnce()
        {
            var subscriber = Resolver.Get <IQueueSubscriber>();

            subscriber.Subscribe <TestHandler, TestMessage>();
            var publisher = Resolver.Get <IQueuePublisher>();
            var listener  = Resolver.Get <QueueListener>();
            await listener.Start("test", CancellationToken.None);

            var testMessage = CreateMessage();

            publisher.Publish(testMessage);
            Throttle.Assert(
                () => ResultHolder.Contains(testMessage.Id) && ResultHolder.Count == 1,
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6)
                );
        }
Пример #6
0
        public async Task WhenMessageSendWithoutSubscribers_ThenMessageShouldBeSentAfterSubscribing()
        {
            var publisher   = Resolver.Get <IQueuePublisher>();
            var testMessage = CreateMessage();

            publisher.Publish(testMessage);
            var subscriber = Resolver.Get <IQueueSubscriber>();

            subscriber.Subscribe <TimeConsumingHandler, TestMessage>();
            var listener = Resolver.Get <QueueListener>();
            await listener.Start("test", CancellationToken.None);

            Throttle.Assert(
                () => ResultHolder.Contains(testMessage.Id) && ResultHolder.Count == 1,
                TimeSpan.FromSeconds(4),
                TimeSpan.FromSeconds(5)
                );
        }
Пример #7
0
        public async Task WhenNMessagesAreSentAsync_TheyAreHandledSimultaneously(int messagesCount)
        {
            var subscriber = Resolver.Get <IQueueSubscriber>();

            subscriber.Subscribe <TimeConsumingHandler, TestMessage>();
            var publisher = Resolver.Get <IQueuePublisher>();
            var listener  = Resolver.Get <QueueListener>();
            await listener.Start("test", CancellationToken.None);

            var testMessages = Enumerable.Range(0, messagesCount).Select(x => CreateMessage()).ToArray();
            await Task.WhenAll(testMessages.Select(testMessage => publisher.PublishAsync(testMessage)));

            Throttle.Assert(
                () => ResultHolder.Contains(testMessages.Select(x => x.Id).ToArray()) && ResultHolder.Count == testMessages.Length,
                TimeSpan.FromSeconds(4),
                TimeSpan.FromSeconds(5)
                );
        }
Пример #8
0
        public void When_scheduler_is_restarted_Then_scheduled_jobs_still_get_executed()
        {
            var tasks = new[] { 0.5, 1, 1.5, 2, 2.5 };

            foreach (var task in tasks)
            {
                var text        = task.ToString(CultureInfo.InvariantCulture);
                var testMessage = new SuccessCommand(text);
                _scheduler.Tell(new ScheduleCommand(testMessage, new ScheduleKey(Guid.Empty, text, text), CreateOptions(task, Timeout)));
            }

            _quartzScheduler.Shutdown(false);
            CreateScheduler();

            var taskIds = tasks.Select(x => x.ToString(CultureInfo.InvariantCulture)).ToArray();

            Throttle.Assert(() => ResultHolder.Contains(taskIds));
        }
Пример #9
0
        public async Task WhenMessageIsResent_SystemProcessesItOnce()
        {
            var subscriber    = Builder.GetSubscriber();
            var configuration = (TestMessagingConfiguration)Resolver.Get <IMessagingConfiguration>();

            configuration.SetResends(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
            subscriber.Subscribe <ResendHandler, TestMessage>();
            var publisher = Resolver.Get <IQueuePublisher>();
            var listener  = Resolver.Get <QueueListener>();
            await listener.Start("test", CancellationToken.None);

            var testMessage = CreateMessage();

            publisher.Publish(testMessage);
            Throttle.Assert(
                () => ResultHolder.Contains(testMessage.Id + "resend") && ResultHolder.Count == 1,
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6)
                );
        }
Пример #10
0
        public async Task WhenNMessagesAreSent_NMessagesHandled(int messagesCount)
        {
            var subscriber = Resolver.Get <IQueueSubscriber>();

            subscriber.Subscribe <SlightlyDifferentTestHandler, SlightlyDifferentTestMessage>();
            var publisher = Resolver.Get <IQueuePublisher>();
            var listener  = Resolver.Get <QueueListener>();
            await listener.Start("test", CancellationToken.None);

            var testMessages = Enumerable.Range(0, messagesCount).Select(x => CreateMessage()).ToArray();

            foreach (var testMessage in testMessages)
            {
                publisher.Publish(testMessage);
            }
            Throttle.Assert(
                () => ResultHolder.Contains(testMessages.Select(x => x.Id).ToArray()) && ResultHolder.Count == testMessages.Length,
                TimeSpan.FromSeconds(5),
                TimeSpan.FromSeconds(6)
                );
        }