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