MDL-56273 cache: Fixed initialise call

After store is created, it should be checked if
it's ready before calling initialise
This commit is contained in:
Rajesh Taneja 2016-11-02 14:04:22 +08:00
parent cad8adccc7
commit 4a910b9aa6
No known key found for this signature in database
GPG Key ID: B363F7FB787F80E4
9 changed files with 21 additions and 20 deletions

View File

@ -258,7 +258,9 @@ class cachestore_dummy extends cache_store {
*/
public static function initialise_test_instance(cache_definition $definition) {
$cache = new cachestore_dummy('Dummy store test');
$cache->initialise($definition);
if ($cache->is_ready()) {
$cache->initialise($definition);
}
return $cache;
}

View File

@ -155,15 +155,6 @@ class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_i
return ($this->definition !== null);
}
/**
* Returns true if this cache store instance is ready to use.
* @return bool
*/
public function is_ready() {
// No set up is actually required, providing apc is installed and enabled.
return true;
}
/**
* Prepares the given key for use.
*
@ -325,6 +316,7 @@ class cachestore_apcu extends cache_store implements cache_is_key_aware, cache_i
}
$name = 'APCu test';
$cache = new cachestore_apcu($name);
// No need to check if is_ready() as this has already being done by requirement check.
$cache->initialise($definition);
return $cache;
}

View File

@ -673,7 +673,9 @@ class cachestore_file extends cache_store implements cache_is_key_aware, cache_i
$name = 'File test';
$path = make_cache_directory('cachestore_file_test');
$cache = new cachestore_file($name, array('path' => $path));
$cache->initialise($definition);
if ($cache->is_ready()) {
$cache->initialise($definition);
}
return $cache;
}

View File

@ -576,7 +576,9 @@ class cachestore_memcache extends cache_store implements cache_is_configurable {
}
$store = new cachestore_memcache('Test memcache', $configuration);
$store->initialise($definition);
if ($store->is_ready()) {
$store->initialise($definition);
}
return $store;
}

View File

@ -58,12 +58,12 @@ class cachestore_memcache_test extends cachestore_tests {
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcache', 'phpunit_test');
$instance = new cachestore_memcache('Memcache Test', cachestore_memcache::unit_test_configuration());
$instance->initialise($definition);
if (!$instance->is_ready()) {
// Something prevented memcache store to be inited (extension, TEST_CACHESTORE_MEMCACHE_TESTSERVERS...).
$this->markTestSkipped();
}
$instance->initialise($definition);
$keys = array(
// Alphanumeric.

View File

@ -733,7 +733,10 @@ class cachestore_memcached extends cache_store implements cache_is_configurable
}
$store = new cachestore_memcached($name, $configuration);
$store->initialise($definition);
// If store is ready then only initialise.
if ($store->is_ready()) {
$store->initialise($definition);
}
return $store;
}

View File

@ -62,12 +62,12 @@ class cachestore_memcached_test extends cachestore_tests {
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcached', 'phpunit_test');
$instance = new cachestore_memcached('Memcached Test', cachestore_memcached::unit_test_configuration());
$instance->initialise($definition);
if (!$instance->is_ready()) {
// Something prevented memcached store to be inited (extension, TEST_CACHESTORE_MEMCACHED_TESTSERVERS...).
$this->markTestSkipped();
}
$instance->initialise($definition);
$keys = array(
// Alphanumeric.
@ -183,7 +183,7 @@ class cachestore_memcached_test extends cachestore_tests {
set_config('testname', $testserver, 'cachestore_memcached');
set_config('testservers', $testserver, 'cachestore_memcached');
$checkinstance = cachestore_memcached::initialise_test_instance($definition);
if (!$checkinstance) {
if (!$checkinstance->is_ready()) {
$this->markTestSkipped();
}
$checkinstances[] = $checkinstance;

View File

@ -57,11 +57,11 @@ class cachestore_mongodb_test extends cachestore_tests {
// This generates a definition that has a hash starting with a number. MDL-46208.
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_mongodb', 'abc');
$instance = new cachestore_mongodb('MongoDB_Test', cachestore_mongodb::unit_test_configuration());
$instance->initialise($definition);
if (!$instance->is_ready()) {
$this->markTestSkipped();
}
$instance->initialise($definition);
$this->assertTrue($instance->set(1, 'alpha'));
$this->assertTrue($instance->set(2, 'beta'));

View File

@ -63,33 +63,33 @@ abstract class cachestore_tests extends advanced_testcase {
if ($modes & cache_store::MODE_APPLICATION) {
$definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, $class, 'phpunit_test');
$instance = new $class($class.'_test', $class::unit_test_configuration());
$instance->initialise($definition);
if (!$instance->is_ready()) {
$this->markTestSkipped('Could not test '.$class.'. No test instance configured for application caches.');
} else {
$instance->initialise($definition);
$this->run_tests($instance);
}
}
if ($modes & cache_store::MODE_SESSION) {
$definition = cache_definition::load_adhoc(cache_store::MODE_SESSION, $class, 'phpunit_test');
$instance = new $class($class.'_test', $class::unit_test_configuration());
$instance->initialise($definition);
if (!$instance->is_ready()) {
$this->markTestSkipped('Could not test '.$class.'. No test instance configured for session caches.');
} else {
$instance->initialise($definition);
$this->run_tests($instance);
}
}
if ($modes & cache_store::MODE_REQUEST) {
$definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, $class, 'phpunit_test');
$instance = new $class($class.'_test', $class::unit_test_configuration());
$instance->initialise($definition);
if (!$instance->is_ready()) {
$this->markTestSkipped('Could not test '.$class.'. No test instance configured for request caches.');
} else {
$instance->initialise($definition);
$this->run_tests($instance);
}
}