當前位置: 首頁>>代碼示例>>Python>>正文


Python AIOKafkaClient.get_random_node方法代碼示例

本文整理匯總了Python中aiokafka.client.AIOKafkaClient.get_random_node方法的典型用法代碼示例。如果您正苦於以下問題:Python AIOKafkaClient.get_random_node方法的具體用法?Python AIOKafkaClient.get_random_node怎麽用?Python AIOKafkaClient.get_random_node使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在aiokafka.client.AIOKafkaClient的用法示例。


在下文中一共展示了AIOKafkaClient.get_random_node方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_no_concurrent_send_on_connection

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_no_concurrent_send_on_connection(self):
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=self.hosts,
            metadata_max_age_ms=10000)
        yield from client.bootstrap()
        self.add_cleanup(client.close)

        yield from self.wait_topic(client, self.topic)

        node_id = client.get_random_node()
        wait_request = FetchRequest_v0(
            -1,  # replica_id
            500,  # max_wait_ms
            1024 * 1024,  # min_bytes
            [(self.topic, [(0, 0, 1024)]
              )])
        vanila_request = MetadataRequest([])

        send_time = self.loop.time()
        long_task = self.loop.create_task(
            client.send(node_id, wait_request)
        )
        yield from asyncio.sleep(0.0001, loop=self.loop)
        self.assertFalse(long_task.done())

        yield from client.send(node_id, vanila_request)
        resp_time = self.loop.time()
        fetch_resp = yield from long_task
        # Check error code like resp->topics[0]->partitions[0]->error_code
        self.assertEqual(fetch_resp.topics[0][1][0][1], 0)

        # Check that vanila request actually executed after wait request
        self.assertGreaterEqual(resp_time - send_time, 0.5)
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:36,代碼來源:test_client.py

示例2: test_send_request

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
 def test_send_request(self):
     client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
     yield from client.bootstrap()
     node_id = client.get_random_node()
     resp = yield from client.send(node_id, MetadataRequest([]))
     self.assertTrue(isinstance(resp, MetadataResponse))
     yield from client.close()
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:9,代碼來源:test_client.py

示例3: test_check_version

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_check_version(self):
        client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
        yield from client.bootstrap()
        ver = yield from client.check_version()
        self.assertTrue('0.' in ver)
        yield from self.wait_topic(client, 'some_test_topic')
        ver2 = yield from client.check_version()
        self.assertEqual(ver, ver2)
        ver2 = yield from client.check_version(client.get_random_node())
        self.assertEqual(ver, ver2)

        with mock.patch.object(
                AIOKafkaConnection, 'send') as mocked:
            mocked.side_effect = KafkaError('mocked exception')
            with self.assertRaises(UnrecognizedBrokerVersion):
                yield from client.check_version(client.get_random_node())

        client._get_conn = asyncio.coroutine(lambda _: None)
        with self.assertRaises(ConnectionError):
            yield from client.check_version()
開發者ID:fabregas,項目名稱:aiokafka,代碼行數:22,代碼來源:test_client.py

示例4: test_init_with_list

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_init_with_list(self):
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=['kafka01:9092', 'kafka02:9092', 'kafka03:9092'])
        self.assertEqual(
            '<AIOKafkaClient client_id=aiokafka-0.0.1>', client.__repr__())
        self.assertEqual(sorted({'kafka01': 9092,
                                 'kafka02': 9092,
                                 'kafka03': 9092}.items()),
                         sorted(client.hosts))

        node = client.get_random_node()
        self.assertEqual(node, None)  # unknown cluster metadata
開發者ID:fabregas,項目名稱:aiokafka,代碼行數:15,代碼來源:test_client.py

示例5: test_init_with_list

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_init_with_list(self):
        client = AIOKafkaClient(
            loop=self.loop, bootstrap_servers=[
                '127.0.0.1:9092', '127.0.0.2:9092', '127.0.0.3:9092'])
        self.assertEqual(
            '<AIOKafkaClient client_id=aiokafka-0.1.2>', client.__repr__())
        self.assertEqual(
            sorted([('127.0.0.1', 9092, socket.AF_INET),
                    ('127.0.0.2', 9092, socket.AF_INET),
                    ('127.0.0.3', 9092, socket.AF_INET)]),
            sorted(client.hosts))

        node = client.get_random_node()
        self.assertEqual(node, None)  # unknown cluster metadata
開發者ID:crccheck,項目名稱:aiokafka,代碼行數:16,代碼來源:test_client.py

