Ejemplo n.º 1
0
        public void ReadLastEnqueuedEventInformationPopulatesFromTheLastReceivedEvent()
        {
            var lastEvent = new EventData
                            (
                eventBody: Array.Empty <byte>(),
                lastPartitionSequenceNumber: 12345,
                lastPartitionOffset: 89101,
                lastPartitionEnqueuedTime: DateTimeOffset.Parse("2015-10-27T00:00:00Z"),
                lastPartitionInformationRetrievalTime: DateTimeOffset.Parse("2012-03-04T08:49:00Z")
                            );

            var eventHub      = "someHub";
            var partition     = "PART";
            var transportMock = new ObservableTransportConsumerMock {
                LastReceivedEvent = lastEvent
            };
            var receiver = new PartitionReceiver("group", partition, eventHub, true, TimeSpan.Zero, transportMock);
            var metrics  = receiver.ReadLastEnqueuedEventInformation();

            Assert.That(metrics.EventHubName, Is.EqualTo(eventHub), "The Event Hub name should match.");
            Assert.That(metrics.PartitionId, Is.EqualTo(partition), "The partition id should match.");
            Assert.That(metrics.LastEnqueuedSequenceNumber, Is.EqualTo(lastEvent.LastPartitionSequenceNumber), "The sequence number should match.");
            Assert.That(metrics.LastEnqueuedOffset, Is.EqualTo(lastEvent.LastPartitionOffset), "The offset should match.");
            Assert.That(metrics.LastEnqueuedTime, Is.EqualTo(lastEvent.LastPartitionEnqueuedTime), "The enqueue time should match.");
            Assert.That(metrics.InformationReceived, Is.EqualTo(lastEvent.LastPartitionInformationRetrievalTime), "The retrieval time should match.");
        }
        public void ConstructorSetsTheConsumerGroup()
        {
            var consumerGroup     = "SomeGroup";
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", consumerGroup, "0", EventPosition.Latest, new EventHubConsumerOptions(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(consumer.ConsumerGroup, Is.EqualTo(consumerGroup));
        }
Ejemplo n.º 3
0
        public void CloseClosesTheTransportConsumer()
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var receiver          = new PartitionReceiver("group", "0", "hub", true, TimeSpan.Zero, transportConsumer);

            receiver.Close();
            Assert.That(transportConsumer.WasCloseCalled, Is.True);
        }
        public void ConstructorSetsTheRetryPolicy()
        {
            var retryPolicy       = Mock.Of <EventHubRetryPolicy>();
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", "consumerGroup", "0", EventPosition.Latest, new EventHubConsumerOptions(), retryPolicy);

            Assert.That(consumer.RetryPolicy, Is.SameAs(retryPolicy));
        }
        public void ConstructorSetsTheStartingPosition()
        {
            var expectedPosition  = EventPosition.FromSequenceNumber(5641);
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroupName, "0", expectedPosition, new EventHubConsumerOptions(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(consumer.StartingPosition, Is.EqualTo(expectedPosition));
        }
        public void ConstructorSetsThePartition()
        {
            var partition         = "aPartition";
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroupName, partition, EventPosition.FromSequenceNumber(1), new EventHubConsumerOptions(), Mock.Of <EventHubRetryPolicy>());

            Assert.That(consumer.PartitionId, Is.EqualTo(partition));
        }
        public void CloseClosesTheTransportConsumer()
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", "0", EventPosition.Latest, new EventHubConsumerOptions());

            consumer.Close();

            Assert.That(transportConsumer.WasCloseCalled, Is.True);
        }
