Пример #1
0
    def test_decode_message_set(self):
        encoded = b"".join([
            struct.pack(">q", 0),          # MsgSet Offset
            struct.pack(">i", 18),         # Msg Size
            struct.pack(">i", 1474775406), # CRC
            struct.pack(">bb", 0, 0),      # Magic, flags
            struct.pack(">i", 2),          # Length of key
            b"k1",                         # Key
            struct.pack(">i", 2),          # Length of value
            b"v1",                         # Value

            struct.pack(">q", 1),          # MsgSet Offset
            struct.pack(">i", 18),         # Msg Size
            struct.pack(">i", -16383415),  # CRC
            struct.pack(">bb", 0, 0),      # Magic, flags
            struct.pack(">i", 2),          # Length of key
            b"k2",                         # Key
            struct.pack(">i", 2),          # Length of value
            b"v2",                         # Value
        ])

        msgs = list(KafkaProtocol._decode_message_set_iter(encoded))
        self.assertEqual(len(msgs), 2)
        msg1, msg2 = msgs

        returned_offset1, decoded_message1 = msg1
        returned_offset2, decoded_message2 = msg2

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

        self.assertEqual(returned_offset2, 1)
        self.assertEqual(decoded_message2, create_message(b"v2", b"k2"))
Пример #2
0
    def test_decode_message_set_stop_iteration(self):
        encoded = "".join([
            struct.pack(">q", 0),  # MsgSet Offset
            struct.pack(">i", 18),  # Msg Size
            struct.pack(">i", 1474775406),  # CRC
            struct.pack(">bb", 0, 0),  # Magic, flags
            struct.pack(">i", 2),  # Length of key
            "k1",  # Key
            struct.pack(">i", 2),  # Length of value
            "v1",  # Value
            struct.pack(">q", 1),  # MsgSet Offset
            struct.pack(">i", 18),  # Msg Size
            struct.pack(">i", -16383415),  # CRC
            struct.pack(">bb", 0, 0),  # Magic, flags
            struct.pack(">i", 2),  # Length of key
            "k2",  # Key
            struct.pack(">i", 2),  # Length of value
            "v2",  # Value
            "@1$%(Y!",  # Random padding
        ])

        msgs = list(KafkaProtocol._decode_message_set_iter(encoded))
        self.assertEqual(len(msgs), 2)
        msg1, msg2 = msgs

        returned_offset1, decoded_message1 = msg1
        returned_offset2, decoded_message2 = msg2

        self.assertEqual(returned_offset1, 0)
        self.assertEqual(decoded_message1, create_message("v1", "k1"))

        self.assertEqual(returned_offset2, 1)
        self.assertEqual(decoded_message2, create_message("v2", "k2"))
Пример #3
0
 def test_decode_message_set_stop_iteration(self):
     encoded = ('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10L\x9f[\xc2'
                '\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v1\x00\x00\x00\x00'
                '\x00\x00\x00\x00\x00\x00\x00\x10\xd5\x96\nx\x00\x00\xff'
                '\xff\xff\xff\x00\x00\x00\x02v2')
     iter = KafkaProtocol._decode_message_set_iter(encoded + "@#$%(Y!")
     decoded = list(iter)
     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_set_stop_iteration(self):
     encoded = ('\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10L\x9f[\xc2'
                '\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v1\x00\x00\x00\x00'
                '\x00\x00\x00\x00\x00\x00\x00\x10\xd5\x96\nx\x00\x00\xff'
                '\xff\xff\xff\x00\x00\x00\x02v2')
     iter = KafkaProtocol._decode_message_set_iter(encoded + "@#$%(Y!")
     decoded = list(iter)
     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_set(self):
     encoded = (
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10L\x9f[\xc2"
         "\x00\x00\xff\xff\xff\xff\x00\x00\x00\x02v1\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x10\xd5\x96\nx\x00\x00\xff"
         "\xff\xff\xff\x00\x00\x00\x02v2"
     )
     iter = KafkaProtocol._decode_message_set_iter(encoded)
     decoded = list(iter)
     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"))
Пример #6
0
 def test_decode_message_set_fetch_size_too_small(self):
     with self.assertRaises(ConsumerFetchSizeTooSmall):
         list(KafkaProtocol._decode_message_set_iter('a'))
Пример #7
0
 def test_decode_message_set_fetch_size_too_small(self):
     with self.assertRaises(ConsumerFetchSizeTooSmall):
         list(KafkaProtocol._decode_message_set_iter('a'))
Пример #8
0
 def test_decode_message_set_fetch_size_too_small(self):
     iter = KafkaProtocol._decode_message_set_iter('a')
     self.assertRaises(ConsumerFetchSizeTooSmall, list, iter)
Пример #9
0
 def test_decode_message_set_fetch_size_too_small(self):
     iter = KafkaProtocol._decode_message_set_iter('a')
     self.assertRaises(ConsumerFetchSizeTooSmall, list, iter)