コード例 #1
0
        public void IsEventPositionEquivalentDetectsDifferentSequence()
        {
            var trackOnePosition = TrackOne.EventPosition.FromSequenceNumber(54123);
            var trackTwoPosition = EventPosition.FromSequenceNumber(2);

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.False);
        }
コード例 #2
0
        public async Task ReceiverIsConstructedCorrectly()
        {
            var eventHub         = "eventHub";
            var consumerGroup    = "$TestThing";
            var partition        = "123";
            var position         = EventPosition.FromEnqueuedTime(DateTimeOffset.Parse("2015-10-25T12:00:00Z"));
            var priority         = 8765;
            var identifier       = "ThisIsAnAwesomeConsumer!";
            var partitionMetrics = new LastEnqueuedEventProperties(eventHub, partition);
            var retryPolicy      = Mock.Of <EventHubRetryPolicy>();
            var mock             = new ObservableReceiverMock(new ClientMock(), consumerGroup, partition, TrackOne.EventPosition.FromEnqueuedTime(position.EnqueuedTime.Value.UtcDateTime), priority, new ReceiverOptions {
                Identifier = identifier, EnableReceiverRuntimeMetric = true
            });
            var consumer = new TrackOneEventHubConsumer(_ => mock, retryPolicy, partitionMetrics);

            // Invoke an operation to force the consumer to be lazily instantiated.  Otherwise,
            // construction does not happen.

            await consumer.ReceiveAsync(0, TimeSpan.Zero, default);

            Assert.That(mock.ConstructedWith.ConsumerGroup, Is.EqualTo(consumerGroup), "The consumer group should match.");
            Assert.That(mock.ConstructedWith.Partition, Is.EqualTo(partition), "The partition should match.");
            Assert.That(TrackOneComparer.IsEventPositionEquivalent(mock.ConstructedWith.Position, position), Is.True, "The starting event position should match.");
            Assert.That(mock.ConstructedWith.Priority, Is.EqualTo(priority), "The owner level should match.");
            Assert.That(mock.ConstructedWith.Options.Identifier, Is.EqualTo(identifier), "The consumer identifier should match.");
            Assert.That(mock.ConstructedWith.Options.EnableReceiverRuntimeMetric, Is.True, "The receiver metrics should be enabled when set in the options.");

            var consumerRetry = GetRetryPolicy(consumer);

            Assert.That(consumerRetry, Is.SameAs(retryPolicy), "The consumer retry instance should match.");
        }
コード例 #3
0
        public void IsEventPositionEquivalentRecognizesSameOffsets()
        {
            var trackOnePosition = TrackOne.EventPosition.FromOffset("12", true);
            var trackTwoPosition = EventPosition.FromOffset(12);

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True, "The offset for track two is inclusive; the equivalent offset set as inclusive should match.");
        }
コード例 #4
0
        public void IsEventPositionEquivalentRecognizesSameBeginning()
        {
            var trackOnePosition = TrackOne.EventPosition.FromStart();
            var trackTwoPosition = EventPosition.Earliest;

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True);
        }
コード例 #5
0
        public async Task SendAsyncTransformsSimpleEvents()
        {
            var sourceEvents = new[]
            {
                new EventData(Encoding.UTF8.GetBytes("FirstValue")),
                new EventData(Encoding.UTF8.GetBytes("Second")),
                new EventData(new byte[] { 0x11, 0x22, 0x33 })
            };

            var options  = new SendOptions();
            var mock     = new ObservableSenderMock(new ClientMock(), null);
            var producer = new TrackOneEventHubProducer(_ => mock, Mock.Of <EventHubRetryPolicy>());

            await producer.SendAsync(sourceEvents, options, CancellationToken.None);

            Assert.That(mock.SendCalledWithParameters, Is.Not.Null, "The Send request should have been delegated.");

            var sentEvents = mock.SendCalledWithParameters.Events.ToArray();

            Assert.That(sentEvents.Length, Is.EqualTo(sourceEvents.Length), "The number of events sent should match the number of source events.");

            // The events should not only be structurally equivalent, the ordering of them should be preserved.  Compare the
            // sequence in order and validate that the events in each position are equivalent.

            for (var index = 0; index < sentEvents.Length; ++index)
            {
                // If the system properties for the sent events was null, then normalize it to an empty
                // instance because the source event does not allow null.

                sentEvents[index].SystemProperties = sentEvents[index].SystemProperties ?? new TrackOne.EventData.SystemPropertiesCollection();
                Assert.That(TrackOneComparer.IsEventDataEquivalent(sentEvents[index], sourceEvents[index]), Is.True, $"The sequence of events sent should match; they differ at index: { index }");
            }
        }
