Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to attain QoS is not bad #1845

Merged
merged 1 commit into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,10 @@ object MqttCodec {
extends DecodeError

/**
* Something is wrong with the subscribe ack message
* Unable to subscribe at the requested QoS
* @deprecated this message was never able to be returned - always use [[SubAck]] to test subscribed QoS, since 1.1.1
*/
@deprecated("this message was never able to be returned - always use [[SubAck]] to test subscribed QoS", "1.1.1")
final case class BadSubAckMessage(packetId: PacketId, returnCodes: Seq[ControlPacketFlags]) extends DecodeError

/**
Expand Down Expand Up @@ -1005,15 +1007,7 @@ object MqttCodec {
returnCodes
}
val returnCodes = decodeReturnCodes(l - (packetLen - v.len), Vector.empty)
val returnCodesValid = returnCodes.nonEmpty && returnCodes.foldLeft(true) {
case (true, rc) if rc.underlying < ControlPacketFlags.QoSReserved.underlying => true
case _ => false
}
if (returnCodesValid) {
Right(SubAck(packetId, returnCodes))
} else {
Left(BadSubAckMessage(packetId, returnCodes))
}
Right(SubAck(packetId, returnCodes))
} catch {
case _: NoSuchElementException => Left(BufferUnderflow)
}
Expand Down
16 changes: 3 additions & 13 deletions mqtt-streaming/src/test/scala/docs/scaladsl/MqttCodecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,13 @@ class MqttCodecSpec extends WordSpec with Matchers {
bytes.iterator.decodeControlPacket(MaxPacketSize) shouldBe Right(packet)
}

"bad sub ack message when decoding sub ack packets given failure QoS" in {
"regular sub ack message when decoding sub ack packets given failure QoS" in {
val bsb: ByteStringBuilder = ByteString.newBuilder
val packet = SubAck(PacketId(1), List(ControlPacketFlags.QoSExactlyOnceDelivery, ControlPacketFlags.QoSFailure))
val bytes = packet.encode(bsb).result()
bytes.iterator
.decodeControlPacket(MaxPacketSize) shouldBe Left(
BadSubAckMessage(PacketId(1), List(ControlPacketFlags.QoSExactlyOnceDelivery, ControlPacketFlags.QoSFailure))
)
}

"bad sub ack message when decoding sub ack packets given no topics" in {
val bsb: ByteStringBuilder = ByteString.newBuilder
val packet = SubAck(PacketId(1), List.empty)
val bytes = packet.encode(bsb).result()
bytes.iterator
.decodeControlPacket(MaxPacketSize) shouldBe Left(
BadSubAckMessage(PacketId(1), List.empty)
.decodeControlPacket(MaxPacketSize) shouldBe Right(
SubAck(PacketId(1), List(ControlPacketFlags.QoSExactlyOnceDelivery, ControlPacketFlags.QoSFailure))
)
}

Expand Down