Skip to content

Commit

Permalink
fix(iot-dev): Fix QOS not set for incoming messages from $iothub/twin…
Browse files Browse the repository at this point in the history
…/PAT… (#1747)
  • Loading branch information
dzakub authored Oct 17, 2023
1 parent 4ed458d commit b39cc38
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ else if (topic.length() > PATCH.length() && topic.startsWith(PATCH))
{
message = new IotHubTransportMessage(data, MessageType.DEVICE_TWIN);
message.setDeviceOperationType(DeviceOperations.DEVICE_OPERATION_TWIN_SUBSCRIBE_DESIRED_PROPERTIES_RESPONSE);
message.setQualityOfService(mqttMessage.getQos());
}

// Case for $iothub/twin/PATCH/properties/desired/?$version={new version}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,33 @@ public void receiveDoesNotSetVersionForDesiredPropNotifRespIfNotFound() throws T
}
}

@Test
public void receiveSetQosForDesiredProp() throws TransportException
{
final byte[] actualPayload = "NotificationResponseDataContainingDesiredPropertiesDocument".getBytes(StandardCharsets.UTF_8);
final String expectedTopic = "$iothub/twin/PATCH/properties/desired/";
IotHubTransportMessage receivedMessage = null;
int expectedQualityOfService = 2;
try
{
//arrange
Queue<Pair<String, MqttMessage>> testreceivedMessages = new ConcurrentLinkedQueue<>();
MqttMessage mqttMessage = new MqttMessage(actualPayload);
mqttMessage.setQos(expectedQualityOfService);
testreceivedMessages.add(new MutablePair<>(expectedTopic, mqttMessage));
MqttTwin testTwin = new MqttTwin("", mockedConnectOptions, new HashMap<>(), testreceivedMessages);

//act
receivedMessage = testTwin.receive();
}
finally
{
//assert
assertNotNull(receivedMessage);
assertEquals(expectedQualityOfService, receivedMessage.getQualityOfService());
}
}

/*
**Tests_SRS_MQTTDEVICETWIN_25_042: [If the topic is of type patch for desired properties then this method shall parse further to look for version which if found is set by calling setVersion]
*/
Expand Down

0 comments on commit b39cc38

Please sign in to comment.