private async Task SendMessagePoolOverAmqp( TestDeviceType type, Client.TransportType transport, int poolSize, int devicesCount, ConnectionStringAuthScope authScope = ConnectionStringAuthScope.Device) { Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) => { s_log.WriteLine($"{nameof(MessageSendE2EPoolAmqpTests)}: Preparing to send message for device {testDevice.Id}"); await deviceClient.OpenAsync().ConfigureAwait(false); (Client.Message testMessage, string messageId, string payload, string p1Value) = MessageSendE2ETests.ComposeD2cTestMessage(); s_log.WriteLine($"{nameof(MessageSendE2EPoolAmqpTests)}.{testDevice.Id}: messageId='{messageId}' payload='{payload}' p1Value='{p1Value}'"); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(testDevice.Id, payload, p1Value); Assert.IsTrue(isReceived, "Message is not received."); }; await PoolingOverAmqp .TestPoolAmqpAsync( _devicePrefix, transport, poolSize, devicesCount, null, testOperation, null, authScope, true) .ConfigureAwait(false); }
public static async Task SendSendBatchMessagesAndVerifyAsync(DeviceClient deviceClient, string deviceId) { EventHubTestListener testListener = await EventHubTestListener.CreateListener(deviceId).ConfigureAwait(false); try { var messages = new List <Client.Message>(); var props = new List <Tuple <string, string> >(); for (int i = 0; i < MESSAGE_BATCH_COUNT; i++) { (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2CTestMessage(); messages.Add(testMessage); props.Add(Tuple.Create(payload, p1Value)); } await deviceClient.SendEventBatchAsync(messages).ConfigureAwait(false); foreach (Tuple <string, string> prop in props) { bool isReceived = await testListener.WaitForMessage(deviceId, prop.Item1, prop.Item2).ConfigureAwait(false); Assert.IsTrue(isReceived, "Message is not received."); } } finally { await testListener.CloseAsync().ConfigureAwait(false); } }
public static async Task SendSendBatchMessagesAndVerifyAsync(DeviceClient deviceClient, string deviceId) { var messages = new List <Client.Message>(); try { var props = new List <Tuple <string, string> >(); for (int i = 0; i < MessageBatchCount; i++) { (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2cTestMessage(); messages.Add(testMessage); props.Add(Tuple.Create(payload, p1Value)); } await deviceClient.SendEventBatchAsync(messages).ConfigureAwait(false); foreach (Tuple <string, string> prop in props) { bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(deviceId, prop.Item1, prop.Item2); Assert.IsTrue(isReceived, "Message is not received."); } } finally { foreach (Client.Message message in messages) { message.Dispose(); } } }
public static async Task SendSendBatchMessagesAndVerifyAsync(DeviceClient deviceClient, string deviceId) { var messagesToBeSent = new Dictionary <Client.Message, Tuple <string, string> >(); try { var props = new List <Tuple <string, string> >(); for (int i = 0; i < MessageBatchCount; i++) { (Client.Message testMessage, string payload, string p1Value) = ComposeD2cTestMessage(); messagesToBeSent.Add(testMessage, Tuple.Create(payload, p1Value)); } await deviceClient.SendEventBatchAsync(messagesToBeSent.Keys.ToList()).ConfigureAwait(false); foreach (KeyValuePair <Client.Message, Tuple <string, string> > messageEntry in messagesToBeSent) { Client.Message message = messageEntry.Key; Tuple <string, string> prop = messageEntry.Value; bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(deviceId, message, prop.Item1, prop.Item2); Assert.IsTrue(isReceived, "Message is not received."); } } finally { foreach (KeyValuePair <Client.Message, Tuple <string, string> > messageEntry in messagesToBeSent) { Client.Message message = messageEntry.Key; message.Dispose(); } } }
private async Task SendSingleMessageModuleAndVerifyAsync(ModuleClient moduleClient, string deviceId) { (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2CTestMessage(); await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(deviceId, payload, p1Value); Assert.IsTrue(isReceived, "Message is not received."); }
private async Task SendMessagePoolOverAmqp( TestDeviceType type, Client.TransportType transport, int poolSize, int devicesCount, ConnectionStringAuthScope authScope = ConnectionStringAuthScope.Device) { Dictionary <string, EventHubTestListener> eventHubListeners = new Dictionary <string, EventHubTestListener>(); Func <DeviceClient, TestDevice, Task> initOperation = async(deviceClient, testDevice) => { EventHubTestListener testListener = await EventHubTestListener.CreateListener(testDevice.Id).ConfigureAwait(false); eventHubListeners.Add(testDevice.Id, testListener); }; Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) => { _log.WriteLine($"{nameof(MessageSendE2EPoolAmqpTests)}: Preparing to send message for device {testDevice.Id}"); await deviceClient.OpenAsync().ConfigureAwait(false); (Client.Message testMessage, string messageId, string payload, string p1Value) = MessageSendE2ETests.ComposeD2CTestMessage(); _log.WriteLine($"{nameof(MessageSendE2EPoolAmqpTests)}.{testDevice.Id}: messageId='{messageId}' payload='{payload}' p1Value='{p1Value}'"); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); EventHubTestListener testListener = eventHubListeners[testDevice.Id]; bool isReceived = await testListener.WaitForMessage(testDevice.Id, payload, p1Value).ConfigureAwait(false); Assert.IsTrue(isReceived, "Message is not received."); }; Func <IList <DeviceClient>, Task> cleanupOperation = async(deviceClients) => { foreach (var listener in eventHubListeners) { await listener.Value.CloseAsync().ConfigureAwait(false); } foreach (DeviceClient deviceClient in deviceClients) { deviceClient.Dispose(); } eventHubListeners.Clear(); }; await PoolingOverAmqp.TestPoolAmqpAsync( DevicePrefix, transport, poolSize, devicesCount, initOperation, testOperation, cleanupOperation, authScope).ConfigureAwait(false); }
private async Task ValidateEvent(string deviceId, string eventId, string payload, string p1Value, EventHubTestListener testListener, AzureSecurityCenterForIoTLogAnalyticsClient logAnalticsTestClient) { bool isReceivedEventHub = await testListener.WaitForMessage(deviceId, payload, p1Value).ConfigureAwait(false); Assert.IsFalse(isReceivedEventHub, "Security message received in customer event hub."); bool isReceivedOms = await logAnalticsTestClient.IsRawEventExist(deviceId, eventId).ConfigureAwait(false); Assert.IsTrue(isReceivedOms, "Security message was not recived in customer log analytics"); }
internal async Task SendMessageRecovery( TestDeviceType type, Client.TransportType transport, string faultType, string reason, int delayInSec, int durationInSec = FaultInjection.DefaultDurationInSec, int retryDurationInMilliSec = FaultInjection.RecoveryTimeMilliseconds) { EventHubTestListener testListener = null; Func <DeviceClient, TestDevice, Task> init = async(deviceClient, testDevice) => { testListener = await EventHubTestListener.CreateListener(testDevice.Id).ConfigureAwait(false); deviceClient.OperationTimeoutInMilliseconds = (uint)retryDurationInMilliSec; }; Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) => { string payload, p1Value; Client.Message testMessage = ComposeD2CTestMessage(out payload, out p1Value); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = false; isReceived = await testListener.WaitForMessage(testDevice.Id, payload, p1Value).ConfigureAwait(false); Assert.IsTrue(isReceived); }; Func <Task> cleanupOperation = () => { if (testListener != null) { return(testListener.CloseAsync()); } else { return(Task.FromResult(false)); } }; await FaultInjection.TestErrorInjectionAsync( DevicePrefix, type, transport, faultType, reason, delayInSec, durationInSec, init, testOperation, cleanupOperation).ConfigureAwait(false); }
public static async Task SendSingleMessageAndVerifyAsync(DeviceClient deviceClient, string deviceId) { (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2cTestMessage(); using (testMessage) { await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(deviceId, payload, p1Value); Assert.IsTrue(isReceived, "Message is not received."); } }
private async Task ValidateEventAsync( string deviceId, string eventId, string payload, string p1Value, AzureSecurityCenterForIoTLogAnalyticsClient logAnalticsTestClient) { bool isReceivedEventHub = EventHubTestListener.VerifyIfMessageIsReceived(deviceId, payload, p1Value, TimeSpan.FromSeconds(10)); Assert.IsFalse(isReceivedEventHub, "Security message received in customer event hub."); bool isReceivedOms = await logAnalticsTestClient.IsRawEventExist(deviceId, eventId).ConfigureAwait(false); Assert.IsTrue(isReceivedOms, "Security message was not received in customer log analytics"); }
private async Task SendMessageRecoveryPoolOverAmqpAsync( TestDeviceType type, Client.TransportType transport, int poolSize, int devicesCount, string faultType, string reason, int delayInSec = FaultInjection.DefaultDelayInSec, int durationInSec = FaultInjection.DefaultDurationInSec, ConnectionStringAuthScope authScope = ConnectionStringAuthScope.Device) { Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) => { _log.WriteLine($"{nameof(FaultInjectionPoolAmqpTests)}: Preparing to send message for device {testDevice.Id}"); await deviceClient.OpenAsync().ConfigureAwait(false); (Client.Message testMessage, string messageId, string payload, string p1Value) = MessageSendE2ETests.ComposeD2cTestMessage(); _log.WriteLine($"{nameof(FaultInjectionPoolAmqpTests)}.{testDevice.Id}: payload='{payload}' p1Value='{p1Value}'"); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(testDevice.Id, payload, p1Value); Assert.IsTrue(isReceived, $"Message is not received for device {testDevice.Id}."); }; Func <IList <DeviceClient>, Task> cleanupOperation = (deviceClients) => { foreach (DeviceClient deviceClient in deviceClients) { deviceClient.Dispose(); } return(Task.FromResult(0)); }; await FaultInjectionPoolingOverAmqp .TestFaultInjectionPoolAmqpAsync( MessageSend_DevicePrefix, transport, poolSize, devicesCount, faultType, reason, delayInSec, durationInSec, (d, t) => { return(Task.FromResult(false)); }, testOperation, cleanupOperation, authScope) .ConfigureAwait(false); }
private async Task SendSingleMessageModuleAndVerifyAsync(ModuleClient moduleClient, string deviceId) { EventHubTestListener testListener = await EventHubTestListener.CreateListener(deviceId).ConfigureAwait(false); try { (Client.Message testMessage, string messageId, string payload, string p1Value) = ComposeD2CTestMessage(); await moduleClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = await testListener.WaitForMessage(deviceId, payload, p1Value).ConfigureAwait(false); Assert.IsTrue(isReceived, "Message is not received."); } finally { await testListener.CloseAsync().ConfigureAwait(false); } }
private async Task TestSecurityMessage(Client.TransportType transport) { TestDevice testDevice = await TestDevice.GetTestDeviceAsync(_devicePrefix).ConfigureAwait(false); EventHubTestListener testListener = await EventHubTestListener.CreateListener(testDevice.Id).ConfigureAwait(false); using (DeviceClient deviceClient = testDevice.CreateDeviceClient(transport)) { try { await SendSingleSecurityMessage(deviceClient, testDevice.Id, testListener, _logAnalyticsClient).ConfigureAwait(false); } finally { await deviceClient.CloseAsync().ConfigureAwait(false); await testListener.CloseAsync().ConfigureAwait(false); } } }
private async Task TestSecurityMessageModule(Client.TransportType transport) { TestModule testModule = await TestModule.GetTestModuleAsync(_devicePrefix, _modulePrefix).ConfigureAwait(false); EventHubTestListener testListener = await EventHubTestListener.CreateListener(testModule.Id).ConfigureAwait(false); using (ModuleClient moduleClient = ModuleClient.CreateFromConnectionString(testModule.ConnectionString, transport)) { try { await SendSingleSecurityMessageModule(moduleClient, testModule.DeviceId, testListener, _logAnalyticsClient).ConfigureAwait(false); } finally { await moduleClient.CloseAsync().ConfigureAwait(false); await testListener.CloseAsync().ConfigureAwait(false); } } }
public static async Task SendSingleMessageAndVerifyAsync(DeviceClient deviceClient, string deviceId) { EventHubTestListener testListener = await EventHubTestListener.CreateListener(deviceId).ConfigureAwait(false); try { string payload; string p1Value; Client.Message testMessage = ComposeD2CTestMessage(out payload, out p1Value); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = await testListener.WaitForMessage(deviceId, payload, p1Value).ConfigureAwait(false); Assert.IsTrue(isReceived, "Message is not received."); } finally { await testListener.CloseAsync().ConfigureAwait(false); } }
internal async Task SendMessageRecoveryAsync( TestDeviceType type, Client.TransportType transport, string faultType, string reason, int delayInSec, int durationInSec = FaultInjection.DefaultDurationInSec, int retryDurationInMilliSec = FaultInjection.RecoveryTimeMilliseconds) { Func <DeviceClient, TestDevice, Task> init = (deviceClient, testDevice) => { deviceClient.OperationTimeoutInMilliseconds = (uint)retryDurationInMilliSec; return(Task.FromResult(0)); }; Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) => { (Client.Message testMessage, string messageId, string payload, string p1Value) = MessageSendE2ETests.ComposeD2cTestMessage(); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = false; isReceived = EventHubTestListener.VerifyIfMessageIsReceived(testDevice.Id, payload, p1Value); Assert.IsTrue(isReceived); }; await FaultInjection .TestErrorInjectionAsync( _devicePrefix, type, transport, faultType, reason, delayInSec, durationInSec, init, testOperation, () => { return(Task.FromResult(false)); }) .ConfigureAwait(false); }
public static async Task SendSingleMessageAndVerifyAsync(DeviceClient deviceClient, string deviceId, int messageSize = 0) { Client.Message testMessage; string payload; string p1Value; if (messageSize == 0) { (testMessage, _, payload, p1Value) = ComposeD2cTestMessage(); } else { (testMessage, _, payload, p1Value) = ComposeD2cTestMessageOfSpecifiedSize(messageSize); } using (testMessage) { await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(deviceId, payload, p1Value); Assert.IsTrue(isReceived, "Message is not received."); } }
private async Task SendSingleSecurityMessage(DeviceClient deviceClient, string deviceId, EventHubTestListener testListener, AzureSecurityCenterForIoTLogAnalyticsClient logAnalticsTestClient) { await deviceClient.OpenAsync().ConfigureAwait(false); Client.Message testMessage = ComposeD2CSecurityTestMessage(out string eventId, out string payload, out string p1Value); await deviceClient.SendEventAsync(testMessage).ConfigureAwait(false); await ValidateEvent(deviceId, eventId, payload, p1Value, testListener, logAnalticsTestClient).ConfigureAwait(false); }
private Task SendSingleSecurityMessageModule(ModuleClient moduleClient, string deviceId, EventHubTestListener testListener, AzureSecurityCenterForIoTLogAnalyticsClient logAnalticsTestClient) { moduleClient.OpenAsync(); Client.Message testMessage = ComposeD2CSecurityTestMessage(out string eventId, out string payload, out string p1Value); moduleClient.SendEventAsync(testMessage); return(ValidateEvent(deviceId, eventId, payload, p1Value, testListener, logAnalticsTestClient)); }