예제 #1
0
파일: client_test.go 프로젝트: mezzato/gmq
func TestClient_handlePUBCOMP(t *testing.T) {
	cli := New(&Options{
		ErrorHandler: func(_ error) {},
	})

	err := cli.Connect(&ConnectOptions{
		Network:  "tcp",
		Address:  testAddress,
		ClientID: []byte("clientID"),
	})
	if err != nil {
		nilErrorExpected(t, err)
	}

	defer cli.Disconnect()

	p := &packet.PUBCOMP{
		PacketID: 1,
	}

	pubrel, err := packet.NewPUBREL(&packet.PUBRELOptions{
		PacketID: 1,
	})
	if err != nil {
		nilErrorExpected(t, err)
		return
	}

	cli.sess.sendingPackets[1] = pubrel

	if err := cli.handlePUBCOMP(p); err != nil {
		nilErrorExpected(t, err)
	}
}
예제 #2
0
파일: client_test.go 프로젝트: mezzato/gmq
func TestClient_Connect_restoreSession(t *testing.T) {
	cli := New(&Options{
		ErrorHandler: func(_ error) {},
	})

	cli.sess = newSession(false, []byte("cliendID"))

	publish, err := packet.NewPUBLISH(&packet.PUBLISHOptions{
		PacketID: 1,
	})
	if err != nil {
		nilErrorExpected(t, err)
	}

	cli.sess.sendingPackets[1] = publish

	pubrel, err := packet.NewPUBREL(&packet.PUBRELOptions{
		PacketID: 2,
	})
	if err != nil {
		nilErrorExpected(t, err)
	}

	cli.sess.sendingPackets[2] = pubrel

	cli.sess.sendingPackets[3] = packet.NewPINGREQ()

	err = cli.Connect(&ConnectOptions{
		Network: "tcp",
		Address: testAddress,
	})
	if err != nil {
		nilErrorExpected(t, err)
	}
}
예제 #3
0
파일: client.go 프로젝트: mezzato/gmq
// handlePUBREC handles the PUBREC Packet.
func (cli *Client) handlePUBREC(p packet.Packet) error {
	// Lock for update.
	cli.muSess.Lock()

	// Unlock.
	defer cli.muSess.Unlock()

	// Extract the Packet Identifier of the Packet.
	id := p.(*packet.PUBREC).PacketID

	// Validate the Packet Identifier.
	if err := cli.validatePacketID(cli.sess.sendingPackets, id, packet.TypePUBLISH); err != nil {
		return err
	}

	// Create a PUBREL Packet.
	pubrel, err := packet.NewPUBREL(&packet.PUBRELOptions{
		PacketID: id,
	})
	if err != nil {
		return err
	}

	// Set the PUBREL Packet to the Session.
	cli.sess.sendingPackets[id] = pubrel

	// Send the Packet to the Server.
	cli.conn.send <- pubrel

	return nil
}
예제 #4
0
파일: client_test.go 프로젝트: mezzato/gmq
func TestClient_handlePacket_PUBREL(t *testing.T) {
	cli := New(&Options{
		ErrorHandler: func(_ error) {},
	})

	err := cli.Connect(&ConnectOptions{
		Network:  "tcp",
		Address:  testAddress,
		ClientID: []byte("clientID"),
	})
	if err != nil {
		nilErrorExpected(t, err)
	}

	defer cli.Disconnect()

	p, err := packet.NewPUBREL(&packet.PUBRELOptions{
		PacketID: 1,
	})

	cli.handlePacket(p)
}