Skip to content

Commit 67c6417

Browse files
committed
Added unit test for key distribution function.
1 parent 8f5783c commit 67c6417

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/array-tests.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ public function testKeyLocality() {
9393
$this->checkCommonLocality();
9494
}
9595

96+
public function customDistributor($key)
97+
{
98+
$a = unpack("N*", md5($key, true));;
99+
global $newRing;
100+
$pos = $a[1] % count($newRing);
101+
102+
return $pos;
103+
}
104+
105+
public function testKeyDistributor()
106+
{
107+
global $newRing, $useIndex;
108+
$this->ra = new RedisArray($newRing, array(
109+
'index' => $useIndex,
110+
'function' => 'custom_hash',
111+
'distributor' => array($this, "customDistributor")));
112+
113+
// custom key distribution function.
114+
$this->addData('fb'.rand());
115+
116+
// check that they're all on the expected node.
117+
$lastNode = NULL;
118+
foreach($this->data as $k => $v) {
119+
$node = $this->ra->_target($k);
120+
$pos = $this->customDistributor($k);
121+
$this->assertTrue($node === $newRing[$pos]);
122+
}
123+
}
124+
96125
}
97126

98127
class Redis_Rehashing_Test extends TestSuite

0 commit comments

Comments
 (0)