SENTINEL_Test.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Command\Redis;
  11. /**
  12. * @group commands
  13. * @group realm-server
  14. */
  15. class SENTINEL_Test extends PredisCommandTestCase
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getExpectedCommand()
  21. {
  22. return 'Predis\Command\Redis\SENTINEL';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function getExpectedId()
  28. {
  29. return 'SENTINEL';
  30. }
  31. /**
  32. * @group disconnected
  33. */
  34. public function testFilterArguments()
  35. {
  36. $arguments = array('get-master-addr-by-name', 'predis:master');
  37. $expected = array('get-master-addr-by-name', 'predis:master');
  38. $command = $this->getCommandWithArgumentsArray($arguments);
  39. $this->assertSame($expected, $command->getArguments());
  40. }
  41. /**
  42. * @group disconnected
  43. */
  44. public function testParseResponse()
  45. {
  46. $expected = array('127.0.0.1', '6379');
  47. $command = $this->getCommand();
  48. $this->assertSame($expected, $command->parseResponse($expected));
  49. }
  50. /**
  51. * @group disconnected
  52. */
  53. public function testSentinelMastersResponse()
  54. {
  55. $response = array(
  56. array(
  57. 'name', 'predis:master',
  58. 'ip', '127.0.0.1',
  59. 'port', '6379',
  60. 'runid', '89f6128a7e5780aa6ef7d4d7022cfafbf799b3ab',
  61. 'flags', 'master',
  62. 'pending-commands', '0',
  63. 'last-ok-ping-reply', '386',
  64. 'last-ping-reply', '386',
  65. 'info-refresh', '9926',
  66. 'num-slaves', '1',
  67. 'num-other-sentinels', '0',
  68. 'quorum', '2',
  69. ),
  70. );
  71. $expected = array(
  72. array(
  73. 'name' => 'predis:master',
  74. 'ip' => '127.0.0.1',
  75. 'port' => '6379',
  76. 'runid' => '89f6128a7e5780aa6ef7d4d7022cfafbf799b3ab',
  77. 'flags' => 'master',
  78. 'pending-commands' => '0',
  79. 'last-ok-ping-reply' => '386',
  80. 'last-ping-reply' => '386',
  81. 'info-refresh' => '9926',
  82. 'num-slaves' => '1',
  83. 'num-other-sentinels' => '0',
  84. 'quorum' => '2',
  85. ),
  86. );
  87. $command = $this->getCommandWithArguments('masters');
  88. $this->assertSame($expected, $command->parseResponse($response));
  89. }
  90. /**
  91. * @group disconnected
  92. */
  93. public function testSentinelSlavesResponse()
  94. {
  95. $response = array(
  96. array(
  97. 'name', '127.0.0.1:6380',
  98. 'ip', '127.0.0.1',
  99. 'port', '6380',
  100. 'runid', '92aea60e4fead2507cccd6574e4c7139d401d0ae',
  101. 'flags', 'slave',
  102. 'pending-commands', '0',
  103. 'last-ok-ping-reply', '1011',
  104. 'last-ping-reply', '1011',
  105. 'info-refresh', '4366',
  106. 'master-link-down-time', '0',
  107. 'master-link-status', 'ok',
  108. 'master-host', '127.0.0.1',
  109. 'master-port', '6379',
  110. 'slave-priority', '100',
  111. ),
  112. );
  113. $expected = array(
  114. array(
  115. 'name' => '127.0.0.1:6380',
  116. 'ip' => '127.0.0.1',
  117. 'port' => '6380',
  118. 'runid' => '92aea60e4fead2507cccd6574e4c7139d401d0ae',
  119. 'flags' => 'slave',
  120. 'pending-commands' => '0',
  121. 'last-ok-ping-reply' => '1011',
  122. 'last-ping-reply' => '1011',
  123. 'info-refresh' => '4366',
  124. 'master-link-down-time' => '0',
  125. 'master-link-status' => 'ok',
  126. 'master-host' => '127.0.0.1',
  127. 'master-port' => '6379',
  128. 'slave-priority' => '100',
  129. ),
  130. );
  131. $command = $this->getCommandWithArguments('slaves', 'predis:master');
  132. $this->assertSame($expected, $command->parseResponse($response));
  133. }
  134. /**
  135. * @group disconnected
  136. */
  137. public function testSentinelIsMasterDownByAddr()
  138. {
  139. $response = array('0', '7388832d5fdee6a2e301d6bbc5052bd1526d741c');
  140. $expected = array('0', '7388832d5fdee6a2e301d6bbc5052bd1526d741c');
  141. $command = $this->getCommandWithArguments('is-master-down-by-addr', '127.0.0.1', '6379');
  142. $this->assertSame($expected, $command->parseResponse($response));
  143. }
  144. /**
  145. * @group disconnected
  146. */
  147. public function testSentinelGetMasterAddrByName()
  148. {
  149. $response = array('127.0.0.1', '6379');
  150. $expected = array('127.0.0.1', '6379');
  151. $command = $this->getCommandWithArguments('get-master-addr-by-name', 'predis:master');
  152. $this->assertSame($expected, $command->parseResponse($response));
  153. }
  154. /**
  155. * @group disconnected
  156. */
  157. public function testSentinelReset()
  158. {
  159. $response = 1;
  160. $expected = 1;
  161. $command = $this->getCommandWithArguments('reset', 'predis:*');
  162. $this->assertSame($expected, $command->parseResponse($response));
  163. }
  164. }