コード例 #6
0
        public void IsEventPositionEquivalentRecognizesSameEnding()
        {
            var trackOnePosition = TrackOne.EventPosition.FromEnd();
            var trackTwoPosition = EventPosition.Latest;

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True);
        }
コード例 #7
0
        public void IsEventDataEquivalentDetectsEqualEvents()
        {
            var body   = new byte[] { 0x22, 0x44, 0x88 };
            var offset = 27;
            var trackTwoSystemProperties = new Dictionary <string, object>();

            var trackTwoEvent = new EventData(
                eventBody: (byte[])body.Clone(),
                offset: offset,
                systemProperties: trackTwoSystemProperties,
                lastPartitionSequenceNumber: 9765551212,
                lastPartitionOffset: 54321,
                lastPartitionEnqueuedTime: DateTimeOffset.Parse("2015-10-27T00:00:00Z"));

            trackTwoEvent.Properties["test"] = "same";

            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());

            trackOneEvent.Properties["test"] = trackTwoEvent.Properties["test"];
            trackOneEvent.SystemProperties   = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties[TrackOne.ClientConstants.OffsetName] = offset.ToString();
            trackOneEvent.LastEnqueuedOffset = trackTwoEvent.LastPartitionOffset.ToString();
            trackOneEvent.LastSequenceNumber = trackTwoEvent.LastPartitionSequenceNumber.Value;
            trackOneEvent.LastEnqueuedTime   = trackTwoEvent.LastPartitionEnqueuedTime.Value.UtcDateTime;

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.True);
        }
コード例 #8
0
        public void IsEventDataEquivalentDetectsDifferentBodies()
        {
            var trackOneEvent = new TrackOne.EventData(new byte[] { 0x22, 0x44 });
            var trackTwoEvent = new EventData(new byte[] { 0x11, 0x33 });

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #9
0
        public async Task SendAsyncTransformsSimpleEvents()
        {
            var sourceEvents = new[]
            {
                new EventData(Encoding.UTF8.GetBytes("FirstValue")),
                new EventData(Encoding.UTF8.GetBytes("Second")),
                new EventData(new byte[] { 0x11, 0x22, 0x33 })
            };

            var options = new EventBatchingOptions();
            var mock    = new ObservableSenderMock(new ClientMock(), null);
            var sender  = new TrackOneEventSender(() => mock);

            await sender.SendAsync(sourceEvents, options, CancellationToken.None);

            Assert.That(mock.SendCalledWithParameters, Is.Not.Null, "The Send request should have been delegated.");

            var sentEvents = mock.SendCalledWithParameters.Events.ToArray();

            Assert.That(sentEvents.Length, Is.EqualTo(sourceEvents.Length), "The number of events sent should match the number of source events.");

            // The events should not only be structurally equivilent, the ordering of them should be preserved.  Compare the
            // sequence in order and validate that the events in each position are equivilent.

            for (var index = 0; index < sentEvents.Length; ++index)
            {
                Assert.That(TrackOneComparer.IsEventDataEquivalent(sentEvents[index], sourceEvents[index]), Is.True, $"The sequence of events sent should match; they differ at index: { index }");
            }
        }
コード例 #10
0
        public void IsEventPositionEquivalentRecognizesSameSequence()
        {
            var trackOnePosition = TrackOne.EventPosition.FromSequenceNumber(54123);
            var trackTwoPosition = EventPosition.FromSequenceNumber(54123);

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True);
        }
