summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-09-10 20:33:18 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-09-10 20:33:18 +0100
commit620173c792c88407e73587d0667358eda78d8ad5 (patch)
tree77f18b4e29f91b636031bab33b4808400273bc6d /tests
parentfb717f254fe81065912c13e0907ba374c8167f98 (diff)
parentb64e3f8db609b1f65ec23f467da7488abf92c05a (diff)
downloadnextcloud-server-620173c792c88407e73587d0667358eda78d8ad5.tar.gz
nextcloud-server-620173c792c88407e73587d0667358eda78d8ad5.zip
Merge pull request #18851 from owncloud/memcached-getallkeys-fallback
Fallback to complete Memcached flush if getAllKeys fails
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/memcache/memcached.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php
index 51a78996dd4..3ea9216029a 100644
--- a/tests/lib/memcache/memcached.php
+++ b/tests/lib/memcache/memcached.php
@@ -26,4 +26,27 @@ class Memcached extends Cache {
parent::setUp();
$this->instance = new \OC\Memcache\Memcached($this->getUniqueID());
}
+
+ public function testClear() {
+ // Memcached is sometimes broken with clear(), so we don't test it thoroughly
+ $value='ipsum lorum';
+ $this->instance->set('1_value1', $value);
+ $this->instance->set('1_value2', $value);
+ $this->instance->set('2_value1', $value);
+ $this->instance->set('3_value1', $value);
+
+ $this->assertTrue($this->instance->clear('1_'));
+
+ $this->assertFalse($this->instance->hasKey('1_value1'));
+ $this->assertFalse($this->instance->hasKey('1_value2'));
+ //$this->assertTrue($this->instance->hasKey('2_value1'));
+ //$this->assertTrue($this->instance->hasKey('3_value1'));
+
+ $this->assertTrue($this->instance->clear());
+
+ $this->assertFalse($this->instance->hasKey('1_value1'));
+ $this->assertFalse($this->instance->hasKey('1_value2'));
+ $this->assertFalse($this->instance->hasKey('2_value1'));
+ $this->assertFalse($this->instance->hasKey('3_value1'));
+ }
}
eight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<?php
/**
 * ownCloud
 *
 * @author Jakob Sack
 * @copyright 2012 Jakob Sack owncloud@jakobsack.de
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

// Unfortunately we need this class for shutdown function
class TemporaryCronClass {
	public static $sent = false;
	public static $lockfile = "";
	public static $keeplock = false;
}

// We use this function to handle (unexpected) shutdowns
function handleUnexpectedShutdown() {
	// Delete lockfile
	if (!TemporaryCronClass::$keeplock && file_exists(TemporaryCronClass::$lockfile)) {
		unlink(TemporaryCronClass::$lockfile);
	}

	// Say goodbye if the app did not shutdown properly
	if (!TemporaryCronClass::$sent) {
		if (OC::$CLI) {
			echo 'Unexpected error!' . PHP_EOL;
		} else {
			OC_JSON::error(array('data' => array('message' => 'Unexpected error!')));
		}
	}
}

try {

	require_once 'lib/base.php';

	session_write_close();

	// Don't do anything if ownCloud has not been installed
	if (!OC_Config::getValue('installed', false)) {
		exit(0);
	}

	// Handle unexpected errors
	register_shutdown_function('handleUnexpectedShutdown');

	// Delete temp folder
	OC_Helper::cleanTmpNoClean();

	// Exit if background jobs are disabled!
	$appmode = OC_BackgroundJob::getExecutionType();
	if ($appmode == 'none') {
		TemporaryCronClass::$sent = true;
		if (OC::$CLI) {
			echo 'Background Jobs are disabled!' . PHP_EOL;
		} else {
			OC_JSON::error(array('data' => array('message' => 'Background jobs disabled!')));
		}
		exit(1);
	}

	if (OC::$CLI) {
		// Create lock file first
		TemporaryCronClass::$lockfile = OC_Config::getValue("datadirectory", OC::$SERVERROOT . '/data') . '/cron.lock';

		// We call ownCloud from the CLI (aka cron)
		if ($appmode != 'cron') {
			// Use cron in feature!
			OC_BackgroundJob::setExecutionType('cron');
		}

		// check if backgroundjobs is still running
		if (file_exists(TemporaryCronClass::$lockfile)) {
			TemporaryCronClass::$keeplock = true;
			TemporaryCronClass::$sent = true;
			echo "Another instance of cron.php is still running!";
			exit(1);
		}

		// Create a lock file
		touch(TemporaryCronClass::$lockfile);

		// Work
		$jobList = new \OC\BackgroundJob\JobList();
		$jobs = $jobList->getAll();
		foreach ($jobs as $job) {
			$job->execute($jobList);
		}
	} else {
		// We call cron.php from some website
		if ($appmode == 'cron') {
			// Cron is cron :-P
			OC_JSON::error(array('data' => array('message' => 'Backgroundjobs are using system cron!')));
		} else {
			// Work and success :-)
			$jobList = new \OC\BackgroundJob\JobList();
			$job = $jobList->getNext();
			$job->execute($jobList);
			$jobList->setLastJob($job);
			OC_JSON::success();
		}
	}

	// done!
	TemporaryCronClass::$sent = true;
	exit();

} catch (Exception $ex) {
	\OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL);
}