Commit 9efdbceb authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DDC-613' into 2.4

parents 814e53d0 71ea2a5d
...@@ -115,7 +115,7 @@ class PoolingShardManager implements ShardManager ...@@ -115,7 +115,7 @@ class PoolingShardManager implements ShardManager
$oldDistribution = $this->getCurrentDistributionValue(); $oldDistribution = $this->getCurrentDistributionValue();
foreach ($shards as $shard) { foreach ($shards as $shard) {
$this->selectShard($shard['id']); $this->conn->connect($shard['id']);
foreach ($this->conn->fetchAll($sql, $params, $types) as $row) { foreach ($this->conn->fetchAll($sql, $params, $types) as $row) {
$result[] = $row; $result[] = $row;
} }
......
...@@ -36,6 +36,15 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase ...@@ -36,6 +36,15 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
return $mock; return $mock;
} }
private function createStaticShardChoser()
{
$mock = $this->getMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser');
$mock->expects($this->any())
->method('pickShard')
->will($this->returnCallback(function($value) { return 1; }));
return $mock;
}
public function testSelectGlobal() public function testSelectGlobal()
{ {
$conn = $this->createConnectionMock(); $conn = $this->createConnectionMock();
...@@ -104,5 +113,35 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase ...@@ -104,5 +113,35 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(array('id' => 1), array('id' => 2)), $result); $this->assertEquals(array(array('id' => 1), array('id' => 2)), $result);
} }
public function testQueryAllWithStaticShardChoser()
{
$sql = "SELECT * FROM table";
$params = array(1);
$types = array(1);
$conn = $this->createConnectionMock();
$conn->expects($this->at(0))->method('getParams')->will($this->returnValue(
array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createStaticShardChoser())
));
$conn->expects($this->at(1))->method('getParams')->will($this->returnValue(
array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createStaticShardChoser())
));
$conn->expects($this->at(2))->method('connect')->with($this->equalTo(1));
$conn->expects($this->at(3))
->method('fetchAll')
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
->will($this->returnValue(array( array('id' => 1) ) ));
$conn->expects($this->at(4))->method('connect')->with($this->equalTo(2));
$conn->expects($this->at(5))
->method('fetchAll')
->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types))
->will($this->returnValue(array( array('id' => 2) ) ));
$shardManager = new PoolingShardManager($conn, $this->createStaticShardChoser());
$result = $shardManager->queryAll($sql, $params, $types);
$this->assertEquals(array(array('id' => 1), array('id' => 2)), $result);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment