-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a sorted set container type #3
base: master
Are you sure you want to change the base?
Changes from all commits
560089b
b7082cc
1a5e596
041b210
cba71ef
752a0d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
namespace PHPQueue\Backend; | ||
class PredisZsetTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $object; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
if (!class_exists('\Predis\Client')) { | ||
$this->markTestSkipped('Predis not installed'); | ||
} else { | ||
$options = array( | ||
'servers' => array('host' => '127.0.0.1', 'port' => 6379) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this go somewhere central? (It's repeated in a few places... Just a thought, may not be worth consolidating, tho...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I started documenting that as CoderKungfu#42 |
||
, 'queue' => 'testqueue-' . mt_rand() | ||
, 'score_key' => 'timestamp' | ||
, 'correlation_key' => 'txn_id' | ||
); | ||
$this->object = new Predis($options); | ||
} | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
if ($this->object) { | ||
$this->object->getConnection()->flushall(); | ||
} | ||
parent::tearDown(); | ||
} | ||
|
||
public function testSet() | ||
{ | ||
$key = 'A0001'; | ||
$data = array('name' => 'Michael', 'timestamp' => 1); | ||
$this->object->set($key, $data); | ||
|
||
$key = 'A0001'; | ||
$data = array('name' => 'Michael Cheng', 'timestamp' => 2); | ||
$this->object->set($key, $data); | ||
|
||
$key = 'A0002'; | ||
$data = array('name' => 'Michael Cheng', 'timestamp' => 3); | ||
$this->object->set($key, $data); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
$key = 'A0001'; | ||
$data1 = array('name' => 'Michael', 'timestamp' => 1); | ||
$this->object->set($key, $data1); | ||
|
||
$key = 'A0001'; | ||
$data2 = array('name' => 'Michael Cheng', 'timestamp' => 2); | ||
$this->object->set($key, $data2); | ||
|
||
$key = 'A0002'; | ||
$data3 = array('name' => 'Michael Cheng', 'timestamp' => 3); | ||
$this->object->set($key, $data3); | ||
|
||
$result = $this->object->get('A0001'); | ||
$this->assertEquals($data2, $result); | ||
|
||
$result = $this->object->getKey('A0002'); | ||
$this->assertEquals($data3, $result); | ||
} | ||
|
||
public function testClear() | ||
{ | ||
$key = 'A0002'; | ||
$data = array('name' => 'Adam Wight', 'timestamp' => 2718); | ||
$result = $this->object->set($key, $data); | ||
|
||
$result = $this->object->clear($key); | ||
$this->assertTrue($result); | ||
|
||
$result = $this->object->get($key); | ||
$this->assertNull($result); | ||
} | ||
|
||
public function testClearEmpty() | ||
{ | ||
$jobId = 'xxx'; | ||
$this->assertFalse($this->object->clear($jobId)); | ||
} | ||
|
||
public function testPushPop() | ||
{ | ||
$data = array( | ||
'name' => 'Weezle-' . mt_rand(), | ||
'timestamp' => mt_rand(), | ||
'txn_id' => mt_rand(), | ||
); | ||
$this->object->push($data); | ||
|
||
$this->assertEquals($data, $this->object->get($data['txn_id'])); | ||
|
||
$this->assertEquals($data, $this->object->pop()); | ||
|
||
$this->assertNull($this->object->get($data['txn_id'])); | ||
} | ||
|
||
public function testPopEmpty() | ||
{ | ||
$this->assertNull($this->object->pop()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!! Just a few minor comments:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about "score", I'm hiding that detail in favor of "order key" which should be more descriptive.