public void DeviceScopeMuxConnection_MaxDevicesPerConnectionTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); // Reduce poolsize to 1. This will mux all devices onto one connection amqpConnectionPoolSettings.MaxPoolSize = 1; var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock <IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act // Create 995 Muxed Device Connections for (int i = 0; i < AmqpConnectionPoolSettings.MaxDevicesPerConnection; i++) { connectionPool.GetConnection(iotHubConnectionString + "DeviceId=" + Guid.NewGuid().ToString()); } // try one more. This should throw invalid operation exception var connection = connectionPool.GetConnection(iotHubConnectionString + "DeviceId=" + Guid.NewGuid().ToString()); }
public async Task DeviceScopeMuxConnection_ConnectionIdleTimeoutTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); amqpConnectionPoolSettings.ConnectionIdleTimeout = TimeSpan.FromSeconds(5); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock <IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act var connections = new IotHubDeviceMuxConnection[10]; // Create 10 Muxed Device Connections - these should hash into different mux connections for (int i = 0; i < 10; i++) { connections[i] = (IotHubDeviceMuxConnection)connectionPool.GetConnection(i.ToString()); } for (int j = 0; j < 10; j++) { connectionPool.RemoveDeviceFromConnection(connections[j], j.ToString()); } await Task.Delay(TimeSpan.FromSeconds(6)).ConfigureAwait(false); // Assert Assert.IsTrue(connectionPool.GetCount() == 0, "Did not cleanup all Connection objects"); }
public IotHubDeviceMuxConnection(IotHubDeviceScopeConnectionPool deviceScopeConnectionPool, long cacheKey, IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSettings) : base(connectionString.HostName, connectionString.AmqpEndpoint.Port, amqpTransportSettings) { this.deviceScopeConnectionPool = deviceScopeConnectionPool; this.cacheKey = cacheKey; this.FaultTolerantSession = new FaultTolerantAmqpObject<AmqpSession>(this.CreateSessionAsync, this.CloseConnection); this.iotHubTokenRefreshers = new ConcurrentDictionary<AmqpObject, IotHubTokenRefresher>(); }
public void DeviceScopeMuxConnection_PoolingOnNegativeReleaseTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock<IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); connectionCache.Setup(cache => cache.GetConnection(It.IsAny<IotHubConnectionString>(), It.IsAny<AmqpTransportSettings>())).Returns(connectionPool.GetConnection("device1")); // Act var connection = connectionCache.Object.GetConnection(iotHubConnectionString, amqpTransportSettings); // throw exception if you release a device that is not in the pool connection.Release("device2"); }
public void DeviceScopeMuxConnection_PoolingOnNegativeReleaseTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock <IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); connectionCache.Setup(cache => cache.GetConnection(It.IsAny <IotHubConnectionString>(), It.IsAny <AmqpTransportSettings>())).Returns(connectionPool.GetConnection("device1")); // Act var connection = connectionCache.Object.GetConnection(iotHubConnectionString, amqpTransportSettings); // throw exception if you release a device that is not in the pool connection.Release("device2"); }
public void DeviceScopeMuxConnection_PoolingOnPositiveReleaseTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=dGVzdFN0cmluZzE="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock <IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); connectionCache.Setup( cache => cache.GetConnection(It.IsAny <IotHubConnectionString>(), It.IsAny <AmqpTransportSettings>())).Returns(connectionPool.GetConnection("device1")); // Act var connection = connectionCache.Object.GetConnection(iotHubConnectionString, amqpTransportSettings); connection.Release("device1"); // Success - Device1 was in the pool and released }
public void DeviceScopeMuxConnection_NumberOfPoolsTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock <IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act // Create 10 Muxed Device Connections - these should hash into different mux connections for (int i = 0; i < 10; i++) { var connection = connectionPool.GetConnection(i.ToString()); } // Assert Assert.IsTrue(connectionPool.GetCount() == 10, "Did not create 10 different Connection objects"); }
public void DeviceScopeMuxConnection_MaxDevicesPerConnectionTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); // Reduce poolsize to 1. This will mux all devices onto one connection amqpConnectionPoolSettings.MaxPoolSize = 1; var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock<IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act // Create 995 Muxed Device Connections for (int i = 0; i < AmqpConnectionPoolSettings.MaxDevicesPerConnection; i++) { connectionPool.GetConnection(iotHubConnectionString + "DeviceId=" + Guid.NewGuid().ToString()); } // try one more. This should throw invalid operation exception var connection = connectionPool.GetConnection(iotHubConnectionString + "DeviceId=" + Guid.NewGuid().ToString()); }
public async Task DeviceScopeMuxConnection_ConnectionIdleTimeoutTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); amqpConnectionPoolSettings.ConnectionIdleTimeout = TimeSpan.FromSeconds(5); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock<IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act var connections = new IotHubDeviceMuxConnection[10]; // Create 10 Muxed Device Connections - these should hash into different mux connections for (int i = 0; i < 10; i++) { connections[i] = (IotHubDeviceMuxConnection)connectionPool.GetConnection(i.ToString()); } for (int j = 0; j < 10; j++) { connectionPool.RemoveDeviceFromConnection(connections[j], j.ToString()); } await Task.Delay(TimeSpan.FromSeconds(6)); // Assert Assert.IsTrue(connectionPool.GetCount() == 0, "Did not cleanup all Connection objects"); }
public void DeviceScopeMuxConnection_NumberOfPoolsTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var amqpTransportSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); string connectionString = "HostName=acme.azure-devices.net;DeviceId=device1;SharedAccessKey=CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="; var iotHubConnectionString = IotHubConnectionStringBuilder.Create(connectionString).ToIotHubConnectionString(); var connectionCache = new Mock<IotHubConnectionCache>(); var connectionPool = new IotHubDeviceScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act // Create 10 Muxed Device Connections - these should hash into different mux connections for (int i = 0; i < 10; i++) { var connection = connectionPool.GetConnection(i.ToString()); } // Assert Assert.IsTrue(connectionPool.GetCount() == 10, "Did not create 10 different Connection objects"); }