|
@@ -65,8 +65,8 @@ class MasterSlaveReplicationTest extends PredisTestCase
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
- * @expectedException \RuntimeException
|
|
|
- * @expectedExceptionMessage Replication needs one master and at least one slave.
|
|
|
+ * @expectedException \Predis\ClientException
|
|
|
+ * @expectedExceptionMessage No available connection for replication
|
|
|
*/
|
|
|
public function testThrowsExceptionOnEmptyReplication()
|
|
|
{
|
|
@@ -76,26 +76,18 @@ class MasterSlaveReplicationTest extends PredisTestCase
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
- * @expectedException \RuntimeException
|
|
|
- * @expectedExceptionMessage Replication needs one master and at least one slave.
|
|
|
*/
|
|
|
- public function testThrowsExceptionOnMissingMaster()
|
|
|
+ public function testConnectsToOneOfSlaves()
|
|
|
{
|
|
|
- $replication = new MasterSlaveReplication();
|
|
|
- $replication->add($this->getMockConnection('tcp://host2?alias=slave1'));
|
|
|
+ $master = $this->getMockConnection('tcp://host1?alias=master');
|
|
|
+ $master->expects($this->never())->method('connect');
|
|
|
|
|
|
- $replication->connect();
|
|
|
- }
|
|
|
+ $slave = $this->getMockConnection('tcp://host2?alias=slave1');
|
|
|
+ $slave->expects($this->once())->method('connect');
|
|
|
|
|
|
- /**
|
|
|
- * @group disconnected
|
|
|
- * @expectedException \RuntimeException
|
|
|
- * @expectedExceptionMessage Replication needs one master and at least one slave.
|
|
|
- */
|
|
|
- public function testThrowsExceptionOnMissingSlave()
|
|
|
- {
|
|
|
$replication = new MasterSlaveReplication();
|
|
|
- $replication->add($this->getMockConnection('tcp://host1?alias=master'));
|
|
|
+ $replication->add($master);
|
|
|
+ $replication->add($slave);
|
|
|
|
|
|
$replication->connect();
|
|
|
}
|
|
@@ -103,19 +95,15 @@ class MasterSlaveReplicationTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testConnectForcesConnectionToOneOfSlaves()
|
|
|
+ public function testConnectsToMasterOnMissingSlaves()
|
|
|
{
|
|
|
$master = $this->getMockConnection('tcp://host1?alias=master');
|
|
|
- $master->expects($this->never())->method('connect');
|
|
|
-
|
|
|
- $slave = $this->getMockConnection('tcp://host2?alias=slave1');
|
|
|
- $slave->expects($this->once())->method('connect');
|
|
|
|
|
|
$replication = new MasterSlaveReplication();
|
|
|
$replication->add($master);
|
|
|
- $replication->add($slave);
|
|
|
|
|
|
$replication->connect();
|
|
|
+ $this->assertSame($master, $replication->getCurrent());
|
|
|
}
|
|
|
|
|
|
/**
|