Ejemplo n.º 1
0
 def test_encode_fetch_request(self):
     requests = [FetchRequest("topic1", 0, 10, 1024),
                 FetchRequest("topic2", 1, 20, 100)]
     expect = ('\x00\x00\x00Y\x00\x01\x00\x00\x00\x00\x00\x03\x00\x07'
               'client1\xff\xff\xff\xff\x00\x00\x00\x02\x00\x00\x00d\x00'
               '\x00\x00\x02\x00\x06topic1\x00\x00\x00\x01\x00\x00\x00\x00'
               '\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x04\x00\x00\x06'
               'topic2\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00'
               '\x00\x00\x14\x00\x00\x00d')
     encoded = KafkaProtocol.encode_fetch_request("client1", 3, requests, 2,
                                                  100)
     self.assertEqual(encoded, expect)
Ejemplo n.º 2
0
 def test_encode_fetch_request(self):
     requests = [
         FetchRequest("topic1", 0, 10, 1024),
         FetchRequest("topic2", 1, 20, 100)
     ]
     expect = ('\x00\x00\x00Y\x00\x01\x00\x00\x00\x00\x00\x03\x00\x07'
               'client1\xff\xff\xff\xff\x00\x00\x00\x02\x00\x00\x00d\x00'
               '\x00\x00\x02\x00\x06topic1\x00\x00\x00\x01\x00\x00\x00\x00'
               '\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x04\x00\x00\x06'
               'topic2\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00'
               '\x00\x00\x14\x00\x00\x00d')
     encoded = KafkaProtocol.encode_fetch_request("client1", 3, requests, 2,
                                                  100)
     self.assertEqual(encoded, expect)
Ejemplo n.º 3
0
    def test_encode_fetch_request(self):
        requests = [
            FetchRequest("topic1", 0, 10, 1024),
            FetchRequest("topic2", 1, 20, 100),
        ]

        header = "".join([
            struct.pack('>i', 89),  # The length of the message overall
            struct.pack('>h', 1),  # Msg Header, Message type = Fetch
            struct.pack('>h', 0),  # Msg Header, API version
            struct.pack('>i', 3),  # Msg Header, Correlation ID
            struct.pack('>h7s', 7, "client1"),  # Msg Header, The client ID
            struct.pack('>i', -1),  # Replica Id
            struct.pack('>i', 2),  # Max wait time
            struct.pack('>i', 100),  # Min bytes
            struct.pack('>i', 2),  # Num requests
        ])

        topic1 = "".join([
            struct.pack('>h6s', 6, 'topic1'),  # Topic
            struct.pack('>i', 1),  # Num Payloads
            struct.pack('>i', 0),  # Partition 0
            struct.pack('>q', 10),  # Offset
            struct.pack('>i', 1024),  # Max Bytes
        ])

        topic2 = "".join([
            struct.pack('>h6s', 6, 'topic2'),  # Topic
            struct.pack('>i', 1),  # Num Payloads
            struct.pack('>i', 1),  # Partition 0
            struct.pack('>q', 20),  # Offset
            struct.pack('>i', 100),  # Max Bytes
        ])

        expected1 = "".join([header, topic1, topic2])
        expected2 = "".join([header, topic2, topic1])

        encoded = KafkaProtocol.encode_fetch_request("client1", 3, requests, 2,
                                                     100)
        self.assertIn(encoded, [expected1, expected2])
Ejemplo n.º 4
0
    def test_encode_fetch_request(self):
        requests = [
            FetchRequest(b"topic1", 0, 10, 1024),
            FetchRequest(b"topic2", 1, 20, 100),
        ]

        header = b"".join([
            struct.pack('>i', 89),             # The length of the message overall
            struct.pack('>h', 1),              # Msg Header, Message type = Fetch
            struct.pack('>h', 0),              # Msg Header, API version
            struct.pack('>i', 3),              # Msg Header, Correlation ID
            struct.pack('>h7s', 7, b"client1"),# Msg Header, The client ID
            struct.pack('>i', -1),             # Replica Id
            struct.pack('>i', 2),              # Max wait time
            struct.pack('>i', 100),            # Min bytes
            struct.pack('>i', 2),              # Num requests
        ])

        topic1 = b"".join([
            struct.pack('>h6s', 6, b'topic1'),# Topic
            struct.pack('>i', 1),             # Num Payloads
            struct.pack('>i', 0),             # Partition 0
            struct.pack('>q', 10),            # Offset
            struct.pack('>i', 1024),          # Max Bytes
        ])

        topic2 = b"".join([
            struct.pack('>h6s', 6, b'topic2'),# Topic
            struct.pack('>i', 1),             # Num Payloads
            struct.pack('>i', 1),             # Partition 0
            struct.pack('>q', 20),            # Offset
            struct.pack('>i', 100),           # Max Bytes
        ])

        expected1 = b"".join([ header, topic1, topic2 ])
        expected2 = b"".join([ header, topic2, topic1 ])

        encoded = KafkaProtocol.encode_fetch_request(b"client1", 3, requests, 2, 100)
        self.assertIn(encoded, [ expected1, expected2 ])