diff --git a/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransport.java b/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransport.java index 5c6ca241fb..2599f2c6c3 100644 --- a/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransport.java +++ b/iothub/device/iot-device-client/src/main/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransport.java @@ -236,11 +236,14 @@ public boolean needsReconnect() return true; } - for (MultiplexedDeviceState multiplexedDeviceState : this.multiplexedDeviceConnectionStates.values()) + if (this.isMultiplexing) { - if (multiplexedDeviceState.getConnectionStatus() == IotHubConnectionStatus.DISCONNECTED_RETRYING) + for (MultiplexedDeviceState multiplexedDeviceState : this.multiplexedDeviceConnectionStates.values()) { - return true; + if (multiplexedDeviceState.getConnectionStatus() == IotHubConnectionStatus.DISCONNECTED_RETRYING) + { + return true; + } } } diff --git a/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransportTest.java b/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransportTest.java index 0d6498f6f9..cfc26fe836 100644 --- a/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransportTest.java +++ b/iothub/device/iot-device-client/src/test/java/com/microsoft/azure/sdk/iot/device/transport/IotHubTransportTest.java @@ -118,6 +118,50 @@ public void constructorThrowsForNullConfig() IotHubTransport transport = new IotHubTransport(null, mockedIotHubConnectionStatusChangeCallback, false); } + @Test + public void needsReconnectIgnoresDeviceSessionStateWhenNotMultiplexing() + { + //arrange + new Expectations() + { + { + mockedConfig.getDeviceId(); + result = "someDeviceId"; + } + }; + IotHubTransport transport = new IotHubTransport(mockedConfig, mockedIotHubConnectionStatusChangeCallback, false); + Map deviceConnectionStates = Deencapsulation.getField(transport, "multiplexedDeviceConnectionStates"); + deviceConnectionStates.values().iterator().next().setConnectionStatus(DISCONNECTED_RETRYING); + + //act + boolean needsReconnect = transport.needsReconnect(); + + //assert + assertFalse(needsReconnect); + } + + @Test + public void needsReconnectChecksDeviceSessionStateWhenMultiplexing() + { + //arrange + new Expectations() + { + { + mockedConfig.getDeviceId(); + result = "someDeviceId"; + } + }; + IotHubTransport transport = new IotHubTransport(mockedConfig, mockedIotHubConnectionStatusChangeCallback, true); + Map deviceConnectionStates = Deencapsulation.getField(transport, "multiplexedDeviceConnectionStates"); + deviceConnectionStates.values().iterator().next().setConnectionStatus(DISCONNECTED_RETRYING); + + //act + boolean needsReconnect = transport.needsReconnect(); + + //assert + assertTrue(needsReconnect); + } + //Tests_SRS_IOTHUBTRANSPORT_34_004: [This function shall retrieve a packet from the inProgressPackets queue with the message id from the provided message if there is one.] //Tests_SRS_IOTHUBTRANSPORT_34_006: [If there was a packet in the inProgressPackets queue tied to the provided message, and the provided throwable is a TransportException, this function shall call "handleMessageException" with the provided packet and transport exception.] @Test