Implemented MQTT QoS 1

This commit is contained in:
Ziver Koc 2025-12-24 03:01:50 +01:00
parent f31f850644
commit c4f7823ba3
2 changed files with 56 additions and 8 deletions

View file

@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Ziver Koc
* Copyright (c) 2020-2025 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -388,6 +388,32 @@ public class MqttBrokerTest {
assertEquals( null, subscriber2.receivedPayload);
}
@Test
public void publishQoS1() throws IOException {
// Setup broker
MqttBroker broker = new MqttBroker();
MqttConnectionThreadMock thread = new MqttConnectionThreadMock(broker);
MqttSubscriptionListenerMock subscriber = new MqttSubscriptionListenerMock();
broker.subscribe("test/topic", subscriber);
// Setup publish
MqttPacketPublish publish = new MqttPacketPublish();
publish.topicName = "test/topic";
publish.setFlagQoS(1);
publish.packetId = 33;
publish.payload = new byte[]{42};
thread.handlePacket(publish);
// Check response
assertEquals(1, thread.sentPackets.size());
MqttPacketPublishAck ackPacket = (MqttPacketPublishAck) thread.sentPackets.get(0);
assertEquals(33, ackPacket.packetId);
assertEquals("test/topic", subscriber.receivedTopic);
assertEquals((byte) 42, subscriber.receivedPayload[0]);
}
@Test
public void publishBadQos() throws IOException {
// Setup broker