mattrpav commented on code in PR #2517:
URL: https://github.com/apache/activemq/pull/2517#discussion_r3929100284
##########
activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTCodecTest.java:
##########
@@ -364,4 +364,51 @@ public void testUnmarshalInvalidRemainingLengthField() {
}
}
+ @Test
+ public void testCodecAcceptsFourByteRemainingLength() throws Exception {
+ // 2,097,152 is the smallest value that requires a 4-byte Remaining
Length.
+ // Payload size = target RL - variable header overhead (2 topic length
+ topic + 2 packet id)
+ final String topic = "TOPIC";
+ final int overhead = 2 + topic.length() + 2; // topic length field +
topic + message id (QoS 1)
+ final int payloadSize = 2_097_152 - overhead;
+
+ PUBLISH publish = new PUBLISH();
+ publish.qos(QoS.AT_LEAST_ONCE);
+ publish.messageId((short) 1);
+ publish.topicName(new UTF8Buffer(topic));
+ publish.payload(new Buffer(new byte[payloadSize]));
+
+ DataByteArrayOutputStream output = new DataByteArrayOutputStream();
+ wireFormat.marshal(publish.encode(), output);
+ Buffer marshalled = output.toBuffer();
+
+ DataByteArrayInputStream input = new
DataByteArrayInputStream(marshalled);
+ codec.parse(input, marshalled.length());
+
+ assertEquals("Expected one frame from a valid 4-byte Remaining
Length", 1, frames.size());
+ PUBLISH decoded = new PUBLISH().decode(frames.get(0));
+ assertEquals(payloadSize, decoded.payload().length());
+ }
+
+ @Test
+ public void testUnmarshalAcceptsFourByteRemainingLength() throws Exception
{
+ final String topic = "TOPIC";
+ final int overhead = 2 + topic.length() + 2;
+ final int payloadSize = 2_097_152 - overhead;
+
+ PUBLISH publish = new PUBLISH();
+ publish.qos(QoS.AT_LEAST_ONCE);
+ publish.messageId((short) 1);
+ publish.topicName(new UTF8Buffer(topic));
+ publish.payload(new Buffer(new byte[payloadSize]));
+
+ DataByteArrayOutputStream output = new DataByteArrayOutputStream();
Review Comment:
try-with-resources here
##########
activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTCodecTest.java:
##########
@@ -364,4 +364,51 @@ public void testUnmarshalInvalidRemainingLengthField() {
}
}
+ @Test
+ public void testCodecAcceptsFourByteRemainingLength() throws Exception {
+ // 2,097,152 is the smallest value that requires a 4-byte Remaining
Length.
+ // Payload size = target RL - variable header overhead (2 topic length
+ topic + 2 packet id)
+ final String topic = "TOPIC";
+ final int overhead = 2 + topic.length() + 2; // topic length field +
topic + message id (QoS 1)
+ final int payloadSize = 2_097_152 - overhead;
+
+ PUBLISH publish = new PUBLISH();
+ publish.qos(QoS.AT_LEAST_ONCE);
+ publish.messageId((short) 1);
+ publish.topicName(new UTF8Buffer(topic));
+ publish.payload(new Buffer(new byte[payloadSize]));
+
+ DataByteArrayOutputStream output = new DataByteArrayOutputStream();
+ wireFormat.marshal(publish.encode(), output);
+ Buffer marshalled = output.toBuffer();
+
+ DataByteArrayInputStream input = new
DataByteArrayInputStream(marshalled);
Review Comment:
try-with-resources here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact