Пример #1
0
 def test_decode_message(self):
     encoded = "\xaa\xf1\x8f[\x00\x00\x00\x00\x00\x03key\x00\x00\x00\x04test"
     offset = 10
     (returned_offset, decoded_message) = \
         list(KafkaProtocol._decode_message(encoded, offset))[0]
     self.assertEqual(returned_offset, offset)
     self.assertEqual(decoded_message, create_message("test", "key"))
Пример #2
0
 def test_decode_message(self):
     encoded = "\xaa\xf1\x8f[\x00\x00\x00\x00\x00\x03key\x00\x00\x00\x04test"
     offset = 10
     (returned_offset, decoded_message) = \
         list(KafkaProtocol._decode_message(encoded, offset))[0]
     self.assertEqual(returned_offset, offset)
     self.assertEqual(decoded_message, create_message("test", "key"))
Пример #3
0
 def test_decode_message_snappy(self):
     snappy_encoded = ('\xec\x80\xa1\x95\x00\x02\xff\xff\xff\xff\x00\x00'
                       '\x00,8\x00\x00\x19\x01@\x10L\x9f[\xc2\x00\x00\xff'
                       '\xff\xff\xff\x00\x00\x00\x02v1\x19\x1bD\x00\x10\xd5'
                       '\x96\nx\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v2')
     offset = 11
     decoded = list(KafkaProtocol._decode_message(snappy_encoded, offset))
     self.assertEqual(len(decoded), 2)
     (returned_offset1, decoded_message1) = decoded[0]
     self.assertEqual(returned_offset1, 0)
     self.assertEqual(decoded_message1, create_message("v1"))
     (returned_offset2, decoded_message2) = decoded[1]
     self.assertEqual(returned_offset2, 0)
     self.assertEqual(decoded_message2, create_message("v2"))
Пример #4
0
 def test_decode_message_snappy(self):
     snappy_encoded = ('\xec\x80\xa1\x95\x00\x02\xff\xff\xff\xff\x00\x00'
                       '\x00,8\x00\x00\x19\x01@\x10L\x9f[\xc2\x00\x00\xff'
                       '\xff\xff\xff\x00\x00\x00\x02v1\x19\x1bD\x00\x10\xd5'
                       '\x96\nx\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v2')
     offset = 11
     decoded = list(KafkaProtocol._decode_message(snappy_encoded, offset))
     self.assertEqual(len(decoded), 2)
     (returned_offset1, decoded_message1) = decoded[0]
     self.assertEqual(returned_offset1, 0)
     self.assertEqual(decoded_message1, create_message("v1"))
     (returned_offset2, decoded_message2) = decoded[1]
     self.assertEqual(returned_offset2, 0)
     self.assertEqual(decoded_message2, create_message("v2"))
Пример #5
0
    def test_decode_message(self):
        encoded = b"".join([
            struct.pack(">i", -1427009701), # CRC
            struct.pack(">bb", 0, 0),       # Magic, flags
            struct.pack(">i", 3),           # Length of key
            b"key",                         # key
            struct.pack(">i", 4),           # Length of value
            b"test",                        # value
        ])

        offset = 10
        (returned_offset, decoded_message) = list(KafkaProtocol._decode_message(encoded, offset))[0]

        self.assertEqual(returned_offset, offset)
        self.assertEqual(decoded_message, create_message(b"test", b"key"))
Пример #6
0
 def test_decode_message_gzip(self):
     gzip_encoded = ('\xc0\x11\xb2\xf0\x00\x01\xff\xff\xff\xff\x00\x00\x000'
                     '\x1f\x8b\x08\x00\xa1\xc1\xc5R\x02\xffc`\x80\x03\x01'
                     '\x9f\xf9\xd1\x87\x18\x18\xfe\x03\x01\x90\xc7Tf\xc8'
                     '\x80$wu\x1aW\x05\x92\x9c\x11\x00z\xc0h\x888\x00\x00'
                     '\x00')
     offset = 11
     decoded = list(KafkaProtocol._decode_message(gzip_encoded, offset))
     self.assertEqual(len(decoded), 2)
     (returned_offset1, decoded_message1) = decoded[0]
     self.assertEqual(returned_offset1, 0)
     self.assertEqual(decoded_message1, create_message("v1"))
     (returned_offset2, decoded_message2) = decoded[1]
     self.assertEqual(returned_offset2, 0)
     self.assertEqual(decoded_message2, create_message("v2"))
