Ejemplo n.º 1
0
 def _run_topics_sh(self, args):
     """Run kafka-topics.sh with the provided list of arguments."""
     binfile = os.path.join(self._bin_dir, 'bin/kafka-topics.sh')
     cmd = [binfile, '--zookeeper', self.zookeeper] + args
     cmd = [get_string(c) for c in cmd]  # execv needs only strings
     log.debug('running: %s', ' '.join(cmd))
     return subprocess.check_output(cmd)
Ejemplo n.º 2
0
 def _run_topics_sh(self, args):
     """Run kafka-topics.sh with the provided list of arguments."""
     binfile = os.path.join(self._bin_dir, 'bin/kafka-topics.sh')
     cmd = [binfile, '--zookeeper', self.zookeeper] + args
     cmd = [get_string(c) for c in cmd]  # execv needs only strings
     log.debug('running: %s', ' '.join(cmd))
     return subprocess.check_output(cmd)
Ejemplo n.º 3
0
 def produce_messages(self, topic_name, messages, batch_size=200):
     """Produce some messages to a topic."""
     binfile = os.path.join(self._bin_dir, 'bin/kafka-console-producer.sh')
     cmd = [binfile,
            '--broker-list', self.brokers,
            '--topic', topic_name,
            '--batch-size', batch_size]
     cmd = [get_string(c) for c in cmd]  # execv needs only strings
     log.debug('running: %s', ' '.join(cmd))
     proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)
     proc.communicate(input=get_bytes('\n'.join(messages)))
     if proc.poll() is None:
         proc.kill()
Ejemplo n.º 4
0
 def produce_messages(self, topic_name, messages, batch_size=200):
     """Produce some messages to a topic."""
     binfile = os.path.join(self._bin_dir, 'bin/kafka-console-producer.sh')
     cmd = [
         binfile, '--broker-list', self.brokers, '--topic', topic_name,
         '--batch-size', batch_size
     ]
     cmd = [get_string(c) for c in cmd]  # execv needs only strings
     log.debug('running: %s', ' '.join(cmd))
     proc = subprocess.Popen(cmd, stdin=subprocess.PIPE)
     proc.communicate(input=get_bytes('\n'.join(messages)))
     if proc.poll() is None:
         proc.kill()
Ejemplo n.º 5
0
    def test_partition_offset_commit_request(self):
        topic = mock.Mock()
        topic.name = "test_topic"
        partition = mock.Mock()
        partition.topic = topic
        partition.id = 12345

        op = OwnedPartition(partition)
        op.last_offset_consumed = 200

        request = op.build_offset_commit_request()

        self.assertEqual(request.topic_name, topic.name)
        self.assertEqual(request.partition_id, partition.id)
        self.assertEqual(request.offset, op.last_offset_consumed + 1)
        parsed_metadata = json.loads(get_string(request.metadata))
        self.assertEqual(parsed_metadata["consumer_id"], '')
        self.assertTrue(bool(parsed_metadata["hostname"]))
Ejemplo n.º 6
0
    def test_partition_offset_commit_request(self):
        topic = mock.Mock()
        topic.name = "test_topic"
        partition = mock.Mock()
        partition.topic = topic
        partition.id = 12345

        op = OwnedPartition(partition)
        op.last_offset_consumed = 200

        request = op.build_offset_commit_request()

        self.assertEqual(request.topic_name, topic.name)
        self.assertEqual(request.partition_id, partition.id)
        self.assertEqual(request.offset, op.last_offset_consumed + 1)
        parsed_metadata = json.loads(get_string(request.metadata))
        self.assertEqual(parsed_metadata["consumer_id"], '')
        self.assertTrue(bool(parsed_metadata["hostname"]))