Files
predis/tests/Predis/Distribution/HashRingTest.php
T
Daniele Alessandri dc14c29676 Rename certain namespaces, interfaces and classes.
Now we follow a Symfony2-like naming convention for namespaces, interfaces
and classes sticking with one clear rule.

- Renamed namespaces:

  - Predis\Network
  - Predis\Profiles
  - Predis\Iterators
  - Predis\Options
  - Predis\Commands
  - Predis\Commands\Processors

- Renamed interfaces:

  - Predis\IReplyObject
  - Predis\IRedisServerError
  - Predis\IConnectionFactory
  - Predis\IConnectionParameters
  - Predis\Options\IOption
  - Predis\Options\IClientOptions
  - Predis\Profile\IServerProfile
  - Predis\Pipeline\IPipelineExecutor
  - Predis\Distribution\INodeKeyGenerator
  - Predis\Distribution\IDistributionStrategy
  - Predis\Protocol\IProtocolProcessor
  - Predis\Protocol\IResponseReader
  - Predis\Protocol\IResponseHandler
  - Predis\Protocol\ICommandSerializer
  - Predis\Protocol\IComposableProtocolProcessor
  - Predis\Network\IConnection
  - Predis\Network\IConnectionSingle
  - Predis\Network\IConnectionComposable
  - Predis\Network\IConnectionCluster
  - Predis\Network\IConnectionReplication
  - Predis\Commands\ICommand
  - Predis\Commands\IPrefixable
  - Predis\Command\Processor\ICommandProcessor
  - Predis\Command\Processor\ICommandProcessorChain
  - Predis\Command\Processor\IProcessingSupport

- Renamed Classes:

  - Predis\Commands\Command
  - Predis\Network\ConnectionBase

- Classes moved to different namespaces:

  - Predis\MonitorContext

Meh
2012-01-31 18:19:18 +01:00

133 lines
3.1 KiB
PHP

<?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\Distribution;
/**
* @todo To be improved.
*/
class HashRingTest extends DistributionStrategyTestCase
{
/**
* {@inheritdoc}
*/
public function getDistributorInstance()
{
return new HashRing();
}
/**
* @group disconnected
*/
public function testHash()
{
$ring = $this->getDistributorInstance();
$this->assertEquals(crc32('foobar'), $ring->hash('foobar'));
}
/**
* @group disconnected
*/
public function testSingleNodeInRing()
{
$node = '127.0.0.1:7000';
$ring = $this->getDistributorInstance();
$ring->add($node);
$expected = array_fill(0, 20, $node);
$actual = $this->getNodes($ring, 20);
$this->assertSame($expected, $actual);
}
/**
* @group disconnected
*/
public function testMultipleNodesInRing()
{
$nodes = array(
'127.0.0.1:7000',
'127.0.0.1:7001',
'127.0.0.1:7002',
);
$ring = $this->getDistributorInstance();
foreach ($nodes as $node) {
$ring->add($node);
}
$expected = array(
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7002',
'127.0.0.1:7002',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7000',
'127.0.0.1:7001',
'127.0.0.1:7002',
'127.0.0.1:7002',
'127.0.0.1:7002',
'127.0.0.1:7002',
'127.0.0.1:7000',
'127.0.0.1:7002',
'127.0.0.1:7002',
'127.0.0.1:7002',
'127.0.0.1:7000',
'127.0.0.1:7001',
'127.0.0.1:7002',
);
$actual = $this->getNodes($ring, 20);
$this->assertSame($expected, $actual);
}
/**
* @group disconnected
*/
public function testSubsequendAddAndRemoveFromRing()
{
$ring = $this->getDistributorInstance();
$expected1 = array_fill(0, 10, '127.0.0.1:7000');
$expected3 = array_fill(0, 10, '127.0.0.1:7001');
$expected2 = array(
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7001',
'127.0.0.1:7000',
'127.0.0.1:7001',
'127.0.0.1:7000',
);
$ring->add('127.0.0.1:7000');
$actual1 = $this->getNodes($ring, 10);
$ring->add('127.0.0.1:7001');
$actual2 = $this->getNodes($ring, 10);
$ring->remove('127.0.0.1:7000');
$actual3 = $this->getNodes($ring, 10);
$this->assertSame($expected1, $actual1);
$this->assertSame($expected2, $actual2);
$this->assertSame($expected3, $actual3);
}
}