|
@@ -39,7 +39,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
public function testParametersForSentinelConnectionShouldNotUseDatabaseAndPassword()
|
|
|
{
|
|
|
$replication = $this->getReplicationConnection('svc', array(
|
|
|
- 'tcp://127.0.0.1:5381?alias=sentinel1&database=1&password=secret',
|
|
|
+ 'tcp://127.0.0.1:5381?role=sentinel&database=1&password=secret',
|
|
|
));
|
|
|
|
|
|
$parameters = $replication->getSentinelConnection()->getParameters()->toArray();
|
|
@@ -53,7 +53,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
public function testParametersForSentinelConnectionHaveDefaultTimeout()
|
|
|
{
|
|
|
$replication = $this->getReplicationConnection('svc', array(
|
|
|
- 'tcp://127.0.0.1:5381?alias=sentinel',
|
|
|
+ 'tcp://127.0.0.1:5381?role=sentinel',
|
|
|
));
|
|
|
|
|
|
$parameters = $replication->getSentinelConnection()->getParameters()->toArray();
|
|
@@ -68,7 +68,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
public function testParametersForSentinelConnectionCanOverrideDefaultTimeout()
|
|
|
{
|
|
|
$replication = $this->getReplicationConnection('svc', array(
|
|
|
- 'tcp://127.0.0.1:5381?alias=sentinel&timeout=1',
|
|
|
+ 'tcp://127.0.0.1:5381?role=sentinel&timeout=1',
|
|
|
));
|
|
|
|
|
|
$parameters = $replication
|
|
@@ -86,7 +86,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
public function testConnectionParametersInstanceForSentinelConnectionIsNotModified()
|
|
|
{
|
|
|
$originalParameters = Connection\Parameters::create(
|
|
|
- 'tcp://127.0.0.1:5381?alias=sentinel1&database=1&password=secret'
|
|
|
+ 'tcp://127.0.0.1:5381?role=sentinel&database=1&password=secret'
|
|
|
);
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($originalParameters));
|
|
@@ -105,9 +105,9 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodGetSentinelConnectionReturnsFirstAvailableSentinel()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
- $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?alias=sentinel2');
|
|
|
- $sentinel3 = $this->getMockSentinelConnection('tcp://127.0.0.1:5383?alias=sentinel3');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel&alias=sentinel1');
|
|
|
+ $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?role=sentinel&alias=sentinel2');
|
|
|
+ $sentinel3 = $this->getMockSentinelConnection('tcp://127.0.0.1:5383?role=sentinel&alias=sentinel3');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1, $sentinel2, $sentinel3));
|
|
|
|
|
@@ -119,11 +119,11 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodAddAttachesMasterOrSlaveNodesToReplication()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
|
|
@@ -131,9 +131,9 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
$replication->add($slave1);
|
|
|
$replication->add($slave2);
|
|
|
|
|
|
- $this->assertSame($master, $replication->getConnectionById('master'));
|
|
|
- $this->assertSame($slave1, $replication->getConnectionById('slave1'));
|
|
|
- $this->assertSame($slave2, $replication->getConnectionById('slave2'));
|
|
|
+ $this->assertSame($master, $replication->getConnectionById('127.0.0.1:6381'));
|
|
|
+ $this->assertSame($slave1, $replication->getConnectionById('127.0.0.1:6382'));
|
|
|
+ $this->assertSame($slave2, $replication->getConnectionById('127.0.0.1:6383'));
|
|
|
|
|
|
$this->assertSame($master, $replication->getMaster());
|
|
|
$this->assertSame(array($slave1, $slave2), $replication->getSlaves());
|
|
@@ -141,14 +141,15 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
+ * @FIXME
|
|
|
*/
|
|
|
public function testMethodRemoveDismissesMasterOrSlaveNodesFromReplication()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
|
|
@@ -157,19 +158,105 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
$replication->add($slave2);
|
|
|
|
|
|
$this->assertTrue($replication->remove($slave1));
|
|
|
- $this->assertFalse($replication->remove($sentinel1));
|
|
|
+ $this->assertTrue($replication->remove($sentinel1));
|
|
|
|
|
|
$this->assertSame('127.0.0.1:6381', (string) $replication->getMaster());
|
|
|
$this->assertCount(1, $slaves = $replication->getSlaves());
|
|
|
$this->assertSame('127.0.0.1:6383', (string) $slaves[0]);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testMethodGetConnectionByIdOnEmptyReplication()
|
|
|
+ {
|
|
|
+ $replication = $this->getReplicationConnection('svc', array());
|
|
|
+
|
|
|
+ $this->assertNull($replication->getConnectionById('127.0.0.1:6381'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testMethodGetConnectionByRole()
|
|
|
+ {
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+
|
|
|
+ $replication = $this->getReplicationConnection('svc', array());
|
|
|
+
|
|
|
+ $replication->add($master);
|
|
|
+ $replication->add($slave1);
|
|
|
+ $replication->add($sentinel1);
|
|
|
+
|
|
|
+ $this->assertSame($sentinel1, $replication->getConnectionByRole('sentinel'));
|
|
|
+ $this->assertSame($master, $replication->getConnectionByRole('master'));
|
|
|
+ $this->assertSame($slave1, $replication->getConnectionByRole('slave'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testMethodGetConnectionByRoleOnEmptyReplicationForcesSentinelQueries()
|
|
|
+ {
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
+ $sentinel1
|
|
|
+ ->expects($this->exactly(2))
|
|
|
+ ->method('executeCommand')
|
|
|
+ ->withConsecutive(
|
|
|
+ $this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')),
|
|
|
+ $this->isRedisCommand('SENTINEL', array('slaves', 'svc'))
|
|
|
+ )
|
|
|
+ ->will($this->onConsecutiveCalls(
|
|
|
+ // SENTINEL get-master-addr-by-name svc
|
|
|
+ array('127.0.0.1', '6381'),
|
|
|
+
|
|
|
+ // SENTINEL slaves svc
|
|
|
+ array(
|
|
|
+ array(
|
|
|
+ 'name', '127.0.0.1:6382',
|
|
|
+ 'ip', '127.0.0.1',
|
|
|
+ 'port', '6382',
|
|
|
+ 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f',
|
|
|
+ 'flags', 'slave',
|
|
|
+ 'master-host', '127.0.0.1',
|
|
|
+ 'master-port', '6381',
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ ));
|
|
|
+
|
|
|
+ $replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
+
|
|
|
+ $this->assertSame($sentinel1, $replication->getConnectionByRole('sentinel'));
|
|
|
+ $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $replication->getConnectionByRole('master'));
|
|
|
+ $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $replication->getConnectionByRole('slave'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testMethodGetConnectionByRoleUnknown()
|
|
|
+ {
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+
|
|
|
+ $replication = $this->getReplicationConnection('svc', array());
|
|
|
+
|
|
|
+ $replication->add($master);
|
|
|
+ $replication->add($slave1);
|
|
|
+ $replication->add($sentinel1);
|
|
|
+
|
|
|
+ $this->assertNull($replication->getConnectionByRole('unknown'));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
public function testMethodUpdateSentinelsFetchesSentinelNodes()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->once())
|
|
|
->method('executeCommand')
|
|
@@ -217,7 +304,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodUpdateSentinelsRemovesCurrentSentinelAndRetriesNextOneOnFailure()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel&alias=sentinel1');
|
|
|
$sentinel1
|
|
|
->expects($this->once())
|
|
|
->method('executeCommand')
|
|
@@ -228,7 +315,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
|
|
|
));
|
|
|
|
|
|
- $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?alias=sentinel2');
|
|
|
+ $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?role=sentinel&alias=sentinel2');
|
|
|
$sentinel2
|
|
|
->expects($this->once())
|
|
|
->method('executeCommand')
|
|
@@ -270,7 +357,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodUpdateSentinelsThrowsExceptionOnNoAvailableSentinel()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->once())
|
|
|
->method('executeCommand')
|
|
@@ -290,7 +377,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodQuerySentinelFetchesMasterNodeSlaveNodesAndSentinelNodes()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel&alias=sentinel1');
|
|
|
$sentinel1
|
|
|
->expects($this->exactly(3))
|
|
|
->method('executeCommand')
|
|
@@ -337,11 +424,11 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
)
|
|
|
));
|
|
|
|
|
|
- $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?alias=sentinel2');
|
|
|
+ $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?role=sentinel&alias=sentinel2');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
$replication->querySentinel();
|
|
@@ -373,7 +460,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodGetMasterAsksSentinelForMasterOnMasterNotSet()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->at(0))
|
|
|
->method('executeCommand')
|
|
@@ -396,7 +483,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodGetMasterThrowsExceptionOnNoAvailableSentinels()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -417,7 +504,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodGetSlavesOnEmptySlavePoolAsksSentinelForSlaves()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->at(0))
|
|
|
->method('executeCommand')
|
|
@@ -462,7 +549,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodGetSlavesThrowsExceptionOnNoAvailableSentinels()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -494,14 +581,14 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodConnectForcesConnectionToSlave()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->never())
|
|
|
->method('connect');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
@@ -519,7 +606,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodConnectOnEmptySlavePoolAsksSentinelForSlavesAndForcesConnectionToSlave()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -540,12 +627,12 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
)
|
|
|
));
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->never())
|
|
|
->method('connect');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
@@ -557,7 +644,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
->with(array(
|
|
|
'host' => '127.0.0.1',
|
|
|
'port' => '6382',
|
|
|
- 'alias' => 'slave-127.0.0.1:6382',
|
|
|
+ 'role' => 'slave',
|
|
|
))
|
|
|
->will($this->returnValue($slave1));
|
|
|
|
|
@@ -573,7 +660,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodConnectOnEmptySlavePoolAsksSentinelForSlavesAndForcesConnectionToMasterIfStillEmpty()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->at(0))
|
|
|
->method('executeCommand')
|
|
@@ -593,7 +680,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
array('127.0.0.1', '6381')
|
|
|
));
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
@@ -605,7 +692,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
->with(array(
|
|
|
'host' => '127.0.0.1',
|
|
|
'port' => '6381',
|
|
|
- 'alias' => 'master',
|
|
|
+ 'role' => 'master',
|
|
|
))
|
|
|
->will($this->returnValue($master));
|
|
|
|
|
@@ -619,22 +706,22 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodDisconnectForcesDisconnectionOnAllConnectionsInPool()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->never())
|
|
|
->method('disconnect');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->once())
|
|
|
->method('disconnect');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->once())
|
|
|
->method('disconnect');
|
|
|
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
$slave2
|
|
|
->expects($this->once())
|
|
|
->method('disconnect');
|
|
@@ -653,9 +740,9 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodIsConnectedReturnConnectionStatusOfCurrentConnection()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->exactly(2))
|
|
|
->method('isConnected')
|
|
@@ -668,7 +755,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
$this->assertFalse($replication->isConnected());
|
|
|
$replication->connect();
|
|
|
$this->assertTrue($replication->isConnected());
|
|
|
- $replication->getConnectionById('slave1')->disconnect();
|
|
|
+ $replication->getConnectionById('127.0.0.1:6382')->disconnect();
|
|
|
$this->assertFalse($replication->isConnected());
|
|
|
}
|
|
|
|
|
@@ -677,39 +764,39 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodGetConnectionByIdReturnsConnectionWhenFound()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
|
|
|
$replication->add($master);
|
|
|
$replication->add($slave1);
|
|
|
|
|
|
- $this->assertSame($master, $replication->getConnectionById('master'));
|
|
|
- $this->assertSame($slave1, $replication->getConnectionById('slave1'));
|
|
|
- $this->assertNull($replication->getConnectionById('unknown'));
|
|
|
+ $this->assertSame($master, $replication->getConnectionById('127.0.0.1:6381'));
|
|
|
+ $this->assertSame($slave1, $replication->getConnectionById('127.0.0.1:6382'));
|
|
|
+ $this->assertNull($replication->getConnectionById('127.0.0.1:6383'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testMethodSwitchToSelectsCurrentConnectionByConnectionAlias()
|
|
|
+ public function testMethodSwitchToSelectsCurrentConnection()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->never())
|
|
|
->method('connect');
|
|
|
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave2');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave2
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
@@ -720,10 +807,10 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
$replication->add($slave1);
|
|
|
$replication->add($slave2);
|
|
|
|
|
|
- $replication->switchTo('master');
|
|
|
+ $replication->switchTo($master);
|
|
|
$this->assertSame($master, $replication->getCurrent());
|
|
|
|
|
|
- $replication->switchTo('slave2');
|
|
|
+ $replication->switchTo($slave2);
|
|
|
$this->assertSame($slave2, $replication->getCurrent());
|
|
|
}
|
|
|
|
|
@@ -734,17 +821,18 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodSwitchToThrowsExceptionOnConnectionNotFound()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
|
|
|
$replication->add($master);
|
|
|
$replication->add($slave1);
|
|
|
|
|
|
- $replication->switchTo('unknown');
|
|
|
+ $replication->switchTo($slave2);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -752,14 +840,14 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodSwitchToMasterSelectsCurrentConnectionToMaster()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->never())
|
|
|
->method('connect');
|
|
@@ -779,14 +867,14 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodSwitchToSlaveSelectsCurrentConnectionToRandomSlave()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->never())
|
|
|
->method('connect');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->once())
|
|
|
->method('connect');
|
|
@@ -804,24 +892,24 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetConnectionReturnsMasterForWriteCommands()
|
|
|
+ public function testGetConnectionByCommandReturnsMasterForWriteCommands()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->exactly(2))
|
|
|
->method('isConnected')
|
|
|
->will($this->onConsecutiveCalls(false, true));
|
|
|
$master
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand('ROLE'))
|
|
|
->will($this->returnValue(array(
|
|
|
'master', 3129659, array(array('127.0.0.1', 6382, 3129242)),
|
|
|
)));
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
|
|
|
$replication = $this->getReplicationConnection('svc', array($sentinel1));
|
|
|
|
|
@@ -840,19 +928,19 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetConnectionReturnsSlaveForReadOnlyCommands()
|
|
|
+ public function testGetConnectionByCommandReturnsSlaveForReadOnlyCommands()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->exactly(2))
|
|
|
->method('isConnected')
|
|
|
->will($this->onConsecutiveCalls(false, true));
|
|
|
$slave1
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand('ROLE'))
|
|
|
->will($this->returnValue(array(
|
|
@@ -876,30 +964,30 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetConnectionSwitchesToMasterAfterWriteCommand()
|
|
|
+ public function testGetConnectionByCommandSwitchesToMasterAfterWriteCommand()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->exactly(2))
|
|
|
->method('isConnected')
|
|
|
->will($this->onConsecutiveCalls(false, true));
|
|
|
$master
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand('ROLE'))
|
|
|
->will($this->returnValue(array(
|
|
|
'master', 3129659, array(array('127.0.0.1', 6382, 3129242)),
|
|
|
)));
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->exactly(1))
|
|
|
->method('isConnected')
|
|
|
->will($this->onConsecutiveCalls(false));
|
|
|
$slave1
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand('ROLE'))
|
|
|
->will($this->returnValue(array(
|
|
@@ -929,17 +1017,17 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
* @expectedException Predis\Replication\RoleException
|
|
|
* @expectedExceptionMessage Expected master but got slave [127.0.0.1:6381]
|
|
|
*/
|
|
|
- public function testGetConnectionThrowsExceptionOnNodeRoleMismatch()
|
|
|
+ public function testGetConnectionByCommandThrowsExceptionOnNodeRoleMismatch()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->once())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(false));
|
|
|
$master
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand('ROLE'))
|
|
|
->will($this->returnValue(array(
|
|
@@ -956,9 +1044,9 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetConnectionReturnsMasterForReadOnlyOperationsOnUnavailableSlaves()
|
|
|
+ public function testGetConnectionByCommandReturnsMasterForReadOnlyOperationsOnUnavailableSlaves()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->once())
|
|
|
->method('executeCommand')
|
|
@@ -979,13 +1067,13 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
)
|
|
|
));
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->once())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(false));
|
|
|
$master
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand('ROLE'))
|
|
|
->will($this->returnValue(array(
|
|
@@ -1004,7 +1092,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodExecuteCommandSendsCommandToNodeAndReturnsResponse()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
$cmdGet = Command\RawCommand::create('get', 'key');
|
|
|
$cmdGetResponse = 'value';
|
|
@@ -1012,26 +1100,26 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
$cmdSet = Command\RawCommand::create('set', 'key', 'value');
|
|
|
$cmdSetResponse = Response\Status::get('OK');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$master
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'SET', array('key', $cmdGetResponse)
|
|
|
))
|
|
|
->will($this->returnValue($cmdSetResponse));
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$slave1
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'GET', array('key')
|
|
@@ -1052,7 +1140,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodExecuteCommandRetriesReadOnlyCommandOnNextSlaveOnFailure()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -1073,19 +1161,19 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
)
|
|
|
));
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
$slave1
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$slave1
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'GET', array('key')
|
|
@@ -1094,13 +1182,13 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
new Connection\ConnectionException($slave1, 'Unknown connection error [127.0.0.1:6382]')
|
|
|
));
|
|
|
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
$slave2
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$slave2
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'GET', array('key')
|
|
@@ -1114,7 +1202,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
->with(array(
|
|
|
'host' => '127.0.0.1',
|
|
|
'port' => '6383',
|
|
|
- 'alias' => 'slave-127.0.0.1:6383',
|
|
|
+ 'role' => 'slave',
|
|
|
))
|
|
|
->will($this->returnValue($slave2));
|
|
|
|
|
@@ -1133,7 +1221,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodExecuteCommandRetriesWriteCommandOnNewMasterOnFailure()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -1144,13 +1232,13 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
array('127.0.0.1', '6391')
|
|
|
));
|
|
|
|
|
|
- $masterOld = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $masterOld = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$masterOld
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$masterOld
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'DEL', array('key')
|
|
@@ -1159,13 +1247,13 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]')
|
|
|
));
|
|
|
|
|
|
- $masterNew = $this->getMockConnection('tcp://127.0.0.1:6391?alias=master');
|
|
|
+ $masterNew = $this->getMockConnection('tcp://127.0.0.1:6391?role=master');
|
|
|
$masterNew
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$masterNew
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'DEL', array('key')
|
|
@@ -1179,7 +1267,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
->with(array(
|
|
|
'host' => '127.0.0.1',
|
|
|
'port' => '6391',
|
|
|
- 'alias' => 'master',
|
|
|
+ 'role' => 'master',
|
|
|
))
|
|
|
->will($this->returnValue($masterNew));
|
|
|
|
|
@@ -1199,7 +1287,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodExecuteCommandThrowsExceptionOnUnknownServiceName()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -1208,13 +1296,13 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
))
|
|
|
->will($this->returnValue(null));
|
|
|
|
|
|
- $masterOld = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $masterOld = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$masterOld
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$masterOld
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'DEL', array('key')
|
|
@@ -1239,7 +1327,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodExecuteCommandThrowsExceptionOnConnectionFailureAndNoAvailableSentinels()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
$sentinel1
|
|
|
->expects($this->any())
|
|
|
->method('executeCommand')
|
|
@@ -1250,13 +1338,13 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
|
|
|
));
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
$master
|
|
|
->expects($this->any())
|
|
|
->method('isConnected')
|
|
|
->will($this->returnValue(true));
|
|
|
$master
|
|
|
- ->expects($this->at(2))
|
|
|
+ ->expects($this->at(3))
|
|
|
->method('executeCommand')
|
|
|
->with($this->isRedisCommand(
|
|
|
'DEL', array('key')
|
|
@@ -1283,7 +1371,7 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
$factory = new Connection\Factory();
|
|
|
|
|
|
$replication = new SentinelReplication(
|
|
|
- 'svc', array('tcp://127.0.0.1:5381?alias=sentinel1'), $factory, $strategy
|
|
|
+ 'svc', array('tcp://127.0.0.1:5381?role=sentinel'), $factory, $strategy
|
|
|
);
|
|
|
|
|
|
$this->assertSame($strategy, $replication->getReplicationStrategy());
|
|
@@ -1294,11 +1382,11 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
*/
|
|
|
public function testMethodSerializeCanSerializeWholeObject()
|
|
|
{
|
|
|
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1');
|
|
|
+ $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
|
|
|
|
|
|
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
|
|
|
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
|
|
|
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
|
|
|
+ $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
|
|
|
+ $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
|
|
|
+ $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
|
|
|
|
|
|
$strategy = new Replication\ReplicationStrategy();
|
|
|
$factory = new Connection\Factory();
|
|
@@ -1311,9 +1399,9 @@ class SentinelReplicationTest extends PredisTestCase
|
|
|
|
|
|
$unserialized = unserialize(serialize($replication));
|
|
|
|
|
|
- $this->assertEquals($master, $unserialized->getConnectionById('master'));
|
|
|
- $this->assertEquals($slave1, $unserialized->getConnectionById('slave1'));
|
|
|
- $this->assertEquals($master, $unserialized->getConnectionById('slave2'));
|
|
|
+ $this->assertEquals($master, $unserialized->getConnectionById('127.0.0.1:6381'));
|
|
|
+ $this->assertEquals($slave1, $unserialized->getConnectionById('127.0.0.1:6382'));
|
|
|
+ $this->assertEquals($master, $unserialized->getConnectionById('127.0.0.1:6383'));
|
|
|
$this->assertEquals($strategy, $unserialized->getReplicationStrategy());
|
|
|
}
|
|
|
|