public void TransportSettingsTest_TransportType_Amqp_WebSocket_Tcp() { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var transportSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); Assert.IsTrue(transportSetting.GetTransportType() == TransportType.Amqp_Tcp_Only, "Should be TransportType.Amqp_Tcp_Only"); Assert.IsTrue(transportSetting.PrefetchCount == 200, "Should be value of 200"); }
public IotHubSingleTokenConnection(IotHubScopeConnectionPool iotHubScopeConnectionPool, IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSettings) :base(connectionString.HostName, connectionString.AmqpEndpoint.Port, amqpTransportSettings) { this.iotHubScopeConnectionPool = iotHubScopeConnectionPool; this.ConnectionString = connectionString; this.FaultTolerantSession = new FaultTolerantAmqpObject<AmqpSession>(this.CreateSessionAsync, this.CloseConnection); }
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 IotHubConnection(IotHubConnectionString connectionString, AccessRights accessRights, AmqpTransportSettings amqpTransportSettings) { this.connectionString = connectionString; this.accessRights = accessRights; this.faultTolerantSession = new FaultTolerantAmqpObject <AmqpSession>(this.CreateSessionAsync, this.CloseConnection); this.refreshTokenTimer = new IOThreadTimer(s => ((IotHubConnection)s).OnRefreshToken(), this, false); this.amqpTransportSettings = amqpTransportSettings; }
public IotHubConnection(IotHubConnectionString connectionString, AccessRights accessRights, AmqpTransportSettings amqpTransportSettings) { this.connectionString = connectionString; this.accessRights = accessRights; this.faultTolerantSession = new FaultTolerantAmqpObject<AmqpSession>(this.CreateSessionAsync, this.CloseConnection); this.refreshTokenTimer = new IOThreadTimer(s => ((IotHubConnection)s).OnRefreshToken(), this, false); this.amqpTransportSettings = amqpTransportSettings; }
public AmqpDeviceClient(IotHubConnectionString connectionString, AmqpTransportSettings transportSettings) { this.IotHubConnection = connectionCache.GetConnection(connectionString, transportSettings); this.deviceId = connectionString.DeviceId; this.openTimeout = IotHubConnection.DefaultOpenTimeout; this.operationTimeout = IotHubConnection.DefaultOperationTimeout; this.DefaultReceiveTimeout = IotHubConnection.DefaultOperationTimeout; this.faultTolerantEventSendingLink = new FaultTolerantAmqpObject<SendingAmqpLink>(this.CreateEventSendingLinkAsync, this.IotHubConnection.CloseLink); this.faultTolerantDeviceBoundReceivingLink = new FaultTolerantAmqpObject<ReceivingAmqpLink>(this.CreateDeviceBoundReceivingLinkAsync, this.IotHubConnection.CloseLink); this.prefetchCount = transportSettings.PrefetchCount; }
public AmqpDeviceClient(IotHubConnectionString connectionString, AmqpTransportSettings transportSettings) { this.IotHubConnection = connectionCache.GetConnection(connectionString, transportSettings); this.deviceId = connectionString.DeviceId; this.openTimeout = IotHubConnection.DefaultOpenTimeout; this.operationTimeout = IotHubConnection.DefaultOperationTimeout; this.DefaultReceiveTimeout = IotHubConnection.DefaultOperationTimeout; this.faultTolerantEventSendingLink = new FaultTolerantAmqpObject <SendingAmqpLink>(this.CreateEventSendingLinkAsync, this.IotHubConnection.CloseLink); this.faultTolerantDeviceBoundReceivingLink = new FaultTolerantAmqpObject <ReceivingAmqpLink>(this.CreateDeviceBoundReceivingLinkAsync, this.IotHubConnection.CloseLink); this.prefetchCount = transportSettings.PrefetchCount; }
public IotHubDeviceScopeConnectionPool(IotHubConnectionCache cache, IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSettings) { this.cache = cache; this.connectionString = connectionString; this.amqpTransportSettings = amqpTransportSettings; this.connectionPool = new Dictionary <long, Tuple <IotHubDeviceMuxConnection, uint> >(); #if WINDOWS_UWP this.idleTimers = new Dictionary <IotHubDeviceMuxConnection, IOThreadTimerSlim>(); #else this.idleTimers = new Dictionary <IotHubDeviceMuxConnection, IOThreadTimer>(); #endif this.idleTimeout = amqpTransportSettings.AmqpConnectionPoolSettings.ConnectionIdleTimeout; this.thisLock = new object(); }
public bool Equals(AmqpTransportSettings other) { if (other == null) { return(false); } if (object.ReferenceEquals(this, other)) { return(true); } // ClientCertificates are usually different return(this.PrefetchCount == other.PrefetchCount && this.OpenTimeout == other.OpenTimeout && this.OperationTimeout == other.OperationTimeout && this.AmqpConnectionPoolSettings.Equals(other.AmqpConnectionPoolSettings)); }
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_PoolingOffReleaseTest() { // Arrange var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); amqpConnectionPoolSettings.Pooling = false; 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>(); // Pooling is off - pass null for ConnectionPoolCache var iotHubConnection = new IotHubDeviceMuxConnection(null, 1, iotHubConnectionString, amqpTransportSettings); connectionCache.Setup(cache => cache.GetConnection(It.IsAny<IotHubConnectionString>(), It.IsAny<AmqpTransportSettings>())).Returns(iotHubConnection); // Act var connection = connectionCache.Object.GetConnection(iotHubConnectionString, amqpTransportSettings); connection.Release("device"); // does not match "device1" above, However pooling is off. Thus, this iothubconnection object is closed // Success }
public static async Task<IMessagingServiceClient> CreateFromConnectionStringAsync(string deviceId, string connectionString, int connectionPoolSize, TimeSpan? connectionIdleTimeout, IotHubClientSettings settings, IByteBufferAllocator allocator, IMessageAddressConverter messageAddressConverter) { int maxPendingOutboundMessages = settings.MaxPendingOutboundMessages; var tcpSettings = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only); var webSocketSettings = new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only); webSocketSettings.PrefetchCount = tcpSettings.PrefetchCount = (uint)maxPendingOutboundMessages; if (connectionPoolSize > 0) { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings { MaxPoolSize = unchecked ((uint)connectionPoolSize), Pooling = connectionPoolSize > 0 }; if (connectionIdleTimeout.HasValue) { amqpConnectionPoolSettings.ConnectionIdleTimeout = connectionIdleTimeout.Value; } tcpSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; webSocketSettings.AmqpConnectionPoolSettings = amqpConnectionPoolSettings; } DeviceClient client = DeviceClient.CreateFromConnectionString(connectionString, new ITransportSettings[] { tcpSettings, webSocketSettings }); try { await client.OpenAsync(); } catch (IotHubException ex) { throw ComposeIotHubCommunicationException(ex); } return new IotHubClient(client, deviceId, settings, allocator, messageAddressConverter); }
public void TransportSettingsTest_TransportType_Amqp() { var transportSetting = new AmqpTransportSettings(TransportType.Amqp); }
public void ConnectionPoolSettingsTest_PoolingOff() { var connectionPoolSettings = new AmqpConnectionPoolSettings(); connectionPoolSettings.Pooling = false; var transportSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, connectionPoolSettings); Assert.IsTrue(transportSetting.AmqpConnectionPoolSettings.Pooling == false, "Pooling should be off"); }
public void ConnectionPoolSettingsTest_MaxPoolSizeTest() { var connectionPoolSettings = new AmqpConnectionPoolSettings(); connectionPoolSettings.MaxPoolSize = ushort.MaxValue; var transportSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, connectionPoolSettings); Assert.IsTrue(transportSetting.AmqpConnectionPoolSettings.MaxPoolSize == ushort.MaxValue, "MaxPoolSize should be 64K"); }
// Making this virtual to allow Moq to override public virtual IotHubConnection GetConnection(IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSetting) { // Only the initial transportSetting is used, subsequent ones are ignored if (this.amqpTransportSettings == null) { Interlocked.CompareExchange(ref this.amqpTransportSettings, amqpTransportSetting, null); } else { // Client certificate is per device and must be overriden this.amqpTransportSettings.ClientCertificate = amqpTransportSetting.ClientCertificate; } // Uncomment when we rev the ApiVersion since this is a breaking change //if (!this.amqpTransportSettings.Equals(amqpTransportSetting)) //{ // throw new ArgumentException("AmqpTransportSettings cannot be modified from the initial settings."); //} IotHubConnection iotHubConnection; if (connectionString.SharedAccessKeyName != null || connectionString.SharedAccessSignature != null) { // Connections are not pooled when SAS signatures are used. However, we still use a connection pool object // Connections are not shared since the SAS signature will not match another connection string IotHubScopeConnectionPool iotHubScopeConnectionPool; do { iotHubScopeConnectionPool = this.hubScopeConnectionPools.GetOrAdd( connectionString, k => new IotHubScopeConnectionPool(this, k, this.amqpTransportSettings) ); }while (!iotHubScopeConnectionPool.TryAddRef()); iotHubConnection = iotHubScopeConnectionPool.Connection; } else if (this.amqpTransportSettings.AmqpConnectionPoolSettings.Pooling) { // use connection pooling for device scope connection string do { IotHubDeviceScopeConnectionPool iotHubDeviceScopeConnectionPool = this.deviceScopeConnectionPools.GetOrAdd( connectionString, k => new IotHubDeviceScopeConnectionPool(this, k, this.amqpTransportSettings) ); iotHubConnection = iotHubDeviceScopeConnectionPool.GetConnection(connectionString.DeviceId); }while (iotHubConnection == null); } else { // Connection pooling is turned off for device-scope connection strings iotHubConnection = new IotHubSingleTokenConnection(null, connectionString, this.amqpTransportSettings); } return(iotHubConnection); }
public IotHubScopeConnectionPool(IotHubConnectionCache cache, IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSettings) { Fx.Assert(cache != null, "IotHubConnectionCache reference is null"); this.cache = cache; this.ConnectionString = connectionString; this.Connection = new IotHubSingleTokenConnection(this, connectionString, amqpTransportSettings); this.thisLock = new object(); #if WINDOWS_UWP || PCL || NETSTANDARD1_3 this.idleTimer = new IOThreadTimerSlim(s => ((IotHubScopeConnectionPool)s).IdleTimerCallback(), this, false); #else this.idleTimer = new IOThreadTimer(s => ((IotHubScopeConnectionPool)s).IdleTimerCallback(), this, false); #endif this.idleTimeout = amqpTransportSettings.AmqpConnectionPoolSettings.ConnectionIdleTimeout; this.idleTimer.Set(this.idleTimeout); }
public void TransportSettingsTest_TransportType_AmqpTcp_Prefetch_0() { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var transportSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 0, amqpConnectionPoolSettings); }
protected IotHubConnection(string hostName, int port, AmqpTransportSettings amqpTransportSettings) { this.hostName = hostName; this.port = port; this.AmqpTransportSettings = amqpTransportSettings; }
public IotHubConnection GetConnection(IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSettings) { if (connectionString.SharedAccessKeyName != null) { // Use connection caching CachedConnection cachedConnection; do { cachedConnection = this.connections.GetOrAdd(connectionString, k => new CachedConnection(this, new IotHubConnection(k, this.accessRights, amqpTransportSettings))); }while (!cachedConnection.TryAddRef()); return(cachedConnection.Connection); } return(new IotHubConnection(connectionString, this.accessRights, amqpTransportSettings)); }
public void TransportSettingsTest_TransportType_AmqpTcp_Prefetch_0() { var transportSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 0); }
public void X509Certificate_MutipleClientAuthMechanism() { string hostName = "acme.azure-devices.net"; var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var transportSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 200, amqpConnectionPoolSettings); var authMethod1 = new DeviceAuthenticationWithRegistrySymmetricKey("device1", "CQN2K33r45/0WeIjpqmErV5EIvX8JZrozt3NEHCEkG8="); var deviceClient = DeviceClient.Create(hostName, authMethod1, new ITransportSettings[] { transportSetting }); var cert = CertificateHelper.InstallCertificateFromFile(LocalCertFilename, LocalCertPasswordFile); var authMethod2 = new DeviceAuthenticationWithX509Certificate("device2", cert); var device2Client = DeviceClient.Create(hostName, authMethod2, new ITransportSettings[] { new AmqpTransportSettings(TransportType.Amqp_Tcp_Only, 100) }); }
public void TransportSettingsTest_TransportType_Amqp_Http() { var transportSetting = new AmqpTransportSettings(TransportType.Http1); }
public async Task HubScopeMuxConnection_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>(); connectionCache.Setup(cache => cache.RemoveHubScopeConnectionPool(It.IsAny<IotHubConnectionString>())).Returns(true); var hubscopeConnectionPool = new IotHubScopeConnectionPool(connectionCache.Object, iotHubConnectionString, amqpTransportSettings); // Act for (int i = 0; i < 10; i++) { hubscopeConnectionPool.TryAddRef(); } // Assert Assert.IsTrue(hubscopeConnectionPool.GetCount() == 10, "Reference count should be ten"); for (int i = 0; i < 10; i++) { hubscopeConnectionPool.RemoveRef(); } // Assert Assert.IsTrue(hubscopeConnectionPool.GetCount() == 0, "Reference count should be zero"); await Task.Delay(TimeSpan.FromSeconds(6)); // Hacky way to verify that the SingleTokenConnection object has been closed. var singleConnection = (IotHubSingleTokenConnection)hubscopeConnectionPool.Connection; await singleConnection.CreateSendingLinkAsync("test", iotHubConnectionString, TimeSpan.FromMinutes(2)); }
public void TransportSettingsTest_TransportType_Amqp_WebSocket() { var transportSetting = new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only); Assert.IsTrue(transportSetting.GetTransportType() == TransportType.Amqp_WebSocket_Only, "Should be TransportType.Amqp_WebSocket_Only"); Assert.IsTrue(transportSetting.PrefetchCount == 50, "Should be default value of 50"); }
// Making this virtual to allow Moq to override public virtual IotHubConnection GetConnection(IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSetting) { // Only the initial transportSetting is used, subsequent ones are ignored if (this.amqpTransportSettings == null) { Interlocked.CompareExchange(ref this.amqpTransportSettings, amqpTransportSetting, null); } else { #if !WINDOWS_UWP && !PCL // Client certificate is per device and must be overriden this.amqpTransportSettings.ClientCertificate = amqpTransportSetting.ClientCertificate; #endif } IotHubConnection iotHubConnection; if (connectionString.SharedAccessKeyName != null || connectionString.SharedAccessSignature != null) { // Connections are not pooled when SAS signatures are used. However, we still use a connection pool object // Connections are not shared since the SAS signature will not match another connection string IotHubScopeConnectionPool iotHubScopeConnectionPool; do { iotHubScopeConnectionPool = this.hubScopeConnectionPools.GetOrAdd( connectionString, k => new IotHubScopeConnectionPool(this, k, this.amqpTransportSettings) ); }while (!iotHubScopeConnectionPool.TryAddRef()); iotHubConnection = iotHubScopeConnectionPool.Connection; } else if (this.amqpTransportSettings.AmqpConnectionPoolSettings.Pooling) { // use connection pooling for device scope connection string do { IotHubDeviceScopeConnectionPool iotHubDeviceScopeConnectionPool = this.deviceScopeConnectionPools.GetOrAdd( connectionString, k => new IotHubDeviceScopeConnectionPool(this, k, this.amqpTransportSettings) ); iotHubConnection = iotHubDeviceScopeConnectionPool.GetConnection(connectionString.DeviceId); }while (iotHubConnection == null); } else { // Connection pooling is turned off for device-scope connection strings iotHubConnection = new IotHubSingleTokenConnection(null, connectionString, this.amqpTransportSettings); } return(iotHubConnection); }
public void TransportSettingsTest_ZeroOpenTimeout() { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var transportSetting = new AmqpTransportSettings(TransportType.Amqp, 200, amqpConnectionPoolSettings); transportSetting.OpenTimeout = TimeSpan.Zero; }
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_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 void TransportSettingsTest_Timeouts() { var amqpConnectionPoolSettings = new AmqpConnectionPoolSettings(); var transportSetting = new AmqpTransportSettings(TransportType.Amqp_WebSocket_Only, 200, amqpConnectionPoolSettings); transportSetting.OpenTimeout = TimeSpan.FromMinutes(5); transportSetting.OperationTimeout = TimeSpan.FromMinutes(10); Assert.IsTrue(transportSetting.OpenTimeout == TimeSpan.FromMinutes(5), "OpenTimeout not set correctly"); Assert.IsTrue(transportSetting.OperationTimeout == TimeSpan.FromMinutes(10), "OperationTimeout not set correctly"); }
public void ConnectionPoolSettingsTest_ZeroPoolSize() { var connectionPoolSettings = new AmqpConnectionPoolSettings(); connectionPoolSettings.MaxPoolSize = 0; var transportSetting = new AmqpTransportSettings(TransportType.Amqp, 200, connectionPoolSettings); }
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 ConnectionPoolSettingsTest_4SecsIdleTimeout() { var connectionPoolSettings = new AmqpConnectionPoolSettings(); connectionPoolSettings.ConnectionIdleTimeout = TimeSpan.FromSeconds(4); var transportSetting = new AmqpTransportSettings(TransportType.Amqp, 200, connectionPoolSettings); }
public IotHubSingleTokenConnection(IotHubScopeConnectionPool iotHubScopeConnectionPool, IotHubConnectionString connectionString, AmqpTransportSettings amqpTransportSettings) : base(connectionString.HostName, connectionString.AmqpEndpoint.Port, amqpTransportSettings) { this.iotHubScopeConnectionPool = iotHubScopeConnectionPool; this.ConnectionString = connectionString; this.FaultTolerantSession = new FaultTolerantAmqpObject <AmqpSession>(this.CreateSessionAsync, this.CloseConnection); }
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"); }