コード例 #1
0
ファイル: pulsar_test.py プロジェクト: zsc347/pulsar
    def test_get_partitioned_topic_name(self):
        client = Client(self.serviceUrl)
        url1 = self.adminUrl + '/admin/v2/persistent/public/default/partitioned_topic_name_test/partitions'
        doHttpPut(url1, '3')

        partitions = [
            'persistent://public/default/partitioned_topic_name_test-partition-0',
            'persistent://public/default/partitioned_topic_name_test-partition-1',
            'persistent://public/default/partitioned_topic_name_test-partition-2'
        ]
        self.assertEqual(
            client.get_topic_partitions(
                'persistent://public/default/partitioned_topic_name_test'),
            partitions)

        consumer = client.subscribe(
            'persistent://public/default/partitioned_topic_name_test',
            'partitioned_topic_name_test_sub',
            consumer_type=ConsumerType.Shared)
        producer = client.create_producer(
            'persistent://public/default/partitioned_topic_name_test')
        producer.send(b'hello')

        msg = consumer.receive(TM)
        self.assertTrue(msg.topic_name() in partitions)
        client.close()
コード例 #2
0
ファイル: pulsar_test.py プロジェクト: zhangcly/pulsar
    def test_get_partitioned_topic_name(self):
        client = Client(self.serviceUrl)
        url1 = self.adminUrl + "/admin/v2/persistent/public/default/partitioned_topic_name_test/partitions"
        doHttpPut(url1, "3")

        partitions = [
            "persistent://public/default/partitioned_topic_name_test-partition-0",
            "persistent://public/default/partitioned_topic_name_test-partition-1",
            "persistent://public/default/partitioned_topic_name_test-partition-2",
        ]
        self.assertEqual(
            client.get_topic_partitions(
                "persistent://public/default/partitioned_topic_name_test"),
            partitions)

        consumer = client.subscribe(
            "persistent://public/default/partitioned_topic_name_test",
            "partitioned_topic_name_test_sub",
            consumer_type=ConsumerType.Shared,
        )
        producer = client.create_producer(
            "persistent://public/default/partitioned_topic_name_test")
        producer.send(b"hello")

        msg = consumer.receive(TM)
        self.assertTrue(msg.topic_name() in partitions)
        client.close()
コード例 #3
0
    def test_get_topics_partitions(self):
        client = Client(self.serviceUrl)
        topic_partitioned = 'persistent://public/default/test_get_topics_partitions'
        topic_non_partitioned = 'persistent://public/default/test_get_topics_not-partitioned'

        url1 = self.adminUrl + '/admin/v2/persistent/public/default/test_get_topics_partitions/partitions'
        doHttpPut(url1, '3')

        self.assertEqual(client.get_topic_partitions(topic_partitioned),
                         ['persistent://public/default/test_get_topics_partitions-partition-0',
                          'persistent://public/default/test_get_topics_partitions-partition-1',
                          'persistent://public/default/test_get_topics_partitions-partition-2'])

        self.assertEqual(client.get_topic_partitions(topic_non_partitioned),
                         [topic_non_partitioned])
        client.close()
コード例 #4
0
ファイル: pulsar_test.py プロジェクト: zhangcly/pulsar
    def test_get_topics_partitions(self):
        client = Client(self.serviceUrl)
        topic_partitioned = "persistent://public/default/test_get_topics_partitions"
        topic_non_partitioned = "persistent://public/default/test_get_topics_not-partitioned"

        url1 = self.adminUrl + "/admin/v2/persistent/public/default/test_get_topics_partitions/partitions"
        doHttpPut(url1, "3")

        self.assertEqual(
            client.get_topic_partitions(topic_partitioned),
            [
                "persistent://public/default/test_get_topics_partitions-partition-0",
                "persistent://public/default/test_get_topics_partitions-partition-1",
                "persistent://public/default/test_get_topics_partitions-partition-2",
            ],
        )

        self.assertEqual(client.get_topic_partitions(topic_non_partitioned),
                         [topic_non_partitioned])
        client.close()