ServerSentinelTest.php 5.3 KB

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