6 class HashRingTest
extends MediaWikiTestCase
{
7 function testHashRing() {
8 $ring = new HashRing( array( 's1' => 1, 's2' => 1, 's3' => 2, 's4' => 2, 's5' => 2, 's6' => 3 ) );
11 for ( $i = 0; $i < 20; $i++
) {
12 $locations[ "hello$i"] = $ring->getLocation( "hello$i" );
14 $expectedLocations = array(
37 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );
40 for ( $i = 0; $i < 5; $i++
) {
41 $locations[ "hello$i"] = $ring->getLocations( "hello$i", 2 );
44 $expectedLocations = array(
45 "hello0" => array( "s5", "s6" ),
46 "hello1" => array( "s6", "s4" ),
47 "hello2" => array( "s2", "s1" ),
48 "hello3" => array( "s5", "s6" ),
49 "hello4" => array( "s6", "s4" ),
51 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' );