public StoreLimitsTestBase(bool usePersistentStorage) { ConfigHelper.TestConfig["UsePersistentStorage"] = usePersistentStorage.ToString(); ConfigHelper.TestConfig["MaxStorageBytes"] = MaxStorageSize.ToString(); ConfigHelper.TestConfig["TimeToLiveSecs"] = "0"; ConfigHelper.TestConfig["Routes"] = JsonConvert.SerializeObject(Routes); this.protocolHeadFixture = EdgeHubFixtureCollection.GetFixture(); }
public EdgeHubTestFixture() { if (protocolHeadFixtureInstance == null) { lock (FixtureLock) { if (protocolHeadFixtureInstance == null) { protocolHeadFixtureInstance = EdgeHubFixtureCollection.GetFixture(); } } } }
public SslProtocolsTest() { this.protocolHead = EdgeHubFixtureCollection.GetFixture(SslProtocols.Tls12); }
async Task BackupAndRestoreMessageDeliveryTestBase( ITransportSettings[] transportSettings, int beforeBackupMessageCount, int afterBackupMessageCount, int expectedMessageCountAfterRestore, Action postBackupModifier) { ProtocolHeadFixture protocolHeadFixture = EdgeHubFixtureCollection.GetFixture(); TestModule sender = null; TestModule receiver = null; string edgeDeviceConnectionString = await SecretsHelper.GetSecretFromConfigKey("edgeCapableDeviceConnStrKey"); IotHubConnectionStringBuilder connectionStringBuilder = IotHubConnectionStringBuilder.Create(edgeDeviceConnectionString); RegistryManager rm = RegistryManager.CreateFromConnectionString(edgeDeviceConnectionString); Func <int, TimeSpan> waitTimeComputer = (numberOfMessages) => TimeSpan.FromMinutes(Math.Ceiling(numberOfMessages / 2000d) + 2); try { sender = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "sender1", transportSettings); receiver = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "receiver1", transportSettings); Console.WriteLine($"Sending {beforeBackupMessageCount} messages."); // Send 10 messages before a receiver is registered. Task <int> task1 = sender.SendMessagesByCountAsync("output1", 0, beforeBackupMessageCount, waitTimeComputer(beforeBackupMessageCount)); int sentMessagesCount = await task1; Assert.Equal(beforeBackupMessageCount, sentMessagesCount); TimeSpan waitTime = TimeSpan.FromMinutes(2); Console.WriteLine($"Waiting {waitTime.TotalSeconds} seconds before validating receipt of messages."); // Wait for a while and then close the test fixture which will in turn close the protocol heads and the in-memory DB store thus creating a backup. await Task.Delay(TimeSpan.FromMinutes(2)); await protocolHeadFixture.CloseAsync(); Console.WriteLine("Protocol heads closed."); postBackupModifier(); // Get new fixture to re-initialize the edge hub container. protocolHeadFixture = EdgeHubFixtureCollection.GetFixture(); // Reconnect clients due to C# SDK bug where it illegally attempts to send through closed amqp link sender = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "sender1", transportSettings); receiver = await TestModule.CreateAndConnect(rm, connectionStringBuilder.HostName, connectionStringBuilder.DeviceId, "receiver1", transportSettings); // Register the message handler now. await receiver.SetupReceiveMessageHandler(); Console.WriteLine($"Sending {afterBackupMessageCount} messages."); // Send more messages after the receiver is registered. Task <int> task2 = sender.SendMessagesByCountAsync("output1", beforeBackupMessageCount, afterBackupMessageCount, TimeSpan.FromMinutes(2)); sentMessagesCount = await task2; Assert.Equal(afterBackupMessageCount, sentMessagesCount); waitTime = waitTimeComputer(expectedMessageCountAfterRestore); Console.WriteLine($"Waiting {waitTime.TotalSeconds} seconds before validating receipt of messages."); // Validate that all the messages were received (both sent earlier and the new messages). await Task.Delay(waitTime); ISet <int> receivedMessages = receiver.GetReceivedMessageIndices(); Assert.Equal(expectedMessageCountAfterRestore, receivedMessages.Count); } finally { if (rm != null) { await rm.CloseAsync(); rm.Dispose(); } if (sender != null) { await sender.Disconnect(); sender.Dispose(); } if (receiver != null) { await receiver.Disconnect(); receiver.Dispose(); } await protocolHeadFixture.CloseAsync(); } // wait for the connection to be closed on the Edge side await Task.Delay(TimeSpan.FromSeconds(10)); }