コード例 #11
0
        public void IsEventPositionEquivalentDetectsDifferentOffsets()
        {
            var trackOnePosition = TrackOne.EventPosition.FromOffset("12", false);
            var trackTwoPosition = EventPosition.FromOffset(12);

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.False, "The offset for track two is inclusive; even the same base offset with non-inclusive is not equivalent.");
        }
コード例 #12
0
        public void IsEventPositionEquivalentDetectsDifferentEnqueueTime()
        {
            var enqueueTime      = DateTimeOffset.Parse("2015-10-27T12:00:00Z");
            var trackOnePosition = TrackOne.EventPosition.FromEnqueuedTime(enqueueTime.UtcDateTime);
            var trackTwoPosition = EventPosition.FromEnqueuedTime(enqueueTime.AddDays(1));

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.False);
        }
コード例 #13
0
        public void IsEventPositionEquivalentRecognizesSameEnqueueTime()
        {
            var enqueueTime      = DateTimeOffset.Parse("2015-10-27T12:00:00Z");
            var trackOnePosition = TrackOne.EventPosition.FromEnqueuedTime(enqueueTime.UtcDateTime);
            var trackTwoPosition = EventPosition.FromEnqueuedTime(enqueueTime);

            Assert.That(TrackOneComparer.IsEventPositionEquivalent(trackOnePosition, trackTwoPosition), Is.True);
        }
コード例 #14
0
        public void IsEventDataEquivalentDetectsWhenOnePropertySetIsNull()
        {
            var body          = new byte[] { 0x22, 0x44, 0x88 };
            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());
            var trackTwoEvent = new EventData((byte[])body.Clone());

            trackOneEvent.Properties         = null;
            trackTwoEvent.Properties["test"] = "trackTwo";

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #15
0
        public void IsEventDataEquivalentDetectsWhenOneSystemPropertySetIsNull()
        {
            var body          = new byte[] { 0x22, 0x44, 0x88 };
            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());
            var trackTwoEvent = new EventData((byte[])body.Clone());

            trackOneEvent.SystemProperties = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties["something"] = "trackOne";

            trackTwoEvent.SystemProperties = null;

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #16
0
        public void IsEventDataEquivalentDetectsDifferentSystemProperties()
        {
            var body          = new byte[] { 0x22, 0x44, 0x88 };
            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());
            var trackTwoEvent = new EventData((byte[])body.Clone());

            trackOneEvent.SystemProperties = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties[TrackOne.ClientConstants.OffsetName] = "4";

            trackTwoEvent.SystemProperties        = new EventData.SystemEventProperties();
            trackTwoEvent.SystemProperties.Offset = 27;

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #17
0
        public void IsEventDataEquivalentDetectsDifferentSystemPropertiesWithMissingTypedMember()
        {
            var body = new byte[] { 0x22, 0x44, 0x88 };
            var trackTwoSystemProperties = new Dictionary <string, object>();

            var trackTwoEvent = new EventData(
                eventBody: (byte[])body.Clone(),
                systemProperties: trackTwoSystemProperties);

            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());

            trackOneEvent.SystemProperties = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties[TrackOne.ClientConstants.OffsetName] = "4";

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #18
0
        public void IsEventDataEquivalentDetectsEqualEvents()
        {
            var body          = new byte[] { 0x22, 0x44, 0x88 };
            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());
            var trackTwoEvent = new EventData((byte[])body.Clone());

            trackOneEvent.Properties["test"] = "same";
            trackTwoEvent.Properties["test"] = "same";

            trackOneEvent.SystemProperties = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties["something"] = "otherSame";

            trackTwoEvent.SystemProperties = new EventData.SystemEventProperties();
            trackTwoEvent.SystemProperties["something"] = "otherSame";

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.True);
        }
