Exemple #1
0
        public async Task SimpleScheduleSuccessTest()
        {
            var context = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName);

            InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);

            message.ScheduleDate = DateTime.UtcNow.AddSeconds(2);

            await _message.EnqueueMessage(context, message);

            await _utility.VerifyQueue(context, _queueName, 0, 1);

            InternalMessageV1 readMessage = await _message.DequeueMessageAndDelete(context, _queueName);

            readMessage.Should().BeNull();

            await Task.Delay(TimeSpan.FromSeconds(5));

            readMessage = await _message.DequeueMessageAndDelete(context, _queueName);

            _utility.VerifyMessage(message, readMessage, agentId, false);

            InternalHistoryV1 history = await _management.GetHistory(context, readMessage.MessageId);

            _utility.VerifyHistoryMessage(readMessage, history, _queueName, _agentName);
        }
Exemple #2
0
        public async Task QueueAbandonTest()
        {
            var context = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName);

            InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);

            await _message.EnqueueMessage(context, message);

            await _utility.VerifyQueue(context, _queueName, 1, 0);

            InternalMessageV1 readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            _utility.VerifyMessage(message, readMessage, agentId, true);

            await _message.SettleMessage(context, readMessage.MessageId, agentId, SettleType.Abandon);

            await _utility.VerifyQueue(context, _queueName, 1, 0);

            readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            _utility.VerifyMessage(message, readMessage, agentId, true);

            await _message.SettleMessage(context, readMessage.MessageId, agentId, SettleType.Processed);

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            InternalHistoryV1 history = await _management.GetHistory(context, readMessage.MessageId);

            _utility.VerifyHistoryMessage(readMessage, history, _queueName, _agentName, 2);
        }
Exemple #3
0
        public async Task MultipleEnqueueWithLockSuccessTest()
        {
            const int messageSize = 100;
            var       context     = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName);

            var messageList     = new List <InternalEnqueueMessageV1>();
            var readMessageList = new List <InternalMessageV1>();

            foreach (int index in Enumerable.Range(0, messageSize))
            {
                InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);
                messageList.Add(message);

                await _message.EnqueueMessage(context, message);
            }

            await _utility.VerifyQueue(context, _queueName, messageSize, 0);

            InternalMessageV1 readMessage;

            foreach (int index in Enumerable.Range(0, messageSize))
            {
                readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

                readMessage.Should().NotBeNull();
                readMessageList.Add(readMessage);
            }

            readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            readMessage.Should().BeNull();

            var zip = messageList
                      .OrderBy(x => x.ClientMessageId)
                      .Zip(readMessageList.OrderBy(x => x.ClientMessageId), (f, s) => new Tuple <InternalEnqueueMessageV1, InternalMessageV1>(f, s));

            foreach (var item in zip)
            {
                _utility.VerifyMessage(item.Item1, item.Item2, agentId, true);
            }

            foreach (var item in readMessageList)
            {
                await _message.SettleMessage(context, item.MessageId, agentId, SettleType.Processed);
            }

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            foreach (var item in readMessageList)
            {
                InternalHistoryV1 history = await _management.GetHistory(context, item.MessageId);

                _utility.VerifyHistoryMessage(item, history, _queueName, _agentName);
            }
        }
        public async Task <IActionResult> GetHistory(long messageId)
        {
            RequestContext requestContext = HttpContext.GetRequestContext();
            var            context        = requestContext.Context.WithTag(_tag);

            InternalHistoryV1 result = await _management.GetHistory(context, messageId);

            return(new StandardActionResult(context)
                   .SetContent(result.ConvertTo()));
        }
Exemple #5
0
 public static HistoryRow ConvertTo(this InternalHistoryV1 self)
 {
     return(new HistoryRow
     {
         HistoryId = self.HistoryId,
         MessageId = self.MessageId,
         ActivityType = self.ActivityType,
         QueueName = self.QueueName,
         Cv = self.Cv,
         ClientMessageId = self.ClientMessageId,
         Payload = self.Payload,
         SettleByAgent = self.SettleByAgent,
         ErrorMessage = self.ErrorMesage,
         RetryCount = self.RetryCount,
         _createdDate = self._createdDate,
     });
 }
Exemple #6
0
        public async Task SimpleClearQueueHistoryTest()
        {
            var context = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName);

            InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);

            long messageId = await _message.EnqueueMessage(context, message);

            await _utility.VerifyQueue(context, _queueName, 1, 0);

            await _management.ClearQueue(context, _queueName, true);

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            InternalHistoryV1 history = await _management.GetHistory(context, messageId);

            history.Should().NotBeNull();
        }
