QueueUnitTestCase.php in Redis 7.3
File
lib/Redis/Tests/Queue/QueueUnitTestCase.php
View source
<?php
abstract class Redis_Tests_Queue_QueueUnitTestCase extends Redis_Tests_AbstractUnitTestCase {
public $queue;
public $name;
public function setUp() {
parent::setUp();
module_load_include('inc', 'system', 'system.queue');
$this->name = 'redis-queue-test-' . time();
$this->queue = new Redis_Queue($this->name);
}
public function tearDown() {
$this->queue
->deleteQueue();
$this->name = null;
parent::tearDown();
}
public function testCreate() {
$res = $this->queue
->createItem('test-queue-item-create');
$num = $this->queue
->numberOfItems();
$this
->assertEqual(1, $num);
}
public function testClaim() {
$data = 'test-queue-item-claimed';
$res = $this->queue
->createItem($data);
$item = $this->queue
->claimItem();
$this
->assertEqual($data, $item->data);
}
public function testRelease() {
$data = 'test-queue-item';
$res = $this->queue
->createItem($data);
$item = $this->queue
->claimItem();
$num = $this->queue
->numberOfItems();
$this
->assertEqual(0, $num);
$res = $this->queue
->releaseItem($item);
$num = $this->queue
->numberOfItems();
$this
->assertEqual(1, $num);
}
public function testOrder() {
$keys = array(
'test1',
'test2',
'test3',
);
foreach ($keys as $k) {
$this->queue
->createItem($k);
}
$first = $this->queue
->claimItem();
$this
->assertEqual($first->data, $keys[0]);
$second = $this->queue
->claimItem();
$this
->assertEqual($second->data, $keys[1]);
$this->queue
->releaseItem($first);
$third = $this->queue
->claimItem();
$this
->assertEqual($third->data, $keys[2]);
$first_again = $this->queue
->claimItem();
$this
->assertEqual($first_again->data, $keys[0]);
$num = $this->queue
->numberOfItems();
$this
->assertEqual(0, $num);
}
}