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); } }
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) => { 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); }
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 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); } } }
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); } } }
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); } }