public void CanSendMessageWithSentException() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IAmqpProperties properties = A.Fake <IAmqpProperties>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => channel.CreateBasicProperties()).Returns(null); A.CallTo(() => channel.BasicPublish( A <string> ._, A <string> ._, A <bool> ._, A <IBasicProperties> ._, A <byte[]> ._)) .Throws <Exception>() .Once(); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .Returns(new AmqpMessage(properties, null, null, null)).Twice(); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); Result <AmqpMessage, ExceptionDispatchInfo> result = new Result <AmqpMessage, ExceptionDispatchInfo>( new AmqpMessage(new AmqpProperties(), string.Empty, string.Empty, new byte[0])); Action action = () => sut.Send(result); action.Should().NotThrow("because the AmqpSender should catch all exceptions to prevent from destroying of the DataFlow chain."); }
public async Task CanSendMessageAfterSentException() { // Arrange var channel = A.Fake <IModel>(); A.CallTo(() => channel.CreateBasicProperties()) .Returns(null); A.CallTo(() => channel.BasicPublish( A <string> ._, A <string> ._, A <bool> ._, A <IBasicProperties> ._, A <byte[]> ._)) .Throws <Exception>() .Once(); IAmqpConnectionFactory connectionFactory = GetConnectionFactory(channel); var tasks = new List <TaskCompletionSource <bool> >() { new TaskCompletionSource <bool>(), new TaskCompletionSource <bool>() }; var properties = A.Fake <IAmqpProperties>(); var messageBuilder = A.Fake <AmqpMessageBuilder>(); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .ReturnsNextFromSequence(new AmqpMessage[] { new AmqpMessage(properties, null, null, new byte[1], tasks[0]), new AmqpMessage(properties, null, null, new byte[1], tasks[1]) }); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); var input = new BufferBlock <IMessage>(); sut.SubscribeTo(input); // Act input.Post(new Message <string>("hello", new Dictionary <string, string>(), tasks[0])); input.Post(new Message <string>("hello", new Dictionary <string, string>(), tasks[1])); // Assert await tasks[0].Task.ContinueWith(t => { t.Status.Should().Be(TaskStatus.Faulted); }); (await tasks[1].Task).Should().Be(true); }
void timer_Tick(GT.Timer timer) { timer.Stop(); timer.Interval = _targetTelemetryInterval; OBDIIReader.OBDIIData obdiiData = null; if (this.OBDReader.InitializeObd()) { obdiiData = this.OBDReader.ReadObdIIData(); UpdateDisplay(obdiiData); } #if !MF_EMULATOR this.temperatureHumidity.RequestMeasurement(); #endif #if SB if (this.TimeHelper.UpdateTime()) { GetDeviceProvisioningInfo(); if (this.SBSender == null) { // TODO: Provision SB credentials properly this.SBSender = new AmqpSender(this, this.deviceInfo.baseUri, this.deviceInfo.keyName, this.deviceInfo.keyValue, this.deviceInfo.OutboxEntity); this.SBSender.StartSender(); #if !OrderedMessagingDemo if (this.SBReceiver == null) { // TODO Use the AMQP session and connection of the sender to minimize socket usage/SSL overhead on both client and service this.SBReceiver = new AmqpReceiver(this, this.deviceInfo.baseUri, this.deviceInfo.keyName, this.deviceInfo.keyValue, this.deviceInfo.InboxEntity, OnMessageCallback); //this.SBReceiver = new AmqpReceiver(this, this.SBSender, this.deviceInfo.InboxEntity, OnMessageCallback); this.SBReceiver.SenderForLatencies = this.SBSender; this.SBReceiver.DeviceIdForLatencies = this.deviceInfo.DeviceId.ToString(); this.SBReceiver.Start(); } #endif } else { SendOBDToSB(obdiiData); if (this._lastDeviceTemperatureHumidityTimestamp > DateTime.MinValue) { SendTemperatureToDB(this.deviceInfo.DeviceId, this._lastDeviceTemperatureHumidityTimestamp, this._lastDeviceTemperature, this._lastDeviceHumidity); } } } #endif timer.Start(); }
public void CanLinkTo() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); ISubscriptionTag tag = sut.SubscribeTo(sourceBlock); tag.Id.Should().NotBeNull(); }
public void CanSendMessageWithSerializationException() { IAmqpConnectionFactory connectionFactory = A.Fake <IAmqpConnectionFactory>(); AmqpMessageBuilder messageBuilder = A.Fake <AmqpMessageBuilder>(); ISourceBlock <IMessage> sourceBlock = A.Fake <ISourceBlock <IMessage> >(); IConnection connection = A.Fake <IConnection>(); IAmqpProperties properties = A.Fake <IAmqpProperties>(); IModel channel = A.Fake <IModel>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection); A.CallTo(() => connection.CreateModel()).Returns(channel); A.CallTo(() => messageBuilder.Serialize(A <IMessage> ._)) .Throws <Exception>() .Once() .Then. Returns(new AmqpMessage(properties, null, null, null)); var sut = new AmqpSender(connectionFactory, messageBuilder, new LogServiceProvider()); IMessage message = new Message <string>("hello", new Dictionary <string, string>()); Action action = () => sut.Transform(message); action.Should().NotThrow("because the AmqpSender should catch all exception to prevent from destroying the DataFlow chain."); }