コード例 #19
0
        public void IsEventDataEquivalentDetectsDifferentSystemPropertiesWithMapMember()
        {
            var body                     = new byte[] { 0x22, 0x44, 0x88 };
            var propertyName             = "Something";
            var trackTwoSystemProperties = new Dictionary <string, object>();

            var trackTwoEvent = new EventData(
                eventBody: (byte[])body.Clone(),
                systemProperties: trackTwoSystemProperties);

            trackTwoSystemProperties[propertyName] = nameof(trackTwoSystemProperties);

            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());

            trackOneEvent.SystemProperties = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties[propertyName] = nameof(trackOneEvent);

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #20
0
        public void IsEventDataEquivalentDetectsDifferentSystemPropertiesMismatchedMembers()
        {
            var body                     = new byte[] { 0x22, 0x44, 0x88 };
            var propertyValue            = "one";
            var trackTwoSystemProperties = new Dictionary <string, object>();

            var trackTwoEvent = new EventData(
                eventBody: (byte[])body.Clone(),
                systemProperties: trackTwoSystemProperties);

            trackTwoSystemProperties["two"] = propertyValue;

            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());

            trackOneEvent.SystemProperties        = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties["one"] = propertyValue;

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.False);
        }
コード例 #21
0
        public void IsEventDataEquivalentDetectsEqualEvents()
        {
            var body   = new byte[] { 0x22, 0x44, 0x88 };
            var offset = 27;
            var trackTwoSystemProperties = new Dictionary <string, object>();

            var trackTwoEvent = new EventData(
                eventBody: (byte[])body.Clone(),
                offset: offset,
                systemProperties: trackTwoSystemProperties);

            var trackOneEvent = new TrackOne.EventData((byte[])body.Clone());

            trackOneEvent.Properties["test"] = "same";
            trackTwoEvent.Properties["test"] = "same";
            trackOneEvent.SystemProperties   = new TrackOne.EventData.SystemPropertiesCollection();
            trackOneEvent.SystemProperties[TrackOne.ClientConstants.OffsetName] = offset.ToString();

            Assert.That(TrackOneComparer.IsEventDataEquivalent(trackOneEvent, trackTwoEvent), Is.True);
        }
コード例 #22
0
        public async Task ReceiverIsConstructedCorrectly()
        {
            var consumerGroup = "$TestThing";
            var partition     = "123";
            var position      = EventPosition.FromEnqueuedTime(DateTime.Parse("2015-10-25T12:00:00Z"));
            var priority      = 8765;
            var identifier    = "ThisIsAnAwesomeConsumer!";
            var mock          = new ObservableReceiverMock(new ClientMock(), consumerGroup, partition, TrackOne.EventPosition.FromEnqueuedTime(position.EnqueuedTimeUtc.Value), priority, new ReceiverOptions {
                Identifier = identifier
            });
            var consumer = new TrackOneEventHubConsumer(() => mock);

            // Invoke an operation to force the consumer to be lazily instantiated.  Otherwise,
            // construction does not happen.

            await consumer.ReceiveAsync(0, TimeSpan.Zero, default);

            Assert.That(mock.ConstructedWith.ConsumerGroup, Is.EqualTo(consumerGroup), "The consumer group should match.");
            Assert.That(mock.ConstructedWith.Partition, Is.EqualTo(partition), "The partition should match.");
            Assert.That(TrackOneComparer.IsEventPositionEquivalent(mock.ConstructedWith.Position, position), Is.True, "The starting event position should match.");
            Assert.That(mock.ConstructedWith.Priority, Is.EqualTo(priority), "The ownerlevel should match.");
            Assert.That(mock.ConstructedWith.Options.Identifier, Is.EqualTo(identifier), "The consumer identifier should match.");
        }