public function testFailSendNotification() { $this->createJob(Opus_Job_Worker_MailNotification::LABEL, array('subject' => 'SendNotification Test', 'message' => 'This is a test message generated in ' . __FILE__, 'users' => '')); $this->executeScript('cron-send-notification.php'); $failedJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_MailNotification::LABEL), null, Opus_Job::STATE_FAILED); $this->assertEquals(1, count($failedJobs), 'Expected one failed job in queue'); }
public function testJobFailsIfInvalidTask() { $this->createJob(Opus_Job_Worker_IndexOpusDocument::LABEL, array('documentId' => $this->document->getId(), 'task' => 'do-the-unexpected')); $this->executeScript('cron-solr-update.php'); $allJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_IndexOpusDocument::LABEL), null, Opus_Job::STATE_FAILED); $this->assertEquals(1, count($allJobs), 'Expected one failed job in queue'); }
protected function tearDown() { if (!is_null($this->config)) { Zend_Registry::set('Zend_Config', $this->config); } // Cleanup of Log File $config = Zend_Registry::get('Zend_Config'); $filename = $config->workspacePath . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'opus_consistency-check.log'; if (file_exists($filename)) { unlink($filename); } // Cleanup of Lock File if (file_exists($filename . '.lock')) { unlink($filename . '.lock'); } // Cleanup of Jobs Table $jobs = Opus_Job::getByLabels(array(Opus_Job_Worker_ConsistencyCheck::LABEL)); foreach ($jobs as $job) { try { $job->delete(); } catch (Exception $e) { // ignore } } parent::tearDown(); }
public function detailAction() { $this->view->state = $this->_request->getParam('state'); $this->view->label = $this->_request->getParam('label'); if (empty($this->view->state) || empty($this->view->label)) { throw new Application_Exception('Invalid arguments'); } $this->view->jobs = Opus_Job::getByLabels(array($this->view->label), null, $this->view->state); }
/** * TODO fix for Solr Update */ public function testJobSuccessWithInconsistency() { $service = Opus_Search_Service::selectIndexingService(null, 'solr'); $service->removeAllDocumentsFromIndex(); $this->createJob(Opus_Job_Worker_ConsistencyCheck::LABEL); $this->executeScript('cron-check-consistency.php'); $allJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_ConsistencyCheck::LABEL), null, Opus_Job::STATE_UNDEFINED); $this->assertTrue(empty($allJobs), 'Expected no more jobs in queue: found ' . count($allJobs) . ' jobs'); $failedJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_ConsistencyCheck::LABEL), null, Opus_Job::STATE_FAILED); $this->assertTrue(empty($failedJobs), 'Expected no failed jobs in queue: found ' . count($failedJobs) . ' jobs'); $logPath = parent::$scriptPath . '/../../workspace/log/'; $this->assertFileExists($logPath . 'opus_consistency-check.log', 'Logfile opus_consistency-check.log does not exist'); $this->assertFileNotExists($logPath . 'opus_consistency-check.log.lock', 'Lockfile opus_consistency-check.log.lock was not removed'); $publishedDocsCount = $this->getPublishedDocumentCount(); $contents = file_get_contents($logPath . 'opus_consistency-check.log'); $this->assertFalse(strpos($contents, 'checking ' . $publishedDocsCount . ' published documents for consistency.') === false, "Logfile opus_consistency-check.log does not contain 'checking ' . {$publishedDocsCount}\n . ' ...' [{$contents}]."); $this->assertFalse(strpos($contents, 'inconsistency found for document 1: document is in database, but is not in Solr index.') === false, 'Logfile opus_consistency-check.log does not contain "inconsistency found for document 1: ...".'); $this->assertFalse(strpos($contents, 'inconsistency found for document 200: document is in database, but is not in Solr index.') === false, 'Logfile opus_consistency-check.log does not contain "inconsistency found for document 200: ...".'); $this->assertFalse(strpos($contents, $publishedDocsCount . ' inconsistencies were detected: ' . $publishedDocsCount . ' of them were resolved.') === false, 'Logfile opus_consistency-check.log does not contain "' . $publishedDocsCount . ' inconsistencies ...".'); $this->assertFalse(strpos($contents, 'number of updates: ' . $publishedDocsCount) === false, 'Logfile opus_consistency-check.log does not contain "number of updates: ' . $publishedDocsCount . '".'); $this->assertFalse(strpos($contents, 'number of deletions: 0') === false, 'Logfile opus_consistency-check.log does not contain "number of deletions: 0".'); $this->assertFalse(strpos($contents, 'Completed operation after') === false, 'Logfile opus_consistency-check.log does not contain "Completed operation after".'); unlink($logPath . 'opus_consistency-check.log'); }
public function testCheckconsistencyActionResult() { $this->enableAsyncIndexmaintenanceMode(); $this->assertEquals(0, Opus_Job::getCountForLabel(Opus_Job_Worker_ConsistencyCheck::LABEL), 'missing cleanup of jobs table'); $this->getRequest()->setMethod('POST'); $this->dispatch('/admin/indexmaintenance/checkconsistency'); $this->assertResponseCode(302); $this->assertResponseLocationHeader($this->getResponse(), '/admin/indexmaintenance'); $this->assertEquals(1, Opus_Job::getCountForLabel(Opus_Job_Worker_ConsistencyCheck::LABEL), 'consistency check job was not stored in database'); /* * check if job was scheduled for execution */ $this->resetResponse(); $this->resetRequest(); $this->dispatch('/admin/indexmaintenance/index'); $this->assertResponseCode(200, 'foo'); $baseUrl = $this->getRequest()->getBaseUrl(); $body = $this->getResponse()->getBody(); $this->assertContains('div class="opprogress"', $body); $this->assertNotContains("action=\"{$baseUrl}/admin/indexmaintenance/checkconsistency\"", $body); // TODO $this->assertContains("action=\"$baseUrl/admin/indexmaintenance/checkfulltexts\"", $body); // TODO $this->assertContains("action=\"$baseUrl/admin/indexmaintenance/optimizeindex\"", $body); /* * run job immediately and check for result */ $jobrunner = new Opus_Job_Runner(); $jobrunner->setLogger(Zend_Registry::get('Zend_Log')); $worker = new Opus_Job_Worker_ConsistencyCheck(); $jobrunner->registerWorker($worker); $jobrunner->run(); $jobs = Opus_Job::getByLabels(array(Opus_Job_Worker_ConsistencyCheck::LABEL)); if (count($jobs) > 0) { $job = $jobs[0]; $message = 'at least one unexpected job found (Label: \'%s\', State: \'%s\', Data: \'%s\', Errors: \'%s\\, SHA1 Hash: \'%s\')'; $label = $job->getLabel(); $state = $job->getState(); $data = $job->getData(); $errors = $job->getErrors(); $hash = $job->getSha1Id(); $this->fail(sprintf($message, $label, $state, $data, $errors, $hash)); } $this->assertEquals(0, Opus_Job::getCountForLabel(Opus_Job_Worker_ConsistencyCheck::LABEL), 'consistency check job was not removed from database after execution'); $this->resetResponse(); $this->resetRequest(); $this->dispatch('/admin/indexmaintenance/index'); $this->assertResponseCode(200, 'bar'); $baseUrl = $this->getRequest()->getBaseUrl(); $body = $this->getResponse()->getBody(); $this->assertNotContains('div class="opprogress"', $body); $this->assertContains('pre class="opoutput"', $body); $this->assertContains("action=\"{$baseUrl}/admin/indexmaintenance/checkconsistency\"", $body); // TODO $this->assertContains("action=\"$baseUrl/admin/indexmaintenance/checkfulltexts\"", $body); // TODO $this->assertContains("action=\"$baseUrl/admin/indexmaintenance/optimizeindex\"", $body); }
public function testCreateWorkerJobIfAsyncEnabled() { $this->config->merge(new Zend_Config(array('runjobs' => array('asynchronous' => 1)))); $this->assertEquals(0, Opus_Job::getCount(), 'test data changed.'); $doc = $this->createTestDocument(); $doc->setLanguage("eng"); $title = new Opus_Title(); $title->setValue("Test Document"); $title->setLanguage("eng"); $doc->addTitleMain($title); $doc->store(); $this->notification->prepareMail($doc, Application_Util_Notification::SUBMISSION, 'http://localhost/foo/1'); $mailJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_MailNotification::LABEL)); $this->assertEquals(1, count($mailJobs), 'Expected 1 mail job'); $jobs = Opus_Job::getAll(); if (!empty($jobs)) { foreach ($jobs as $job) { $job->delete(); } } }
public function testJobSuccess() { $filename = 'test_import_minimal.xml'; $xml = new DOMDocument(); $this->assertTrue($xml->load($this->xmlDir . $filename), 'Could not load xml as DomDocument'); $this->createJob(Opus_Job_Worker_MetadataImport::LABEL, array('xml' => $xml->saveXML())); $this->executeScript('cron-import-metadata.php'); $allJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_MetadataImport::LABEL), null, Opus_Job::STATE_UNDEFINED); $this->assertTrue(empty($allJobs), 'Expected no more jobs in queue'); $failedJobs = Opus_Job::getByLabels(array(Opus_Job_Worker_MetadataImport::LABEL), null, Opus_Job::STATE_FAILED); $this->assertTrue(empty($failedJobs), 'Expected no failed jobs in queue'); $this->documentImported = true; }
/** * Run scheduling of jobs. All jobs currently in the queue get * processed and any new jobs get created in the jobs table. * * @return void */ public function run() { $jobs = Opus_Job::getByLabels(array_keys($this->_workers), $this->_limit, Opus_Job::STATE_UNDEFINED); if (null !== $this->_logger) { $this->_logger->info('Found ' . count($jobs) . ' job(s)'); } $runJobs = 0; foreach ($jobs as $job) { if (true === $this->consume($job)) { $runJobs++; } else { if (null !== $this->_logger) { $this->_logger->warn('Job with ID ' . $job->getId() . ' failed.'); } } } if (null !== $this->_logger) { $this->_logger->info('Processed ' . $runJobs . ' job(s).'); } }