/** * @covers EmbeddedServer */ public function testStartStopIsRunning() { // Check whether the server is currently running. $running = $this->embeddedServer->isRunning(); if ($running) { // If the server is running we stop it, then start it. // Stop the server. self::assertTrue($this->embeddedServer->stopAndWait()); // Restart the server. self::assertTrue($this->embeddedServer->start()); self::assertTrue($this->embeddedServer->isRunning()); } else { // If the server is stopped, we start it, then stop it. // Start the server. self::assertTrue($this->embeddedServer->start()); self::assertTrue($this->embeddedServer->isRunning()); // Stop the server. self::assertTrue($this->embeddedServer->stopAndWait()); } }
/** * @see Plugin::manage() */ function manage($verb, $args, &$message, &$messageParams, &$pluginModalContent = null) { if (!parent::manage($verb, $args, $message, $messageParams)) { return false; } $request = $this->getRequest(); switch ($verb) { case 'settings': // Prepare the template manager. $templateMgr = TemplateManager::getManager($request); $templateMgr->register_function('plugin_url', array($this, 'smartyPluginUrl')); // Instantiate an embedded server instance. $this->import('classes.EmbeddedServer'); $embeddedServer = new EmbeddedServer(); // Instantiate the settings form. $this->import('classes.form.LuceneSettingsForm'); $form = new LuceneSettingsForm($this, $embeddedServer); // Handle request to save configuration data. if ($request->getUserVar('save')) { $form->readInputData(); if ($form->validate()) { $form->execute(); $request->redirect(null, 'manager', 'plugins', 'generic'); return false; } else { $form->display($request); } // Handle administrative request. } else { // Re-init data. It should be visible to users // that whatever data they may have entered into // the form was not saved. $form->initData(); // Index rebuild. if ($request->getUserVar('rebuildIndex')) { // Check whether we got valid index rebuild options. if ($form->validate()) { // Check whether a journal was selected. $journal = null; $journalId = $request->getUserVar('journalToReindex'); if (!empty($journalId)) { $journalDao = DAORegistry::getDAO('JournalDAO'); /* @var $journalDao JournalDAO */ $journal = $journalDao->getById($journalId); if (!is_a($journal, 'Journal')) { $journal = null; } } if (empty($journalId) || !empty($journalId) && is_a($journal, 'Journal')) { // Rebuild index and dictionaries. $messages = null; $this->_rebuildIndex(false, $journal, true, true, true, $messages); // Transfer indexing output to the form template. $form->setData('rebuildIndexMessages', $messages); } } // Dictionary rebuild. } elseif ($request->getUserVar('rebuildDictionaries')) { // Rebuild dictionaries. $journal = null; $this->_rebuildIndex(false, null, false, true, false, $messages); // Transfer indexing output to the form template. $form->setData('rebuildIndexMessages', $messages); // Boost File Update. } elseif ($request->getUserVar('updateBoostFile')) { $this->_updateBoostFiles(); // Start/Stop solr server. } elseif ($request->getUserVar('stopServer')) { // As this is a system plug-in we follow usual // plug-in policy and allow journal managers to start/ // stop the server although this will affect all journals // of the installation. $embeddedServer->stopAndWait(); } elseif ($request->getUserVar('startServer')) { $embeddedServer->start(); } // Re-display the settings page after executing // an administrative task. $form->display($request); } return true; default: // Unknown management verb assert(false); return false; } }
/** * SCENARIO: solr process admin button (solr not running) * GIVEN I am in an environment that allows execution of solr server * process management shell scripts from within PHP * AND solr binaries have been installed within the plugin's * "lib" directory * AND no solr process is running on the local machine * WHEN I open up the lucene plugin settings page * THEN I'll see a button "Start Server". * * SCENARIO: start embedded solr server * GIVEN I see the button "Stop Server" on the lucene plugin * search settings page * WHEN I click on this button * THEN a solr server process will be started. * * SCENARIO: solr process admin button (solr running) * GIVEN I am in an environment that allows execution of solr server * process management shell scripts from within PHP * AND I configured a solr server endpoint on "localhost" * AND a solr process is running on the local machine * AND the PID-file of the process is in the installation's * files direcory * WHEN I open up the lucene plugin settings page * THEN I'll see a button "Stop Server". * * SCENARIO: stop embedded solr server * GIVEN I see the button "Stop Server" on the lucene plugin * search settings page * WHEN I click on this button * THEN the running solr process will be stopped. */ public function testSolrServerStartStopButtons() { // Stop the solr server. (This is part of the // test but will also implicitly make sure that // the server doesn't run under the wrong user // which would make it unavailable to the web // frontend.) import('plugins/generic/lucene/classes/EmbeddedServer'); $embeddedServer = new EmbeddedServer(); $embeddedServer->stopAndWait(); // Make sure that the server really stopped. // NB: If this fails then make sure that the server is // not running under a user different from the test user. // If that's the case we cannot stop the running server // and you'll have to stop it manually. self::assertFalse($embeddedServer->isRunning(), 'Embedded server still running.'); // Open the lucene plugin settings page. $this->logIn(); $this->verifyAndOpen($this->_pluginSettings . '#indexAdmin'); // Check that no availability warning is shown. $this->waitForElementNotPresent('serverNotAvailable'); // Check that a start button appears. $this->assertElementPresent('name=startServer'); $this->assertElementNotPresent('name=stopServer'); // Click on the start button. $this->clickAndWait('name=startServer'); // Check that an embedded solr process is now running. self::assertTrue($embeddedServer->isRunning()); // Check that a stop button appears. $this->assertElementPresent('name=stopServer'); $this->assertElementNotPresent('name=startServer'); // Click on the stop button. $this->clickAndWait('name=stopServer'); // Check that the embedded solr process was stopped. self::assertFalse($embeddedServer->isRunning()); // Restart the server from the test user so that it // is available for other tests. $this->startSolrServer($embeddedServer); }
/** * @covers LucenePlugin */ public function testArticleIndexingProblem() { // Make sure the embedded server is switched off. $embeddedServer = new EmbeddedServer(); $this->assertTrue($embeddedServer->stopAndWait()); // Mock email templates. $constructorArgs = array('LUCENE_ARTICLE_INDEXING_ERROR_NOTIFICATION', null, null, null, true, true); import('lib.pkp.classes.mail.MailTemplate'); $techInfoMail = $this->getMock('MailTemplate', array('send'), $constructorArgs); /* @var $techInfoMail MailTemplate */ $techInfoMail->expects($this->exactly(2))->method('send')->will($this->returnValue(true)); $this->lucenePlugin->setMailTemplate('LUCENE_ARTICLE_INDEXING_ERROR_NOTIFICATION', $techInfoMail); // Reset the time of the last sent email. $this->lucenePlugin->updateSetting(0, 'lastEmailTimestamp', 0); // Trying to delete a document without the server running // should trigger an email to the tech contact. $params = array($articleId = 3, $type = null, $assocId = null); $this->lucenePlugin->callbackArticleFileDeleted('ArticleSearchIndex::articleFileDeleted', $params); $this->lucenePlugin->callbackArticleChangesFinished('ArticleSearchIndex::articleChangesFinished', array()); // Check the mail. $this->assertEquals('Article Indexing Error', $techInfoMail->getSubject()); $this->assertContains('An indexing error occurred while updating the article index.', $techInfoMail->getBody()); $this->assertContains('##plugins.generic.lucene.message.searchServiceOffline##', $techInfoMail->getBody()); if (Core::isWindows()) { $this->assertEquals('*****@*****.**', $techInfoMail->getRecipientString()); } else { $this->assertEquals('"Open Journal Systems" <*****@*****.**>', $techInfoMail->getRecipientString()); } $this->assertEquals('"Open Journal Systems" <*****@*****.**>', $techInfoMail->getFromString()); // Call again to make sure that a second mail is not being sent. $this->lucenePlugin->callbackArticleChangesFinished('ArticleSearchIndex::articleChangesFinished', array()); // Simulate that the last email is more than three hours ago. $this->lucenePlugin->updateSetting(0, 'lastEmailTimestamp', time() - 60 * 60 * 4); // This should trigger another email (see send() call count above). $this->lucenePlugin->callbackArticleChangesFinished('ArticleSearchIndex::articleChangesFinished', array()); // Restart the embedded server. $this->assertTrue($embeddedServer->start()); }