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) => { _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); bool isReceived = EventHubTestListener.VerifyIfMessageIsReceived(testDevice.Id, payload, p1Value); Assert.IsTrue(isReceived, "Message is not received."); }; Func <IList <DeviceClient>, Task> cleanupOperation = (deviceClients) => { foreach (DeviceClient deviceClient in deviceClients) { deviceClient.Dispose(); } return(Task.FromResult(0)); }; await PoolingOverAmqp.TestPoolAmqpAsync( DevicePrefix, transport, poolSize, devicesCount, (d, t) => { return(Task.FromResult(false)); }, testOperation, cleanupOperation, authScope, true).ConfigureAwait(false); }
internal async Task SendMessageRecovery( 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); }
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); }
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) => { (Client.Message testMessage, string messageId, string payload, string p1Value) = MessageSendE2ETests.ComposeD2CTestMessage(); 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); }