Пример #7
0
 def test_decode_message_gzip(self):
     gzip_encoded = ('\xc0\x11\xb2\xf0\x00\x01\xff\xff\xff\xff\x00\x00\x000'
                     '\x1f\x8b\x08\x00\xa1\xc1\xc5R\x02\xffc`\x80\x03\x01'
                     '\x9f\xf9\xd1\x87\x18\x18\xfe\x03\x01\x90\xc7Tf\xc8'
                     '\x80$wu\x1aW\x05\x92\x9c\x11\x00z\xc0h\x888\x00\x00'
                     '\x00')
     offset = 11
     decoded = list(KafkaProtocol._decode_message(gzip_encoded, offset))
     self.assertEqual(len(decoded), 2)
     (returned_offset1, decoded_message1) = decoded[0]
     self.assertEqual(returned_offset1, 0)
     self.assertEqual(decoded_message1, create_message("v1"))
     (returned_offset2, decoded_message2) = decoded[1]
     self.assertEqual(returned_offset2, 0)
     self.assertEqual(decoded_message2, create_message("v2"))
Пример #8
0
    def test_decode_message_snappy(self):
        snappy_encoded = (b'\xec\x80\xa1\x95\x00\x02\xff\xff\xff\xff\x00\x00'
                          b'\x00,8\x00\x00\x19\x01@\x10L\x9f[\xc2\x00\x00\xff'
                          b'\xff\xff\xff\x00\x00\x00\x02v1\x19\x1bD\x00\x10\xd5'
                          b'\x96\nx\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v2')
        offset = 11
        messages = list(KafkaProtocol._decode_message(snappy_encoded, offset))
        self.assertEqual(len(messages), 2)

        msg1, msg2 = messages

        returned_offset1, decoded_message1 = msg1
        self.assertEqual(returned_offset1, 0)
        self.assertEqual(decoded_message1, create_message(b"v1"))

        returned_offset2, decoded_message2 = msg2
        self.assertEqual(returned_offset2, 0)
        self.assertEqual(decoded_message2, create_message(b"v2"))
Пример #9
0
    def test_decode_message_gzip(self):
        gzip_encoded = (b'\xc0\x11\xb2\xf0\x00\x01\xff\xff\xff\xff\x00\x00\x000'
                        b'\x1f\x8b\x08\x00\xa1\xc1\xc5R\x02\xffc`\x80\x03\x01'
                        b'\x9f\xf9\xd1\x87\x18\x18\xfe\x03\x01\x90\xc7Tf\xc8'
                        b'\x80$wu\x1aW\x05\x92\x9c\x11\x00z\xc0h\x888\x00\x00'
                        b'\x00')
        offset = 11
        messages = list(KafkaProtocol._decode_message(gzip_encoded, offset))

        self.assertEqual(len(messages), 2)
        msg1, msg2 = messages

        returned_offset1, decoded_message1 = msg1
        self.assertEqual(returned_offset1, 0)
        self.assertEqual(decoded_message1, create_message(b"v1"))

        returned_offset2, decoded_message2 = msg2
        self.assertEqual(returned_offset2, 0)
        self.assertEqual(decoded_message2, create_message(b"v2"))
Пример #10
0
 def test_decode_message_checksum_error(self):
     invalid_encoded_message = "This is not a valid encoded message"
     iter = KafkaProtocol._decode_message(invalid_encoded_message, 0)
     self.assertRaises(ChecksumError, list, iter)
Пример #11
0
 def test_decode_message_checksum_error(self):
     invalid_encoded_message = b"This is not a valid encoded message"
     iter = KafkaProtocol._decode_message(invalid_encoded_message, 0)
     self.assertRaises(ChecksumError, list, iter)