示例6: test_check_version

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_check_version(self):
        kafka_version = tuple(int(x) for x in self.kafka_version.split("."))

        client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
        yield from client.bootstrap()
        ver = yield from client.check_version()
        self.assertEqual(kafka_version[:2], ver[:2])
        yield from self.wait_topic(client, 'some_test_topic')
        ver2 = yield from client.check_version()
        self.assertEqual(ver, ver2)
        ver2 = yield from client.check_version(client.get_random_node())
        self.assertEqual(ver, ver2)

        with mock.patch.object(
                AIOKafkaConnection, 'send') as mocked:
            mocked.side_effect = KafkaError('mocked exception')
            with self.assertRaises(UnrecognizedBrokerVersion):
                yield from client.check_version(client.get_random_node())

        client._get_conn = asyncio.coroutine(lambda _, **kw: None)
        with self.assertRaises(ConnectionError):
            yield from client.check_version()
        yield from client.close()
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:25,代碼來源:test_client.py

示例7: test_concurrent_send_on_different_connection_groups

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_concurrent_send_on_different_connection_groups(self):
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=self.hosts,
            metadata_max_age_ms=10000)
        yield from client.bootstrap()
        self.add_cleanup(client.close)

        yield from self.wait_topic(client, self.topic)

        node_id = client.get_random_node()
        broker = client.cluster.broker_metadata(node_id)
        client.cluster.add_coordinator(
            node_id, broker.host, broker.port, rack=None,
            purpose=(CoordinationType.GROUP, ""))

        wait_request = FetchRequest_v0(
            -1,  # replica_id
            500,  # max_wait_ms
            1024 * 1024,  # min_bytes
            [(self.topic, [(0, 0, 1024)]
              )])
        vanila_request = MetadataRequest([])

        send_time = self.loop.time()
        long_task = self.loop.create_task(
            client.send(node_id, wait_request)
        )
        yield from asyncio.sleep(0.0001, loop=self.loop)
        self.assertFalse(long_task.done())

        yield from client.send(
            node_id, vanila_request, group=ConnectionGroup.COORDINATION)
        resp_time = self.loop.time()
        self.assertFalse(long_task.done())

        fetch_resp = yield from long_task
        # Check error code like resp->topics[0]->partitions[0]->error_code
        self.assertEqual(fetch_resp.topics[0][1][0][1], 0)

        # Check that vanila request actually executed after wait request
        self.assertLess(resp_time - send_time, 0.5)
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:44,代碼來源:test_client.py

示例8: test_different_connections_in_conn_groups

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_different_connections_in_conn_groups(self):
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=self.hosts,
            metadata_max_age_ms=10000)
        yield from client.bootstrap()
        self.add_cleanup(client.close)

        node_id = client.get_random_node()
        broker = client.cluster.broker_metadata(node_id)
        client.cluster.add_coordinator(
            node_id, broker.host, broker.port, rack=None,
            purpose=(CoordinationType.GROUP, ""))

        conn1 = yield from client._get_conn(node_id)
        conn2 = yield from client._get_conn(
            node_id, group=ConnectionGroup.COORDINATION)

        self.assertTrue(conn1 is not conn2)
        self.assertEqual((conn1.host, conn1.port), (conn2.host, conn2.port))
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:22,代碼來源:test_client.py

示例9: test_metadata_updated_on_socket_disconnect

# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import get_random_node [as 別名]
    def test_metadata_updated_on_socket_disconnect(self):
        # Related to issue 176. A disconnect means that either we lost
        # connection to the node, or we have a node failure. In both cases
        # there's a high probability that Leader distribution will also change.
        client = AIOKafkaClient(
            loop=self.loop,
            bootstrap_servers=self.hosts,
            metadata_max_age_ms=10000)
        yield from client.bootstrap()
        self.add_cleanup(client.close)

        # Init a clonnection
        node_id = client.get_random_node()
        assert node_id is not None
        req = MetadataRequest([])
        yield from client.send(node_id, req)

        # No metadata update pending atm
        self.assertFalse(client._md_update_waiter.done())

        # Connection disconnect should trigger an update
        conn = yield from client._get_conn(node_id)
        conn.close(reason=CloseReason.CONNECTION_BROKEN)
        self.assertTrue(client._md_update_waiter.done())
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:26,代碼來源:test_client.py


注:本文中的aiokafka.client.AIOKafkaClient.get_random_node方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。