コード例 #1
0
ファイル: BenchmarkTest.php プロジェクト: tguyard/flexihash
 public function testHashDistributionWithCrc32Hasher()
 {
     $hashSpace = new Flexihash(new Crc32Hasher());
     foreach (range(1, $this->_targets) as $i) {
         $hashSpace->addTarget("target{$i}");
     }
     $results = array();
     foreach (range(1, $this->_lookups) as $i) {
         $results[$i] = $hashSpace->lookup("t{$i}");
     }
     $distribution = array();
     foreach ($hashSpace->getAllTargets() as $target) {
         $distribution[$target] = count(array_keys($results, $target));
     }
     echo sprintf("\nDistribution of %d lookups per target (min/max/median/avg): %d/%d/%d/%d \n", $this->_lookups / $this->_targets, min($distribution), max($distribution), round($this->_median($distribution)), round(array_sum($distribution) / count($distribution)));
 }
コード例 #2
0
ファイル: FlexihashTest.php プロジェクト: lcwxz1989/flexihash
 /**
  * Does the __toString method behave as we expect.
  *
  * @author Dom Morgan <*****@*****.**>
  */
 public function testHashSpaceToString()
 {
     $mockHasher = new MockHasher();
     $hashSpace = new Flexihash($mockHasher, 1);
     $hashSpace->addTarget('t1');
     $hashSpace->addTarget('t2');
     $this->assertSame($hashSpace->__toString(), 'Flexihash\\Flexihash{targets:[t1,t2]}');
 }
コード例 #3
0
ファイル: FlexihashTest.php プロジェクト: tguyard/flexihash
 public function testFallbackPrecedenceWhenServerRemoved()
 {
     $mockHasher = new MockHasher();
     $hashSpace = new Flexihash($mockHasher, 1);
     $mockHasher->setHashValue(10);
     $hashSpace->addTarget("t1");
     $mockHasher->setHashValue(20);
     $hashSpace->addTarget("t2");
     $mockHasher->setHashValue(30);
     $hashSpace->addTarget("t3");
     $mockHasher->setHashValue(15);
     $this->assertEquals($hashSpace->lookup('resource'), 't2');
     $this->assertEquals($hashSpace->lookupList('resource', 3), array('t2', 't3', 't1'));
     $hashSpace->removeTarget('t2');
     $this->assertEquals($hashSpace->lookup('resource'), 't3');
     $this->assertEquals($hashSpace->lookupList('resource', 3), array('t3', 't1'));
     $hashSpace->removeTarget('t3');
     $this->assertEquals($hashSpace->lookup('resource'), 't1');
     $this->assertEquals($hashSpace->lookupList('resource', 3), array('t1'));
 }