PhpiredisStreamConnectionTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\Connection;
  11. /**
  12. * @group ext-phpiredis
  13. * @requires extension phpiredis
  14. */
  15. class PhpiredisStreamConnectionTest extends PredisConnectionTestCase
  16. {
  17. const CONNECTION_CLASS = 'Predis\Connection\PhpiredisStreamConnection';
  18. // ******************************************************************** //
  19. // ---- INTEGRATION TESTS --------------------------------------------- //
  20. // ******************************************************************** //
  21. /**
  22. * @group connected
  23. * @group slow
  24. * @requires PHP 5.4
  25. * @expectedException \Predis\Connection\ConnectionException
  26. */
  27. public function testThrowsExceptionOnReadWriteTimeout()
  28. {
  29. $profile = $this->getCurrentProfile();
  30. $connection = $this->createConnectionWithParams(array(
  31. 'read_write_timeout' => 0.5,
  32. ), true);
  33. $connection->executeCommand($profile->createCommand('brpop', array('foo', 3)));
  34. }
  35. /**
  36. * @medium
  37. * @group connected
  38. * @expectedException \Predis\Protocol\ProtocolException
  39. */
  40. public function testThrowsExceptionOnProtocolDesynchronizationErrors()
  41. {
  42. $connection = $this->createConnection();
  43. $stream = $connection->getResource();
  44. $connection->writeRequest($this->getCurrentProfile()->createCommand('ping'));
  45. stream_socket_recvfrom($stream, 1);
  46. $connection->read();
  47. }
  48. /**
  49. * @group connected
  50. * @requires PHP 5.4
  51. */
  52. public function testPersistentParameterWithFalseLikeValues()
  53. {
  54. $connection1 = $this->createConnectionWithParams(array('persistent' => 0));
  55. $this->assertNonPersistentConnection($connection1);
  56. $connection2 = $this->createConnectionWithParams(array('persistent' => false));
  57. $this->assertNonPersistentConnection($connection2);
  58. $connection3 = $this->createConnectionWithParams(array('persistent' => '0'));
  59. $this->assertNonPersistentConnection($connection3);
  60. $connection4 = $this->createConnectionWithParams(array('persistent' => 'false'));
  61. $this->assertNonPersistentConnection($connection4);
  62. }
  63. /**
  64. * @group connected
  65. * @requires PHP 5.4
  66. */
  67. public function testPersistentParameterWithTrueLikeValues()
  68. {
  69. $connection1 = $this->createConnectionWithParams(array('persistent' => 1));
  70. $this->assertPersistentConnection($connection1);
  71. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  72. $this->assertPersistentConnection($connection2);
  73. $connection3 = $this->createConnectionWithParams(array('persistent' => '1'));
  74. $this->assertPersistentConnection($connection3);
  75. $connection4 = $this->createConnectionWithParams(array('persistent' => 'true'));
  76. $this->assertPersistentConnection($connection4);
  77. $connection1->disconnect();
  78. }
  79. /**
  80. * @group connected
  81. * @requires PHP 5.4
  82. */
  83. public function testPersistentConnectionsToSameNodeShareResource()
  84. {
  85. $connection1 = $this->createConnectionWithParams(array('persistent' => true));
  86. $connection2 = $this->createConnectionWithParams(array('persistent' => true));
  87. $this->assertPersistentConnection($connection1);
  88. $this->assertPersistentConnection($connection2);
  89. $this->assertSame($connection1->getResource(), $connection2->getResource());
  90. $connection1->disconnect();
  91. }
  92. /**
  93. * @group connected
  94. * @requires PHP 5.4
  95. */
  96. public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID()
  97. {
  98. $connection1 = $this->createConnectionWithParams(array('persistent' => 'conn1'));
  99. $connection2 = $this->createConnectionWithParams(array('persistent' => 'conn2'));
  100. $this->assertPersistentConnection($connection1);
  101. $this->assertPersistentConnection($connection2);
  102. $this->assertNotSame($connection1->getResource(), $connection2->getResource());
  103. }
  104. }