File tree Expand file tree Collapse file tree 4 files changed +34
-26
lines changed
main/java/com/ss/mqtt/broker/network/packet/out
test/groovy/com/ss/mqtt/broker/test Expand file tree Collapse file tree 4 files changed +34
-26
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,20 @@ public class Connect311OutPacket extends MqttWritablePacket {
3232 private final boolean willRetain ;
3333 private final boolean cleanStart ;
3434
35+ public Connect311OutPacket (@ NotNull String clientId , int keepAlive ) {
36+ this (
37+ StringUtils .EMPTY ,
38+ StringUtils .EMPTY ,
39+ clientId ,
40+ ArrayUtils .EMPTY_BYTE_ARRAY ,
41+ ArrayUtils .EMPTY_BYTE_ARRAY ,
42+ QoS .AT_MOST_ONCE_DELIVERY ,
43+ keepAlive ,
44+ false ,
45+ false
46+ );
47+ }
48+
3549 protected @ NotNull MqttVersion getMqttVersion () {
3650 return MqttVersion .MQTT_3_1_1 ;
3751 }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class IntegrationSpecification extends Specification {
1919 public static final topicFilter = " topic/Filter"
2020 public static final publishPayload = " publishPayload" . getBytes(encoding)
2121 public static final clientId = " testClientId"
22+ public static final keepAlive = 120
2223
2324 @Autowired
2425 InetSocketAddress deviceNetworkAddress
@@ -33,9 +34,9 @@ class IntegrationSpecification extends Specification {
3334 MqttConnection mqtt311MockedConnection
3435
3536 def buildClient () {
36- return buildClient(UUID . randomUUID() . toString ())
37+ return buildClient(generateClientId ())
3738 }
38-
39+
3940 def buildClient (String clientId ) {
4041 return MqttClient . builder()
4142 .identifier(clientId)
@@ -45,8 +46,12 @@ class IntegrationSpecification extends Specification {
4546 .build()
4647 .toAsync()
4748 }
48-
49- def static connectWith (Mqtt5AsyncClient client , String user , String pass ) {
49+
50+ def generateClientId () {
51+ UUID . randomUUID(). toString()
52+ }
53+
54+ def connectWith (Mqtt5AsyncClient client , String user , String pass ) {
5055 return client. connectWith()
5156 .simpleAuth()
5257 .username(user)
Original file line number Diff line number Diff line change 11package com.ss.mqtt.broker.test.integration
22
3- import com.ss.mqtt.broker.model.MqttSession
4- import com.ss.mqtt.broker.network.client.MqttClient
5- import com.ss.mqtt.broker.network.packet.in.PublishInPacket
6- import com.ss.mqtt.broker.network.packet.out.ConnectAck5OutPacket
3+ import com.ss.mqtt.broker.network.packet.in.ConnectAckInPacket
4+ import com.ss.mqtt.broker.network.packet.out.Connect311OutPacket
75import com.ss.mqtt.broker.service.MqttSessionService
86import org.springframework.beans.factory.annotation.Autowired
97
10- import java.util.concurrent.atomic.AtomicInteger
11-
128class PublishRetryTest extends IntegrationSpecification {
139
1410 @Autowired
1511 MqttSessionService mqttSessionService
1612
17- /* def "mqtt5 client should be generate session with one pending packet"() {
13+ def " mqtt5 client should be generate session with one pending packet" () {
1814 given :
19- def client = buildMqtt5MockClient()
15+ def client = buildMqtt311MockClient()
16+ def clientId = generateClientId()
2017 when :
2118 client. connect()
22- client.send(new ConnectAck5OutPacket(
23-
24- ))
25- then:
26- noExceptionThrown()
27- publishRetryService.exist(identifier.get().toString())
28- when:
29- client.disconnect().join()
30- Thread.sleep(500)
19+ client. send(new Connect311OutPacket (clientId, keepAlive))
3120 then :
32- noExceptionThrown()
33- !publishRetryService.exist(identifier.get().toString())
34- }*/
21+ client. readNext() instanceof ConnectAckInPacket
22+ }
3523}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.ss.mqtt.broker.test.mock
22
33import com.ss.mqtt.broker.network.MqttConnection
44import com.ss.mqtt.broker.network.packet.PacketType
5+ import com.ss.mqtt.broker.network.packet.in.ConnectAckInPacket
56import com.ss.mqtt.broker.network.packet.in.ConnectInPacket
67import com.ss.mqtt.broker.network.packet.in.MqttReadablePacket
78import com.ss.mqtt.broker.network.packet.out.MqttWritablePacket
@@ -72,8 +73,8 @@ class MqttMockClient {
7273 MqttReadablePacket packet
7374
7475 switch (PacketType . fromByte(type)) {
75- case PacketType . CONNECT :
76- packet = new ConnectInPacket (info)
76+ case PacketType . CONNECT_ACK :
77+ packet = new ConnectAckInPacket (info)
7778 break
7879 default :
7980 throw new IllegalStateException (" Unknown packet of type: $type " )
You can’t perform that action at this time.
0 commit comments