2013-05-15 18:16:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group HashRing
|
|
|
|
|
*/
|
2014-12-30 04:53:24 +00:00
|
|
|
class HashRingTest extends PHPUnit_Framework_TestCase {
|
2013-10-24 10:54:02 +00:00
|
|
|
/**
|
|
|
|
|
* @covers HashRing
|
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testHashRing() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$ring = new HashRing( [ 's1' => 1, 's2' => 1, 's3' => 2, 's4' => 2, 's5' => 2, 's6' => 3 ] );
|
2013-05-15 18:16:16 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$locations = [];
|
2013-05-17 14:47:00 +00:00
|
|
|
for ( $i = 0; $i < 20; $i++ ) {
|
2013-05-15 18:16:16 +00:00
|
|
|
$locations[ "hello$i"] = $ring->getLocation( "hello$i" );
|
|
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$expectedLocations = [
|
2013-05-15 18:16:16 +00:00
|
|
|
"hello0" => "s5",
|
|
|
|
|
"hello1" => "s6",
|
|
|
|
|
"hello2" => "s2",
|
|
|
|
|
"hello3" => "s5",
|
|
|
|
|
"hello4" => "s6",
|
|
|
|
|
"hello5" => "s4",
|
|
|
|
|
"hello6" => "s5",
|
|
|
|
|
"hello7" => "s4",
|
|
|
|
|
"hello8" => "s5",
|
|
|
|
|
"hello9" => "s5",
|
|
|
|
|
"hello10" => "s3",
|
|
|
|
|
"hello11" => "s6",
|
|
|
|
|
"hello12" => "s1",
|
|
|
|
|
"hello13" => "s3",
|
|
|
|
|
"hello14" => "s3",
|
|
|
|
|
"hello15" => "s5",
|
|
|
|
|
"hello16" => "s4",
|
|
|
|
|
"hello17" => "s6",
|
|
|
|
|
"hello18" => "s6",
|
|
|
|
|
"hello19" => "s3"
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-05-15 18:16:16 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$locations = [];
|
2013-05-17 14:47:00 +00:00
|
|
|
for ( $i = 0; $i < 5; $i++ ) {
|
2013-05-15 18:16:16 +00:00
|
|
|
$locations[ "hello$i"] = $ring->getLocations( "hello$i", 2 );
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$expectedLocations = [
|
|
|
|
|
"hello0" => [ "s5", "s6" ],
|
|
|
|
|
"hello1" => [ "s6", "s4" ],
|
|
|
|
|
"hello2" => [ "s2", "s1" ],
|
|
|
|
|
"hello3" => [ "s5", "s6" ],
|
|
|
|
|
"hello4" => [ "s6", "s4" ],
|
|
|
|
|
];
|
2013-05-15 18:16:16 +00:00
|
|
|
$this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
|
|
|
|
|
}
|
|
|
|
|
}
|