Exemple #7
0
 public void VerifyHistoryMessage(
     InternalMessageV1 readMessage,
     InternalHistoryV1 history,
     string queueName,
     string agentName,
     int retryCount        = 1,
     SettleType settleType = SettleType.Processed
     )
 {
     history.Should().NotBeNull();
     history.HistoryId.Should().BeGreaterOrEqualTo(0);
     history.MessageId.Should().Be(readMessage.MessageId);
     history.ActivityType.Should().Be(settleType.ToString());
     history.QueueName.Should().Be(queueName);
     history.Cv.Should().Be(readMessage.Cv);
     history.ClientMessageId.Should().Be(readMessage.ClientMessageId);
     history.Payload.Should().Be(readMessage.Payload);
     history.SettleByAgent.Should().Be(agentName);
     history.ErrorMesage.Should().BeNullOrEmpty();
     history.RetryCount.Should().Be(retryCount);
 }
Exemple #8
0
        public async Task SimpleEnqueueSuccessTest()
        {
            var context = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName);

            InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);

            await _message.EnqueueMessage(context, message);

            await _utility.VerifyQueue(context, _queueName, 1, 0);

            InternalMessageV1 readMessage = await _message.DequeueMessageAndDelete(context, _queueName);

            _utility.VerifyMessage(message, readMessage, agentId, false);

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            InternalHistoryV1 history = await _management.GetHistory(context, readMessage.MessageId);

            _utility.VerifyHistoryMessage(readMessage, history, _queueName, _agentName);
        }
Exemple #9
0
        public async Task SimpleEnqueueWithLockTimeoutSuccessTest()
        {
            var context = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName, lockValidForSec : 5);

            InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);

            await _message.EnqueueMessage(context, message);

            await _utility.VerifyQueue(context, _queueName, 1, 0);

            InternalMessageV1 readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            long saveMessageId = readMessage.MessageId;

            _utility.VerifyMessage(message, readMessage, agentId, true);

            InternalMessageV1 tempMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            tempMessage.Should().BeNull();

            await Task.Delay(TimeSpan.FromSeconds(10));

            readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            _utility.VerifyMessage(message, readMessage, agentId, true);
            readMessage.MessageId.Should().Be(saveMessageId);

            await _message.SettleMessage(context, readMessage.MessageId, agentId, SettleType.Processed);

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            InternalHistoryV1 history = await _management.GetHistory(context, readMessage.MessageId);

            _utility.VerifyHistoryMessage(readMessage, history, _queueName, _agentName, retryCount: 2);
        }
Exemple #10
0
        public async Task MultipleScheduleSuccessTest()
        {
            const int scheduleSize = 10;
            var       context      = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName);

            var list = new List <InternalEnqueueMessageV1>();

            foreach (var item in Enumerable.Range(0, scheduleSize))
            {
                InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);
                message.ScheduleDate = DateTime.UtcNow.AddSeconds(2);

                await _message.EnqueueMessage(context, message);

                list.Add(message);
            }

            await _utility.VerifyQueue(context, _queueName, 0, scheduleSize);

            InternalMessageV1 readMessage = await _message.DequeueMessageAndDelete(context, _queueName);

            readMessage.Should().BeNull();

            await Task.Delay(TimeSpan.FromSeconds(5));

            var readList = new List <InternalMessageV1>();

            foreach (var item in Enumerable.Range(0, scheduleSize))
            {
                readMessage = await _message.DequeueMessageAndDelete(context, _queueName);

                readMessage.Should().NotBeNull();

                readList.Add(readMessage);
            }

            readList.Count.Should().Be(scheduleSize);

            readMessage = await _message.DequeueMessageAndDelete(context, _queueName);

            readMessage.Should().BeNull();

            var zip = list
                      .OrderBy(x => x.ClientMessageId)
                      .Zip(readList.OrderBy(x => x.ClientMessageId), (f, s) => new Tuple <InternalEnqueueMessageV1, InternalMessageV1>(f, s));

            foreach (var item in zip)
            {
                _utility.VerifyMessage(item.Item1, item.Item2, agentId, false);
            }

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            foreach (var item in readList)
            {
                InternalHistoryV1 history = await _management.GetHistory(context, item.MessageId);

                _utility.VerifyHistoryMessage(item, history, _queueName, _agentName);
            }
        }