DistributionStrategyTestCase.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Distribution;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. abstract class DistributionStrategyTestCase extends StandardTestCase
  16. {
  17. /**
  18. * Returns a new instance of the tested distributor.
  19. *
  20. * @return Predis\Distribution\IDistributionStrategy
  21. */
  22. protected abstract function getDistributorInstance();
  23. /**
  24. * Returns a list of nodes from the hashring.
  25. *
  26. * @param IDistributionStrategy $ring Hashring instance.
  27. * @param int $iterations Number of nodes to fetch.
  28. * @return array Nodes from the hashring.
  29. */
  30. protected function getNodes(IDistributionStrategy $ring, $iterations = 10)
  31. {
  32. $nodes = array();
  33. for ($i = 0; $i < $iterations; $i++) {
  34. $key = $ring->generateKey($i * $i);
  35. $nodes[] = $ring->get($key);
  36. }
  37. return $nodes;
  38. }
  39. /**
  40. * @group disconnected
  41. */
  42. public function testEmptyRingThrowsException()
  43. {
  44. $this->setExpectedException('Predis\Distribution\EmptyRingException');
  45. $ring = $this->getDistributorInstance();
  46. $ring->get('nodekey');
  47. }
  48. /**
  49. * @group disconnected
  50. */
  51. public function testRemoveOnEmptyRingDoesNotThrowException()
  52. {
  53. $ring = $this->getDistributorInstance();
  54. $this->assertNull($ring->remove('node'));
  55. }
  56. }