Example #1
0
        public async Task Multiple_scheduled_commands_having_the_some_causative_command_etag_have_repeatable_and_unique_etags()
        {
            var senderId = Any.Word();
            await store.Put(new CommandTarget(senderId));

            var targetIds = new[] { Any.Word(), Any.Word(), Any.Word() };

            var results = new ConcurrentBag <RequestReply>();

            configuration.TraceScheduledCommands(
                onScheduling: cmd =>
            {
                var requestReply = ((dynamic)cmd).Command as RequestReply;
                if (requestReply != null)
                {
                    results.Add(requestReply);
                }
            });


            var initialEtag = "initial".ToETag();

            var firstCommand = new SendRequests(targetIds)
            {
                ETag = initialEtag
            };

            var scheduledCommand = new ScheduledCommand <CommandTarget>(
                firstCommand,
                senderId);

            await scheduler.Deliver(scheduledCommand);

            var secondCommand = new SendRequests(targetIds)
            {
                ETag = initialEtag
            };

            scheduledCommand = new ScheduledCommand <CommandTarget>(
                secondCommand,
                senderId);

            // redeliver
            await scheduler.Deliver(scheduledCommand);

            Console.WriteLine(results.ToJson());

            results.Should().HaveCount(6);
            results.Select(r => r.ETag)
            .Distinct()
            .Should()
            .HaveCount(3);
        }
Example #2
0
        public async Task EnactCommand(CommandTarget requestor, SendRequests command)
        {
            requestor.CommandsEnacted.Add(command);

            foreach (var targetId in command.TargetIds)
            {
                await scheduler.Schedule(targetId, new RequestReply(requestor.Id)
                {
                    RequestorId = requestor.Id
                });
            }
        }
Example #3
0
        public async Task Scheduled_commands_triggered_by_a_scheduled_command_are_idempotent()
        {
            var id = Any.Word();
            await store.Put(new CommandTarget(id));

            var command = new SendRequests(new[] { id })
            {
                ETag = "hello".ToETag()
            };

            await scheduler.Schedule(id, command);

            await scheduler.Schedule(id, command);

            var recipient = await store.Get(id);

            recipient
            .CommandsEnacted
            .OfType <SendRequests>()
            .Should()
            .HaveCount(1);
        }