public async Task PeekRange_IncrementsSequenceNmber(int messageCt, int peekCt)
        {
            await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true))
            {
                var sender    = new ServiceBusSenderClient(TestEnvironment.ServiceBusConnectionString, scope.QueueName);
                var sessionId = Guid.NewGuid().ToString();
                // send the messages
                IEnumerable <ServiceBusMessage> sentMessages = GetMessages(messageCt, sessionId);
                await sender.SendRangeAsync(sentMessages);

                await using var receiver = new SessionReceiverClient(sessionId, TestEnvironment.ServiceBusConnectionString, scope.QueueName);

                long seq = 0;
                for (int i = 0; i < messageCt / peekCt; i++)
                {
                    IAsyncEnumerable <ServiceBusMessage> peekedMessages = receiver.PeekRangeAsync(
                        maxMessages: peekCt);

                    await foreach (ServiceBusMessage msg in peekedMessages)
                    {
                        Assert.IsTrue(msg.SystemProperties.SequenceNumber > seq);
                        if (seq > 0)
                        {
                            Assert.IsTrue(msg.SystemProperties.SequenceNumber == seq + 1);
                        }
                        seq = msg.SystemProperties.SequenceNumber;
                    }
                }
            }
        }
示例#2
0
        public async Task PeekRange_IncrementsSequenceNmber(int messageCt, int peekCt)
        {
            var sender    = new ServiceBusSenderClient(ConnString, SessionQueueName);
            var sessionId = Guid.NewGuid().ToString();
            // send the messages
            IEnumerable <ServiceBusMessage> sentMessages = GetMessages(messageCt, sessionId);
            await sender.SendRangeAsync(sentMessages);

            var receiver = new SessionReceiverClient(sessionId, ConnString, SessionQueueName);


            long seq = 0;

            for (int i = 0; i < messageCt / peekCt; i++)
            {
                IAsyncEnumerable <ServiceBusMessage> peekedMessages = receiver.PeekRangeAsync(
                    maxMessages: peekCt);

                await foreach (ServiceBusMessage msg in peekedMessages)
                {
                    Assert.IsTrue(msg.SystemProperties.SequenceNumber > seq);
                    if (seq > 0)
                    {
                        Assert.IsTrue(msg.SystemProperties.SequenceNumber == seq + 1);
                    }
                    seq = msg.SystemProperties.SequenceNumber;
                }
            }
        }