1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444 |
- <?php
- /*
- * This file is part of the Predis package.
- *
- * (c) Daniele Alessandri <suppakilla@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Predis\Connection\Replication;
- use Predis\Command;
- use Predis\Connection;
- use Predis\Replication;
- use Predis\Response;
- use PredisTestCase;
- /**
- *
- */
- class SentinelReplicationTest extends PredisTestCase
- {
- /**
- * @group disconnected
- * @expectedException Predis\ClientException
- * @expectedExceptionMessage No sentinel server available for autodiscovery.
- */
- public function testMethodGetSentinelConnectionThrowsExceptionOnEmptySentinelsPool()
- {
- $replication = $this->getReplicationConnection('svc', array());
- $replication->getSentinelConnection();
- }
- /**
- * @group disconnected
- */
- public function testParametersForSentinelConnectionShouldNotUseDatabaseAndPassword()
- {
- $replication = $this->getReplicationConnection('svc', array(
- 'tcp://127.0.0.1:5381?role=sentinel&database=1&password=secret',
- ));
- $parameters = $replication->getSentinelConnection()->getParameters()->toArray();
- $this->assertArraySubset(array('database' => null, 'password' => null), $parameters);
- }
- /**
- * @group disconnected
- */
- public function testParametersForSentinelConnectionHaveDefaultTimeout()
- {
- $replication = $this->getReplicationConnection('svc', array(
- 'tcp://127.0.0.1:5381?role=sentinel',
- ));
- $parameters = $replication->getSentinelConnection()->getParameters()->toArray();
- $this->assertArrayHasKey('timeout', $parameters);
- $this->assertSame(0.100, $parameters['timeout']);
- }
- /**
- * @group disconnected
- */
- public function testParametersForSentinelConnectionCanOverrideDefaultTimeout()
- {
- $replication = $this->getReplicationConnection('svc', array(
- 'tcp://127.0.0.1:5381?role=sentinel&timeout=1',
- ));
- $parameters = $replication
- ->getSentinelConnection()
- ->getParameters()
- ->toArray();
- $this->assertArrayHasKey('timeout', $parameters);
- $this->assertSame('1', $parameters['timeout']);
- }
- /**
- * @group disconnected
- */
- public function testConnectionParametersInstanceForSentinelConnectionIsNotModified()
- {
- $originalParameters = Connection\Parameters::create(
- 'tcp://127.0.0.1:5381?role=sentinel&database=1&password=secret'
- );
- $replication = $this->getReplicationConnection('svc', array($originalParameters));
- $parameters = $replication
- ->getSentinelConnection()
- ->getParameters();
- $this->assertSame($originalParameters, $parameters);
- $this->assertNotNull($parameters->password);
- $this->assertNotNull($parameters->database);
- }
- /**
- * @group disconnected
- */
- public function testMethodGetSentinelConnectionReturnsFirstAvailableSentinel()
- {
- $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));
- $this->assertSame($sentinel1, $replication->getSentinelConnection());
- }
- /**
- * @group disconnected
- */
- public function testMethodAddAttachesMasterOrSlaveNodesToReplication()
- {
- $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');
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->add($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());
- }
- /**
- * @group disconnected
- * @FIXME
- */
- public function testMethodRemoveDismissesMasterOrSlaveNodesFromReplication()
- {
- $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');
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->add($slave2);
- $this->assertTrue($replication->remove($slave1));
- $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?role=sentinel');
- $sentinel1
- ->expects($this->once())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('sentinels', 'svc')
- ))
- ->will($this->returnValue(
- array(
- array(
- 'name', '127.0.0.1:5382',
- 'ip', '127.0.0.1',
- 'port', '5382',
- 'runid', 'a113aa7a0d4870a85bb22b4b605fd26eb93ed40e',
- 'flags', 'sentinel',
- ),
- array(
- 'name', '127.0.0.1:5383',
- 'ip', '127.0.0.1',
- 'port', '5383',
- 'runid', 'f53b52d281be5cdd4873700c94846af8dbe47209',
- 'flags', 'sentinel',
- ),
- )
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->updateSentinels();
- // TODO: sorry for the smell...
- $reflection = new \ReflectionProperty($replication, 'sentinels');
- $reflection->setAccessible(true);
- $expected = array(
- array('host' => '127.0.0.1', 'port' => '5381'),
- array('host' => '127.0.0.1', 'port' => '5382'),
- array('host' => '127.0.0.1', 'port' => '5383'),
- );
- $this->assertSame($sentinel1, $replication->getSentinelConnection());
- $this->assertSame($expected, array_intersect_key($expected, $reflection->getValue($replication)));
- }
- /**
- * @group disconnected
- */
- public function testMethodUpdateSentinelsRemovesCurrentSentinelAndRetriesNextOneOnFailure()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel&alias=sentinel1');
- $sentinel1
- ->expects($this->once())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('sentinels', 'svc')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
- ));
- $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?role=sentinel&alias=sentinel2');
- $sentinel2
- ->expects($this->once())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('sentinels', 'svc')
- ))
- ->will($this->returnValue(
- array(
- array(
- 'name', '127.0.0.1:5383',
- 'ip', '127.0.0.1',
- 'port', '5383',
- 'runid', 'f53b52d281be5cdd4873700c94846af8dbe47209',
- 'flags', 'sentinel',
- ),
- )
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1, $sentinel2));
- $replication->updateSentinels();
- // TODO: sorry for the smell...
- $reflection = new \ReflectionProperty($replication, 'sentinels');
- $reflection->setAccessible(true);
- $expected = array(
- array('host' => '127.0.0.1', 'port' => '5382'),
- array('host' => '127.0.0.1', 'port' => '5383'),
- );
- $this->assertSame($sentinel2, $replication->getSentinelConnection());
- $this->assertSame($expected, array_intersect_key($expected, $reflection->getValue($replication)));
- }
- /**
- * @group disconnected
- * @expectedException Predis\ClientException
- * @expectedExceptionMessage No sentinel server available for autodiscovery.
- */
- public function testMethodUpdateSentinelsThrowsExceptionOnNoAvailableSentinel()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->once())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('sentinels', 'svc')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->updateSentinels();
- }
- /**
- * @group disconnected
- */
- public function testMethodQuerySentinelFetchesMasterNodeSlaveNodesAndSentinelNodes()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel&alias=sentinel1');
- $sentinel1
- ->expects($this->exactly(3))
- ->method('executeCommand')
- ->withConsecutive(
- $this->isRedisCommand('SENTINEL', array('sentinels', 'svc')),
- $this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')),
- $this->isRedisCommand('SENTINEL', array('slaves', 'svc'))
- )
- ->will($this->onConsecutiveCalls(
- // SENTINEL sentinels svc
- array(
- array(
- 'name', '127.0.0.1:5382',
- 'ip', '127.0.0.1',
- 'port', '5382',
- 'runid', 'a113aa7a0d4870a85bb22b4b605fd26eb93ed40e',
- 'flags', 'sentinel',
- ),
- ),
- // 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',
- ),
- array(
- 'name', '127.0.0.1:6383',
- 'ip', '127.0.0.1',
- 'port', '6383',
- 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817',
- 'flags', 'slave',
- 'master-host', '127.0.0.1',
- 'master-port', '6381',
- ),
- )
- ));
- $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?role=sentinel&alias=sentinel2');
- $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();
- // TODO: sorry for the smell...
- $reflection = new \ReflectionProperty($replication, 'sentinels');
- $reflection->setAccessible(true);
- $sentinels = array(
- array('host' => '127.0.0.1', 'port' => '5381'),
- array('host' => '127.0.0.1', 'port' => '5382'),
- );
- $this->assertSame($sentinel1, $replication->getSentinelConnection());
- $this->assertSame($sentinels, array_intersect_key($sentinels, $reflection->getValue($replication)));
- $master = $replication->getMaster();
- $slaves = $replication->getSlaves();
- $this->assertSame('127.0.0.1:6381', (string) $master);
- $this->assertCount(2, $slaves);
- $this->assertSame('127.0.0.1:6382', (string) $slaves[0]);
- $this->assertSame('127.0.0.1:6383', (string) $slaves[1]);
- }
- /**
- * @group disconnected
- */
- public function testMethodGetMasterAsksSentinelForMasterOnMasterNotSet()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->at(0))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('get-master-addr-by-name', 'svc')
- ))
- ->will($this->returnValue(
- array('127.0.0.1', '6381')
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $this->assertSame('127.0.0.1:6381', (string) $replication->getMaster());
- }
- /**
- * @group disconnected
- * @expectedException Predis\ClientException
- * @expectedExceptionMessage No sentinel server available for autodiscovery.
- */
- public function testMethodGetMasterThrowsExceptionOnNoAvailableSentinels()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('get-master-addr-by-name', 'svc')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->getMaster();
- }
- /**
- * @group disconnected
- */
- public function testMethodGetSlavesOnEmptySlavePoolAsksSentinelForSlaves()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->at(0))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('slaves', 'svc')
- ))
- ->will($this->returnValue(
- 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',
- ),
- array(
- 'name', '127.0.0.1:6383',
- 'ip', '127.0.0.1',
- 'port', '6383',
- 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817',
- 'flags', 'slave',
- 'master-host', '127.0.0.1',
- 'master-port', '6381',
- ),
- )
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $slaves = $replication->getSlaves();
- $this->assertSame('127.0.0.1:6382', (string) $slaves[0]);
- $this->assertSame('127.0.0.1:6383', (string) $slaves[1]);
- }
- /**
- * @group disconnected
- * @expectedException Predis\ClientException
- * @expectedExceptionMessage No sentinel server available for autodiscovery.
- */
- public function testMethodGetSlavesThrowsExceptionOnNoAvailableSentinels()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('slaves', 'svc')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->getSlaves();
- }
- /**
- * @group disconnected
- * @expectedException Predis\ClientException
- * @expectedExceptionMessage No sentinel server available for autodiscovery.
- */
- public function testMethodConnectThrowsExceptionOnConnectWithEmptySentinelsPool()
- {
- $replication = $this->getReplicationConnection('svc', array());
- $replication->connect();
- }
- /**
- * @group disconnected
- */
- public function testMethodConnectForcesConnectionToSlave()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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?role=slave');
- $slave1
- ->expects($this->once())
- ->method('connect');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->connect();
- }
- /**
- * @group disconnected
- */
- public function testMethodConnectOnEmptySlavePoolAsksSentinelForSlavesAndForcesConnectionToSlave()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('slaves', 'svc')
- ))
- ->will($this->returnValue(
- 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',
- ),
- )
- ));
- $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?role=slave');
- $slave1
- ->expects($this->once())
- ->method('connect');
- $factory = $this->getMock('Predis\Connection\FactoryInterface');
- $factory
- ->expects($this->once())
- ->method('create')
- ->with(array(
- 'host' => '127.0.0.1',
- 'port' => '6382',
- 'role' => 'slave',
- ))
- ->will($this->returnValue($slave1));
- $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory);
- $replication->add($master);
- $replication->connect();
- }
- /**
- * @group disconnected
- */
- public function testMethodConnectOnEmptySlavePoolAsksSentinelForSlavesAndForcesConnectionToMasterIfStillEmpty()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->at(0))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('slaves', 'svc')
- ))
- ->will($this->returnValue(
- array()
- ));
- $sentinel1
- ->expects($this->at(1))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('get-master-addr-by-name', 'svc')
- ))
- ->will($this->returnValue(
- array('127.0.0.1', '6381')
- ));
- $master = $this->getMockConnection('tcp://127.0.0.1:6381?role=master');
- $master
- ->expects($this->once())
- ->method('connect');
- $factory = $this->getMock('Predis\Connection\FactoryInterface');
- $factory
- ->expects($this->once())
- ->method('create')
- ->with(array(
- 'host' => '127.0.0.1',
- 'port' => '6381',
- 'role' => 'master',
- ))
- ->will($this->returnValue($master));
- $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory);
- $replication->connect();
- }
- /**
- * @group disconnected
- */
- public function testMethodDisconnectForcesDisconnectionOnAllConnectionsInPool()
- {
- $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?role=master');
- $master
- ->expects($this->once())
- ->method('disconnect');
- $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?role=slave');
- $slave2
- ->expects($this->once())
- ->method('disconnect');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->add($slave2);
- $replication->disconnect();
- }
- /**
- * @group disconnected
- */
- public function testMethodIsConnectedReturnConnectionStatusOfCurrentConnection()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
- $slave1
- ->expects($this->exactly(2))
- ->method('isConnected')
- ->will($this->onConsecutiveCalls(true, false));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($slave1);
- $this->assertFalse($replication->isConnected());
- $replication->connect();
- $this->assertTrue($replication->isConnected());
- $replication->getConnectionById('127.0.0.1:6382')->disconnect();
- $this->assertFalse($replication->isConnected());
- }
- /**
- * @group disconnected
- */
- public function testMethodGetConnectionByIdReturnsConnectionWhenFound()
- {
- $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($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $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 testMethodSwitchToSelectsCurrentConnection()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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?role=slave');
- $slave1
- ->expects($this->never())
- ->method('connect');
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6382?role=slave');
- $slave2
- ->expects($this->once())
- ->method('connect');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->add($slave2);
- $replication->switchTo($master);
- $this->assertSame($master, $replication->getCurrent());
- $replication->switchTo($slave2);
- $this->assertSame($slave2, $replication->getCurrent());
- }
- /**
- * @group disconnected
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage Invalid connection or connection not found.
- */
- public function testMethodSwitchToThrowsExceptionOnConnectionNotFound()
- {
- $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');
- $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($slave2);
- }
- /**
- * @group disconnected
- */
- public function testMethodSwitchToMasterSelectsCurrentConnectionToMaster()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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?role=slave');
- $slave1
- ->expects($this->never())
- ->method('connect');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->switchToMaster();
- $this->assertSame($master, $replication->getCurrent());
- }
- /**
- * @group disconnected
- */
- public function testMethodSwitchToSlaveSelectsCurrentConnectionToRandomSlave()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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?role=slave');
- $slave1
- ->expects($this->once())
- ->method('connect');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $replication->switchToSlave();
- $this->assertSame($slave1, $replication->getCurrent());
- }
- /**
- * @group disconnected
- */
- public function testGetConnectionByCommandReturnsMasterForWriteCommands()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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(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?role=slave');
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $this->assertSame($master, $replication->getConnectionByCommand(
- Command\RawCommand::create('set', 'key', 'value')
- ));
- $this->assertSame($master, $replication->getConnectionByCommand(
- Command\RawCommand::create('del', 'key')
- ));
- }
- /**
- * @group disconnected
- */
- public function testGetConnectionByCommandReturnsSlaveForReadOnlyCommands()
- {
- $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');
- $slave1
- ->expects($this->exactly(2))
- ->method('isConnected')
- ->will($this->onConsecutiveCalls(false, true));
- $slave1
- ->expects($this->at(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand('ROLE'))
- ->will($this->returnValue(array(
- 'slave', '127.0.0.1', 9000, 'connected', 3167038,
- )));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $this->assertSame($slave1, $replication->getConnectionByCommand(
- Command\RawCommand::create('get', 'key')
- ));
- $this->assertSame($slave1, $replication->getConnectionByCommand(
- Command\RawCommand::create('exists', 'key')
- ));
- }
- /**
- * @group disconnected
- */
- public function testGetConnectionByCommandSwitchesToMasterAfterWriteCommand()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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(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?role=slave');
- $slave1
- ->expects($this->exactly(1))
- ->method('isConnected')
- ->will($this->onConsecutiveCalls(false));
- $slave1
- ->expects($this->at(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand('ROLE'))
- ->will($this->returnValue(array(
- 'slave', '127.0.0.1', 9000, 'connected', 3167038,
- )));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $this->assertSame($slave1, $replication->getConnectionByCommand(
- Command\RawCommand::create('exists', 'key')
- ));
- $this->assertSame($master, $replication->getConnectionByCommand(
- Command\RawCommand::create('set', 'key', 'value')
- ));
- $this->assertSame($master, $replication->getConnectionByCommand(
- Command\RawCommand::create('get', 'key')
- ));
- }
- /**
- * @group disconnected
- * @expectedException Predis\Replication\RoleException
- * @expectedExceptionMessage Expected master but got slave [127.0.0.1:6381]
- */
- public function testGetConnectionByCommandThrowsExceptionOnNodeRoleMismatch()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand('ROLE'))
- ->will($this->returnValue(array(
- 'slave', '127.0.0.1', 9000, 'connected', 3167038,
- )));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->getConnectionByCommand(Command\RawCommand::create('del', 'key'));
- }
- /**
- * @group disconnected
- */
- public function testGetConnectionByCommandReturnsMasterForReadOnlyOperationsOnUnavailableSlaves()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->once())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('slaves', 'svc')
- ))
- ->will($this->returnValue(
- array(
- array(
- 'name', '127.0.0.1:6382',
- 'ip', '127.0.0.1',
- 'port', '6382',
- 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817',
- 'flags', 'slave,s_down,disconnected',
- 'master-host', '127.0.0.1',
- 'master-port', '6381',
- ),
- )
- ));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand('ROLE'))
- ->will($this->returnValue(array(
- 'master', '0', array(),
- )));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->getConnectionByCommand(Command\RawCommand::create('get', 'key'));
- }
- /**
- * @group disconnected
- */
- public function testMethodExecuteCommandSendsCommandToNodeAndReturnsResponse()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $cmdGet = Command\RawCommand::create('get', 'key');
- $cmdGetResponse = 'value';
- $cmdSet = Command\RawCommand::create('set', 'key', 'value');
- $cmdSetResponse = Response\Status::get('OK');
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SET', array('key', $cmdGetResponse)
- ))
- ->will($this->returnValue($cmdSetResponse));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'GET', array('key')
- ))
- ->will($this->returnValue($cmdGetResponse));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->add($slave1);
- $this->assertSame($cmdGetResponse, $replication->executeCommand($cmdGet));
- $this->assertSame($cmdSetResponse, $replication->executeCommand($cmdSet));
- }
- /**
- * @group disconnected
- */
- public function testMethodExecuteCommandRetriesReadOnlyCommandOnNextSlaveOnFailure()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('slaves', 'svc')
- ))
- ->will($this->returnValue(
- array(
- array(
- 'name', '127.0.0.1:6383',
- 'ip', '127.0.0.1',
- 'port', '6383',
- 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817',
- 'flags', 'slave',
- 'master-host', '127.0.0.1',
- 'master-port', '6381',
- ),
- )
- ));
- $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?role=slave');
- $slave1
- ->expects($this->any())
- ->method('isConnected')
- ->will($this->returnValue(true));
- $slave1
- ->expects($this->at(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'GET', array('key')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($slave1, 'Unknown connection error [127.0.0.1:6382]')
- ));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'GET', array('key')
- ))
- ->will($this->returnValue('value'));
- $factory = $this->getMock('Predis\Connection\FactoryInterface');
- $factory
- ->expects($this->once())
- ->method('create')
- ->with(array(
- 'host' => '127.0.0.1',
- 'port' => '6383',
- 'role' => 'slave',
- ))
- ->will($this->returnValue($slave2));
- $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory);
- $replication->add($master);
- $replication->add($slave1);
- $this->assertSame('value', $replication->executeCommand(
- Command\RawCommand::create('get', 'key')
- ));
- }
- /**
- * @group disconnected
- */
- public function testMethodExecuteCommandRetriesWriteCommandOnNewMasterOnFailure()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('get-master-addr-by-name', 'svc')
- ))
- ->will($this->returnValue(
- array('127.0.0.1', '6391')
- ));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'DEL', array('key')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]')
- ));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'DEL', array('key')
- ))
- ->will($this->returnValue(1));
- $factory = $this->getMock('Predis\Connection\FactoryInterface');
- $factory
- ->expects($this->once())
- ->method('create')
- ->with(array(
- 'host' => '127.0.0.1',
- 'port' => '6391',
- 'role' => 'master',
- ))
- ->will($this->returnValue($masterNew));
- $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory);
- $replication->add($masterOld);
- $this->assertSame(1, $replication->executeCommand(
- Command\RawCommand::create('del', 'key')
- ));
- }
- /**
- * @group disconnected
- * @expectedException Predis\Response\ServerException
- * @expectedExceptionMessage ERR No such master with that name
- */
- public function testMethodExecuteCommandThrowsExceptionOnUnknownServiceName()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('get-master-addr-by-name', 'svc')
- ))
- ->will($this->returnValue(null));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'DEL', array('key')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]')
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($masterOld);
- $replication->executeCommand(
- Command\RawCommand::create('del', 'key')
- );
- }
- /**
- * @group disconnected
- * @expectedException Predis\ClientException
- * @expectedExceptionMessage No sentinel server available for autodiscovery.
- */
- public function testMethodExecuteCommandThrowsExceptionOnConnectionFailureAndNoAvailableSentinels()
- {
- $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?role=sentinel');
- $sentinel1
- ->expects($this->any())
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'SENTINEL', array('get-master-addr-by-name', 'svc')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]')
- ));
- $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(3))
- ->method('executeCommand')
- ->with($this->isRedisCommand(
- 'DEL', array('key')
- ))
- ->will($this->throwException(
- new Connection\ConnectionException($master, 'Unknown connection error [127.0.0.1:6381]')
- ));
- $replication = $this->getReplicationConnection('svc', array($sentinel1));
- $replication->add($master);
- $replication->executeCommand(
- Command\RawCommand::create('del', 'key')
- );
- }
- /**
- * @group disconnected
- */
- public function testMethodGetReplicationStrategyReturnsInstance()
- {
- $strategy = new Replication\ReplicationStrategy();
- $factory = new Connection\Factory();
- $replication = new SentinelReplication(
- 'svc', array('tcp://127.0.0.1:5381?role=sentinel'), $factory, $strategy
- );
- $this->assertSame($strategy, $replication->getReplicationStrategy());
- }
- /**
- * @group disconnected
- */
- public function testMethodSerializeCanSerializeWholeObject()
- {
- $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');
- $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?role=slave');
- $strategy = new Replication\ReplicationStrategy();
- $factory = new Connection\Factory();
- $replication = new SentinelReplication('svc', array($sentinel1), $factory, $strategy);
- $replication->add($master);
- $replication->add($slave1);
- $replication->add($slave2);
- $unserialized = unserialize(serialize($replication));
- $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());
- }
- // ******************************************************************** //
- // ---- HELPER METHODS ------------------------------------------------ //
- // ******************************************************************** //
- /**
- * Creates a new instance of replication connection.
- *
- * @param string $service Name of the service
- * @param array $sentinels Array of sentinels
- * @param ConnectionFactoryInterface|null $factory Optional connection factory instance.
- *
- * @return SentinelReplication
- */
- protected function getReplicationConnection($service, $sentinels, Connection\FactoryInterface $factory = null)
- {
- $factory = $factory ?: new Connection\Factory();
- $replication = new SentinelReplication($service, $sentinels, $factory);
- $replication->setRetryWait(0);
- return $replication;
- }
- /**
- * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface.
- *
- * @param mixed $parameters Optional parameters.
- *
- * @return mixed
- */
- protected function getMockSentinelConnection($parameters = null)
- {
- $connection = $this->getMockConnection($parameters);
- return $connection;
- }
- }
|