MediaWiki
REL1_24
|
00001 <?php 00002 00006 class HashRingTest extends MediaWikiTestCase { 00010 public function testHashRing() { 00011 $ring = new HashRing( array( 's1' => 1, 's2' => 1, 's3' => 2, 's4' => 2, 's5' => 2, 's6' => 3 ) ); 00012 00013 $locations = array(); 00014 for ( $i = 0; $i < 20; $i++ ) { 00015 $locations[ "hello$i"] = $ring->getLocation( "hello$i" ); 00016 } 00017 $expectedLocations = array( 00018 "hello0" => "s5", 00019 "hello1" => "s6", 00020 "hello2" => "s2", 00021 "hello3" => "s5", 00022 "hello4" => "s6", 00023 "hello5" => "s4", 00024 "hello6" => "s5", 00025 "hello7" => "s4", 00026 "hello8" => "s5", 00027 "hello9" => "s5", 00028 "hello10" => "s3", 00029 "hello11" => "s6", 00030 "hello12" => "s1", 00031 "hello13" => "s3", 00032 "hello14" => "s3", 00033 "hello15" => "s5", 00034 "hello16" => "s4", 00035 "hello17" => "s6", 00036 "hello18" => "s6", 00037 "hello19" => "s3" 00038 ); 00039 00040 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' ); 00041 00042 $locations = array(); 00043 for ( $i = 0; $i < 5; $i++ ) { 00044 $locations[ "hello$i"] = $ring->getLocations( "hello$i", 2 ); 00045 } 00046 00047 $expectedLocations = array( 00048 "hello0" => array( "s5", "s6" ), 00049 "hello1" => array( "s6", "s4" ), 00050 "hello2" => array( "s2", "s1" ), 00051 "hello3" => array( "s5", "s6" ), 00052 "hello4" => array( "s6", "s4" ), 00053 ); 00054 $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' ); 00055 } 00056 }