public function testLookupHandler() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $handle = '4b336e15-cac0-3307-8b81-f1de26e6c383'; $event = new QueueLookupEvent($handle); $handler->onLookup($event); $this->assertInstanceOf('LaterJob\\Model\\Queue\\Storage', $event->getResult()); $this->assertEquals('4b336e15-cac0-3307-8b81-f1de26e6c383', $event->getResult()->getJobId()); }
public function testReceiveHandlerDB() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $added = new DateTime('1st November 2013 01:20:00'); # create the transition $event = new QueuePurgeEvent($added); $handler->onPurge($event); $this->assertEquals(4, $event->getResult()); # assert save result set matches $resulting_table = $this->getConnection()->createQueryTable("later_job_queue", "SELECT * FROM later_job_queue ORDER BY dte_add"); $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "purge_handler_result.xml")->getTable("later_job_queue"); $this->assertTablesEqual($expected_table, $resulting_table); }
public function testUnlockHandler() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $now = new DateTime('1-11-2013 13:30:00'); $timeout = new DateTime('1-11-2013 15:00:00'); $handle = '550e8400-e29b-41d4-a716-446655440000'; $limit = 10; $event = new QueueLockEvent($handle, $timeout, $limit, $now); $handler->onUnlock($event); $resulting_table = $this->getConnection()->createQueryTable("later_job_queue", "SELECT * FROM later_job_queue ORDER BY dte_add ASC"); $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "unlock_handler_result.xml")->getTable("later_job_queue"); $this->assertTablesEqual($expected_table, $resulting_table); }
public function testReceiveHandlerDB() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $uuid = new UUID(new MersenneRandom(10000)); $job_name = 'test_job_1'; $added = new DateTime('01-01-2014 00:00:00'); # create the transition $storage = new Storage(); $jobID = $uuid->v3($uuid->v4(), $job_name); $storage->setJobId($jobID); $storage->setDateAdded($added); $storage->setJobData(new \stdClass()); $storage->setState(QueueConfig::STATE_ADD); $storage->setRetryLeft(3); $event = new QueueReceiveEvent($storage); $handler->onReceive($event); # assert save result set matches $resulting_table = $this->getConnection()->createQueryTable("later_job_queue", "SELECT * FROM later_job_queue ORDER BY dte_add"); $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "receive_handler_result.xml")->getTable("later_job_queue"); $this->assertTablesEqual($expected_table, $resulting_table); }
public function testRemoveHandlerDB() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $uuid = new UUID(new MersenneRandom(10000)); $job_name = 'test_job_1'; $added = new DateTime('01-01-2014 00:00:00'); # remove unlocked job $event = new QueueRemoveEvent('2fcbcfc4-6a5c-3498-8095-763c4c965cf7', $added); $handler->onRemove($event); # remove job with lock but expired $event = new QueueRemoveEvent('d420407f-6ff3-3a0d-9e0f-c142cf02f931', new DateTime('01-11-2013 16:00:00')); $handler->onRemove($event); # assert save result set matches $resulting_table = $this->getConnection()->createQueryTable("later_job_queue", "SELECT * FROM later_job_queue ORDER BY dte_add"); $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "remove_handler_result.xml")->getTable("later_job_queue"); $this->assertTablesEqual($expected_table, $resulting_table); }
public function testBeforeAndAfter() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $before = new DateTime('2013-11-01 01:35:00'); $after = new DateTime('2013-11-01 01:00:00'); $event = new QueueListEvent(0, 10, null, null, $before, $after); $handler->onList($event); $results = $event->getResult(); $this->assertEquals(7, count($results)); }
public function testSendHandlerNoReturn() { $gateway = $this->getTableGateway(); $handler = new QueueSubscriber($gateway); $now = new DateTime('1-11-2013 13:36:00'); # only pickup 2 locked error jobs from 3 available $limit = 10; $send_event = new QueueSendEvent('41d4-a716-446655440000', $now); $handler->onSend($send_event); $this->assertNull($send_event->getResult()); }