public async Task TheConsumerIsNotKeptAlive()
        {
            var eventHubName = "hub-name";
            var partitionId  = "id-value";
            var mockConsumer = new LastEventConsumerMock(new EventData(Array.Empty <byte>()));
            var context      = new PartitionContext(eventHubName, partitionId, mockConsumer);

            // Attempt to clear out the consumer and force GC.

            mockConsumer = null;

            // Because cleanup may be non-deterministic, allow a small set of
            // retries.

            var attempts    = 0;
            var maxAttempts = 5;

            while (attempts <= maxAttempts)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));

                GC.Collect();
                GC.WaitForPendingFinalizers();

                try
                {
                    Assert.That(() => context.ReadLastEnqueuedEventInformation(), Throws.TypeOf <EventHubsClientClosedException>());
                }
                catch (AssertionException)
                {
                    if (++attempts <= maxAttempts)
                    {
                        continue;
                    }

                    throw;
                }

                // If things have gotten here, the test passes.

                break;
            }
        }
Ejemplo n.º 2
0
        public void ReadLastEnqueuedEventInformationDelegatesToTheConsumer()
        {
            var lastEvent = new EventData
                            (
                eventBody: Array.Empty <byte>(),
                lastPartitionSequenceNumber: 1234,
                lastPartitionOffset: 42,
                lastPartitionEnqueuedTime: DateTimeOffset.Parse("2015-10-27T00:00:00Z"),
                lastPartitionInformationRetrievalTime: DateTimeOffset.Parse("2012-03-04T08:42Z")
                            );

            var partitionId  = "id-value";
            var mockConsumer = new LastEventConsumerMock(lastEvent);
            var context      = new PartitionContext(partitionId, mockConsumer);
            var information  = context.ReadLastEnqueuedEventInformation();

            Assert.That(information.SequenceNumber, Is.EqualTo(lastEvent.LastPartitionSequenceNumber), "The sequence number should match.");
            Assert.That(information.Offset, Is.EqualTo(lastEvent.LastPartitionOffset), "The offset should match.");
            Assert.That(information.EnqueuedTime, Is.EqualTo(lastEvent.LastPartitionEnqueuedTime), "The last enqueue time should match.");
            Assert.That(information.LastReceivedTime, Is.EqualTo(lastEvent.LastPartitionInformationRetrievalTime), "The retrieval time should match.");
        }