public function testOnMonitorQueryAllRows() { $transition_gateway = $this->getTransitionTableGateway(); $monitor_gateway = $this->getMonitorTableGateway(); $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway); $limit = 30; $offset = 0; $event = new MonitoringQueryEvent($offset, $limit, 'DESC', null, null, true); # run the event $handler->onMonitorQuery($event); # test the results $results = $event->getResult(); $result = $event->getResult(); # 24 results 2 which are locked, using locked = false # should exclude them from result set $this->assertEquals(24, count($result)); $this->assertEquals(24, $result[0]->getMonitorId()); }
public function testOnMonitorCommit() { $date = new DateTime('10-12-2012 01:00:00'); $transition_gateway = $this->getTransitionTableGateway(); $monitor_gateway = $this->getMonitorTableGateway(); $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway); $stats = new Stats(); $event = new MonitoringEvent($stats); $stats->setMonitorDate($date); $stats->setWorkerMaxThroughput(50); $stats->setMonitorId(1); $stats->setQueueJobsAdded(100); $stats->setQueueJobsFailed(2); $stats->setQueueJobsCompleted(53); $stats->setQueueJobsProcessing(56); $stats->setQueueJobsError(5); $stats->setJobMinServiceTime(8038); $stats->setJobMaxServiceTime(10439); $stats->setJobMeanServiceTime(9244); $stats->setWorkerMaxTime(495); $stats->setWorkerMinTime(459); $stats->setWorkerMeanTime(482); $stats->setWorkerMeanThroughput(27); $stats->setWorkerMeanUtilization(0.55); $handler->onMonitorCommit($event); $resulting_table = $this->getConnection()->createQueryTable("later_job_monitor", "SELECT * FROM later_job_monitor LIMIT 1"); $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "commit_handler_result.xml")->getTable("later_job_monitor"); $this->assertEquals(true, $event->getResult()); $this->assertTablesEqual($expected_table, $resulting_table); }
/** * @expectedException LaterJob\Exception * @expectedExceptionMessage SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2012-11-27 13:00:00' for key */ public function testOnMonitorLockAlreadyHasException() { $date = new DateTime('27-11-2012 13:00:00'); $transition_gateway = $this->getTransitionTableGateway(); $monitor_gateway = $this->getMonitorTableGateway(); $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway); # create stats container for results of the monitoring event $stats = new Stats(); $stats->setMonitorDate($date); $stats->setWorkerMaxThroughput(50); $stats_repeat = new Stats(); $stats_repeat->setMonitorDate($date); $stats_repeat->setWorkerMaxThroughput(50); # create event object to pass to handle $event = new MonitoringEvent($stats); $event->setInterval('+ 5 hours'); $event_repeat = new MonitoringEvent($stats_repeat); $event_repeat->setInterval('+ 5 hours'); # first call work as normal $handler->onMonitorLock($event); $this->assertTrue($event->getResult()); $this->assertEquals(1, $event->getStats()->getMonitorId(1)); # lock in place should FAIL $handler->onMonitorLock($event_repeat); }
public function testOnMonitorLock() { $date = new DateTime('10-12-2012 01:00:00'); $transition_gateway = $this->getTransitionTableGateway(); $monitor_gateway = $this->getMonitorTableGateway(); $handler = new MonitorSubscriber($monitor_gateway, $transition_gateway); $stats = new Stats(); $event = new MonitoringEvent($stats); $stats->setMonitorDate($date); $handler->onMonitorLock($event); $resulting_table = $this->getConnection()->createQueryTable("later_job_monitor", "SELECT * FROM later_job_monitor LIMIT 1"); $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "lock_handler_result.xml")->getTable("later_job_monitor"); $this->assertEquals(true, $event->getResult()); $this->assertTablesEqual($expected_table, $resulting_table); }