Skip to content

Commit

Permalink
fix(project): bad value of getBrokers
Browse files Browse the repository at this point in the history
  • Loading branch information
euskadi31 committed Feb 23, 2016
1 parent ca07db5 commit 2e06e76
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# directories
vendor/
build/
dev/

# files
composer.phar
Expand Down
6 changes: 3 additions & 3 deletions src/ClusterMetadata/Zookeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function getZookeeper()
public function getBrokers()
{
$result = [];
$lists = $this->zookeeper->getChildren(self::BROKER_PATH);
$lists = $this->getZookeeper()->getChildren(self::BROKER_PATH);

if (!empty($lists)) {
foreach ($lists as $brokerId) {
Expand Down Expand Up @@ -194,8 +194,8 @@ public function getBrokerDetail($brokerId)
$result = [];
$path = sprintf(self::BROKER_DETAIL_PATH, (int) $brokerId);

if ($this->zookeeper->exists($path)) {
$result = $this->zookeeper->get($path);
if ($this->getZookeeper()->exists($path)) {
$result = $this->getZookeeper()->get($path);

if (empty($result)) {
return [];
Expand Down
7 changes: 6 additions & 1 deletion src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public function __construct(ClusterMetadataInterface $clusterMetadata = null, \R
}

if (!empty($clusterMetadata)) {
$config->set('metadata.broker.list', $clusterMetadata->getBrokers());
$brokers = $clusterMetadata->getBrokers();
$brokers = array_map(function($broker) {
return sprintf('%s:%d', $broker['host'], $broker['port']);
}, $brokers);

$config->set('metadata.broker.list', implode(',', $brokers));
}

parent::__construct($config);
Expand Down
7 changes: 6 additions & 1 deletion src/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public function __construct(ClusterMetadataInterface $clusterMetadata = null, \R
}

if (!empty($clusterMetadata)) {
$config->set('metadata.broker.list', $clusterMetadata->getBrokers());
$brokers = $clusterMetadata->getBrokers();
$brokers = array_map(function($broker) {
return sprintf('%s:%d', $broker['host'], $broker['port']);
}, $brokers);

$config->set('metadata.broker.list', implode(',', $brokers));
}

parent::__construct($config);
Expand Down
14 changes: 12 additions & 2 deletions tests/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public function testConsumerWithClusterMetadata()

$zookeeperMock->expects($this->once())
->method('getBrokers')
->will($this->returnValue('127.0.0.1:9092'));
->will($this->returnValue([
[
'host' => '127.0.0.1',
'port' => 9092
]
]));

(new Consumer($zookeeperMock));
}
Expand All @@ -36,7 +41,12 @@ public function testConsumerWithClusterMetadataAndConf()

$zookeeperMock->expects($this->once())
->method('getBrokers')
->will($this->returnValue('127.0.0.1:9092'));
->will($this->returnValue([
[
'host' => '127.0.0.1',
'port' => 9092
]
]));

$confMock = $this->getMock('\RdKafka\Conf');

Expand Down
14 changes: 12 additions & 2 deletions tests/ProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public function testProducerWithClusterMetadata()

$zookeeperMock->expects($this->once())
->method('getBrokers')
->will($this->returnValue('127.0.0.1:9092'));
->will($this->returnValue([
[
'host' => '127.0.0.1',
'port' => 9092
]
]));

(new Producer($zookeeperMock));
}
Expand All @@ -36,7 +41,12 @@ public function testProducerWithClusterMetadataAndConf()

$zookeeperMock->expects($this->once())
->method('getBrokers')
->will($this->returnValue('127.0.0.1:9092'));
->will($this->returnValue([
[
'host' => '127.0.0.1',
'port' => 9092
]
]));

$confMock = $this->getMock('\RdKafka\Conf');

Expand Down

0 comments on commit 2e06e76

Please sign in to comment.