コード例 #1
0
            public static void ProcessSingleEvent([EventHubTrigger(TestHubName, Connection = TestHubName)] string evt,
                                                  string partitionKey, DateTime enqueuedTimeUtc, IDictionary <string, object> properties,
                                                  IDictionary <string, object> systemProperties,
                                                  PartitionContext partitionContext)
            {
                Assert.True((DateTime.Now - enqueuedTimeUtc).TotalSeconds < 30);

                Assert.AreEqual("value1", properties["TestProp1"]);
                Assert.AreEqual("value2", properties["TestProp2"]);

                Assert.NotNull(partitionContext.PartitionId);
                Assert.NotNull(partitionContext.ReadLastEnqueuedEventProperties());

                _eventWait.Set();
            }
コード例 #2
0
        public async Task TheConsumerIsNotKeptAlive()
        {
            var partitionId  = "id-value";
            var mockConsumer = new LastEventConsumerMock(new EventData(new BinaryData(Array.Empty <byte>())));
            var context      = new PartitionContext(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.ReadLastEnqueuedEventProperties(), Throws.InstanceOf <EventHubsException>().And.Property(nameof(EventHubsException.Reason)).EqualTo(EventHubsException.FailureReason.ClientClosed));
                }
                catch (AssertionException)
                {
                    if (++attempts <= maxAttempts)
                    {
                        continue;
                    }

                    throw;
                }

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

                break;
            }
        }
コード例 #3
0
        public void ReadLastEnqueuedEventPropertiesDelegatesToTheConsumer()
        {
            var lastEvent = new EventData
                            (
                eventBody: Array.Empty <byte>(),
                lastPartitionSequenceNumber: 1234,
                lastPartitionOffset: 42,
                lastPartitionEnqueuedTime: DateTimeOffset.Parse("2015-10-27T00:00:00Z"),
                lastPartitionPropertiesRetrievalTime: DateTimeOffset.Parse("2012-03-04T08:42Z")
                            );

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

            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.LastPartitionPropertiesRetrievalTime), "The retrieval time should match.");
        }
コード例 #4
0
        public void ReadLastEnqueuedEventPropertiesDelegatesToTheConsumer()
        {
            var lastEvent = new EventData
                            (
                eventBody: new BinaryData(Array.Empty <byte>()),
                lastPartitionSequenceNumber: 1234,
                lastPartitionOffset: 42,
                lastPartitionEnqueuedTime: DateTimeOffset.Parse("2015-10-27T00:00:00Z"),
                lastPartitionPropertiesRetrievalTime: DateTimeOffset.Parse("2012-03-04T08:42Z")
                            );

            var mockConsumer = new LastEventConsumerMock(lastEvent);
            var context      = new PartitionContext("fqns", "hub", "consumerGroup", "partition", mockConsumer);
            var information  = context.ReadLastEnqueuedEventProperties();

            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.LastPartitionPropertiesRetrievalTime), "The retrieval time should match.");
            Assert.That(mockConsumer.IsClosed, Is.False, "The consumer should not have been closed or disposed of.");
        }
コード例 #5
0
            public static void ProcessMultipleEvents([EventHubTrigger(TestHubName, Connection = TestHubName)] string[] events,
                                                     string[] partitionKeyArray, DateTime[] enqueuedTimeUtcArray, IDictionary <string, object>[] propertiesArray,
                                                     IDictionary <string, object>[] systemPropertiesArray, PartitionContext partitionContext)
            {
                Assert.AreEqual(events.Length, partitionKeyArray.Length);
                Assert.AreEqual(events.Length, enqueuedTimeUtcArray.Length);
                Assert.AreEqual(events.Length, propertiesArray.Length);
                Assert.AreEqual(events.Length, systemPropertiesArray.Length);

                for (int i = 0; i < events.Length; i++)
                {
                    Assert.AreEqual(s_processedEventCount++, propertiesArray[i]["TestIndex"]);
                }

                Assert.NotNull(partitionContext.PartitionId);
                Assert.AreNotEqual(default(LastEnqueuedEventProperties), partitionContext.ReadLastEnqueuedEventProperties());

                if (s_processedEventCount == s_eventCount)
                {
                    _results.AddRange(events);
                    _eventWait.Set();
                }
            }