Ejemplo n.º 8
0
        public void ReceiveAsyncValidatesTheMaximumWaitTime(int timeSpanDelta)
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var receiver          = new PartitionReceiver("group", "0", "hub", true, TimeSpan.Zero, transportConsumer);
            var expectedWaitTime  = TimeSpan.FromMilliseconds(timeSpanDelta);

            using var cancellation = new CancellationTokenSource();
            Assert.That(async() => await receiver.ReceiveAsync(32, expectedWaitTime, cancellation.Token), Throws.InstanceOf <ArgumentException>());
        }
        public async Task CloseAsyncClosesTheTransportConsumer()
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroup, "0", EventPosition.Latest, new EventHubConsumerOptions());

            await consumer.CloseAsync();

            Assert.That(transportConsumer.WasCloseCalled, Is.True);
        }
        public void ReceiveAsyncValidatesTheMaximumCount(int maximumMessageCount)
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroup, "0", EventPosition.Latest, new EventHubConsumerOptions());
            var cancellation      = new CancellationTokenSource();
            var expectedWaitTime  = TimeSpan.FromDays(1);

            Assert.That(async() => await consumer.ReceiveAsync(maximumMessageCount, expectedWaitTime, cancellation.Token), Throws.InstanceOf <ArgumentException>());
        }
        public void CloseClosesTheTransportConsumer()
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroupName, "0", EventPosition.Latest, new EventHubConsumerOptions(), Mock.Of <EventHubRetryPolicy>());

            consumer.Close();

            Assert.That(transportConsumer.WasCloseCalled, Is.True);
        }
        public void ReceiveAsyncValidatesTheMaximumWaitTime(int timeSpanDelta)
        {
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroupName, "0", EventPosition.Latest, new EventHubConsumerOptions(), Mock.Of <EventHubRetryPolicy>());
            var cancellation      = new CancellationTokenSource();
            var expectedWaitTime  = TimeSpan.FromMilliseconds(timeSpanDelta);

            Assert.That(async() => await consumer.ReceiveAsync(32, expectedWaitTime, cancellation.Token), Throws.InstanceOf <ArgumentException>());
        }
        public void SettingTheRetryPolicyUpdatesTheTransportConsumer()
        {
            var customRetry       = Mock.Of <EventHubRetryPolicy>();
            var transportConsumer = new ObservableTransportConsumerMock();
            var consumerOptions   = new EventHubConsumerOptions();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", "consumerGroup", "0", EventPosition.Latest, consumerOptions, Mock.Of <EventHubRetryPolicy>());

            consumer.RetryPolicy = customRetry;
            Assert.That(transportConsumer.UpdateRetryPolicyCalledWith, Is.SameAs(customRetry), "The custom retry policy should have been set.");
        }
        public void ConstructorSetsTheConsumerGroup()
        {
            var options = new EventHubConsumerOptions
            {
                ConsumerGroup = "SomeGroup"
            };

            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", "0", EventPosition.Latest, options);

            Assert.That(consumer.ConsumerGroup, Is.EqualTo(options.ConsumerGroup));
        }
        public void ConstructorSetsThePriority(long?priority)
        {
            var options = new EventHubConsumerOptions
            {
                OwnerLevel = priority
            };

            var transportConsumer = new ObservableTransportConsumerMock();
            var consumer          = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroupName, "0", EventPosition.FromOffset(65), options, Mock.Of <EventHubRetryPolicy>());

            Assert.That(consumer.OwnerLevel, Is.EqualTo(priority));
        }
Ejemplo n.º 16
0
        public async Task ReceiveAsyncInvokesTheTransportConsumer()
        {
            var defaultMaximumReceiveWaitTime = TimeSpan.FromMilliseconds(8);
            var transportConsumer             = new ObservableTransportConsumerMock();
            var receiver             = new PartitionReceiver("group", "0", "hub", true, defaultMaximumReceiveWaitTime, transportConsumer);
            var expectedMessageCount = 45;

            using var cancellation = new CancellationTokenSource();
            await receiver.ReceiveAsync(expectedMessageCount, null, cancellation.Token);

            (var actualMessageCount, TimeSpan? actualWaitTime) = transportConsumer.ReceiveCalledWith;

            Assert.That(actualMessageCount, Is.EqualTo(expectedMessageCount), "The message counts should match.");
            Assert.That(actualWaitTime, Is.EqualTo(defaultMaximumReceiveWaitTime), "The wait time should match.");
        }
        public async Task ReceiveAsyncInvokesTheTransportConsumer()
        {
            var options = new EventHubConsumerOptions {
                DefaultMaximumReceiveWaitTime = TimeSpan.FromMilliseconds(8)
            };
            var transportConsumer    = new ObservableTransportConsumerMock();
            var consumer             = new EventHubConsumer(transportConsumer, "dummy", EventHubConsumer.DefaultConsumerGroupName, "0", EventPosition.Latest, options, Mock.Of <EventHubRetryPolicy>());
            var cancellation         = new CancellationTokenSource();
            var expectedMessageCount = 45;

            await consumer.ReceiveAsync(expectedMessageCount, null, cancellation.Token);

            (var actualMessageCount, var actualWaitTime) = transportConsumer.ReceiveCalledWith;

            Assert.That(actualMessageCount, Is.EqualTo(expectedMessageCount), "The message counts should match.");
            Assert.That(actualWaitTime, Is.EqualTo(options.DefaultMaximumReceiveWaitTime), "The wait time should match.");
        }