Beispiel #1
0
 def test_publish_single_qos1(self):
     self._connect()
     d = self.protocol.publish(topic="foo/bar/baz1", qos=1, message="hello world 1")
     self.assertEqual(len(self.protocol.factory.queuePublishTx),  1)
     self.transport.clear()
     ack = PUBACK()
     ack.msgId = d.msgId
     self.protocol.dataReceived(ack.encode())
     self.assertEqual(len(self.protocol.factory.queuePublishTx),  0)
     self.assertEqual(ack.msgId, self.successResultOf(d))
Beispiel #2
0
 def _puback(self, dl):
     ackl = []
     for i in range(0, len(dl)):
         ack= PUBACK()
         ack.msgId = dl[i].msgId
         ackl.append(ack)
     encoded = bytearray()
     for ack in ackl:
         encoded.extend(ack.encode())
     self.protocol.dataReceived(encoded)
     self.transport.clear()
     for i in range(0, len(dl)):
         self.assertEqual(dl[i].msgId, self.successResultOf(dl[i]))
 def _puback(self, dl):
     ackl = []
     for i in range(0, len(dl)):
         ack = PUBACK()
         ack.msgId = dl[i].msgId
         ackl.append(ack)
     encoded = bytearray()
     for ack in ackl:
         encoded.extend(ack.encode())
     self.protocol.dataReceived(encoded)
     self.transport.clear()
     for i in range(0, len(dl)):
         self.assertEqual(dl[i].msgId, self.successResultOf(dl[i]))
Beispiel #4
0
    def test_PUBACK_encdec(self):
        request = PUBACK()
        response = PUBACK()
        request.msgId = 65535

        response.decode(request.encode())
        self.assertEqual(request.msgId, response.msgId)
    def test_publish_very_large_qos1(self):
        message = '0123456789ABCDEF' * 1000000  # Large PDU
        self._connect()

        # Test at 1MByte/sec
        self.protocol.setBandwith(1000000.0)
        d = self.protocol.publish(topic="foo/bar/baz1", qos=1, message=message)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][1].dup,
                         False)
        self.transport.clear()
        self.clock.advance(10)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][1].dup,
                         False)
        ack = PUBACK()
        ack.msgId = d.msgId
        self.protocol.dataReceived(ack.encode())
        self.transport.clear()
        self.assertEqual(ack.msgId, self.successResultOf(d))

        # A large PDU with a large bandwith estimation may retransmit
        self.protocol.setBandwith(10000000.0)
        d = self.protocol.publish(topic="foo/bar/baz1", qos=1, message=message)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][2].dup,
                         False)
        self.transport.clear()
        self.clock.advance(10)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][2].dup,
                         True)
        ack = PUBACK()
        ack.msgId = d.msgId
        self.protocol.dataReceived(ack.encode())
        self.transport.clear()
        self.assertEqual(ack.msgId, self.successResultOf(d))
 def test_publish_single_qos1(self):
     self._connect()
     d = self.protocol.publish(topic="foo/bar/baz1",
                               qos=1,
                               message="hello world 1")
     self.assertEqual(len(self.protocol.factory.windowPublish[self.addr]),
                      1)
     self.transport.clear()
     ack = PUBACK()
     ack.msgId = d.msgId
     self.protocol.dataReceived(ack.encode())
     self.assertEqual(len(self.protocol.factory.windowPublish[self.addr]),
                      0)
     self.assertEqual(ack.msgId, self.successResultOf(d))
Beispiel #7
0
 def test_PUBACK_encdec(self):
     request  = PUBACK()
     response = PUBACK()
     request.msgId = 65535
     
     response.decode(request.encode())
     self.assertEqual(request.msgId, response.msgId)
    def test_publish_very_large_qos1(self):
        message = '0123456789ABCDEF'*1000000 # Large PDU
        self._connect()

        # Test at 1MByte/sec
        self.protocol.setBandwith(1000000.0)
        d = self.protocol.publish(topic="foo/bar/baz1", qos=1, message=message)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][1].dup, False)
        self.transport.clear()
        self.clock.advance(10)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][1].dup, False)
        ack = PUBACK()
        ack.msgId = d.msgId
        self.protocol.dataReceived(ack.encode())
        self.transport.clear()
        self.assertEqual(ack.msgId, self.successResultOf(d))

        # A large PDU with a large bandwith estimation may retransmit
        self.protocol.setBandwith(10000000.0)
        d = self.protocol.publish(topic="foo/bar/baz1", qos=1, message=message)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][2].dup, False)
        self.transport.clear()
        self.clock.advance(10)
        self.assertEqual(self.protocol.factory.windowPublish[self.addr][2].dup, True)
        ack = PUBACK()
        ack.msgId = d.msgId
        self.protocol.dataReceived(ack.encode())
        self.transport.clear()
        self.assertEqual(ack.msgId, self.successResultOf(d))
Beispiel #9
0
 def test_PUBREC_enc_fail2(self):
     request  = PUBACK()
     response = PUBACK()
     request.msgId = 2000000
     self.assertRaises(ValueError, request.encode)
Beispiel #10
0
 def test_PUBREC_enc_fail2(self):
     request = PUBACK()
     response = PUBACK()
     request.msgId = 2000000
     self.assertRaises(ValueError, request.encode)