X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Flibs%2FHashRingTest.php;h=8ddb7c9960953361b175cc005128e26d586cadd9;hb=825d66bfa44c5dae2b78e2fe4f3b16f16aff4a12;hp=acaeb025585916bb41d0ad585e1844d6a126b734;hpb=925c20a9ca669c67cc44f4468d0e0f3b33b94213;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/libs/HashRingTest.php b/tests/phpunit/includes/libs/HashRingTest.php index acaeb02558..8ddb7c9960 100644 --- a/tests/phpunit/includes/libs/HashRingTest.php +++ b/tests/phpunit/includes/libs/HashRingTest.php @@ -24,6 +24,32 @@ class HashRingTest extends PHPUnit\Framework\TestCase { } } + public function testHashRingSingleLocation() { + // SHA-1 based and weighted + $ring = new HashRing( [ 's1' => 1 ], 'sha1' ); + + $this->assertEquals( + [ 's1' => 1 ], + $ring->getLocationWeights(), + 'Normalized location weights' + ); + + for ( $i = 0; $i < 5; $i++ ) { + $this->assertEquals( + 's1', + $ring->getLocation( "hello$i" ), + 'Items placed at proper locations' + ); + $this->assertEquals( + [ 's1' ], + $ring->getLocations( "hello$i", 2 ), + 'Items placed at proper locations' + ); + } + + $this->assertEquals( [], $ring->getLocations( "helloX", 0 ), "Limit of 0" ); + } + public function testHashRingMapping() { // SHA-1 based and weighted $ring = new HashRing( @@ -316,8 +342,8 @@ EOT; // Hash of known correct values from C code $this->assertEquals( - 'c69ac9eb7a8a630c0cded201cefeaace', - md5( $ketama_test( 1e5 ) ), + 'd1a4912a80e4654ec2e4e462c8b911c6', + md5( $ketama_test( 1e3 ) ), 'Ketama mode (large, MD5 check)' );