You are here

class MemCacheStampedeProtection in Memcache API and Integration 7

Tests memcache stampede protection.

Hierarchy

Expanded class hierarchy of MemCacheStampedeProtection

File

tests/memcache.test, line 705
Test cases for the memcache cache backend.

View source
class MemCacheStampedeProtection extends MemcacheTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Memcache stampede protection',
      'description' => 'Tests memcache stampede protection.',
      'group' => 'Memcache',
    );
  }

  /**
   * Tests the opt out functionality of stampede protection using a unit test.
   */
  public function testStampedeProtectionIgnoringUnit() {
    global $conf;

    // Setup a new test bin, to be able to override the used class.
    $conf['cache_flush_test_bin'] = 0;
    $conf['cache_class_test_bin'] = 'MockMemCacheDrupal';
    $conf['cache_flush_test_bin_2'] = 0;
    $conf['cache_class_test_bin_2'] = 'MockMemCacheDrupal';

    // Setup stampede protection.
    $conf['memcache_stampede_protection'] = TRUE;
    $conf['memcache_stampede_protection_ignore'] = array(
      'test_bin',
      'test_bin_2' => array(
        'cid_no_prefix',
        'cid_with_prefix:*',
      ),
    );

    // Ensure the mock object is used.

    /** @var \MockMemCacheDrupal $cache_object_bin */
    $cache_object_bin = _cache_get_object('test_bin');
    $this
      ->assertEqual(get_class($cache_object_bin), 'MockMemCacheDrupal');

    /** @var \MockMemCacheDrupal $cache_object_bin2 */
    $cache_object_bin2 = _cache_get_object('test_bin_2');
    $this
      ->assertEqual(get_class($cache_object_bin2), 'MockMemCacheDrupal');

    // Test ignoring of an entire bin.
    $this
      ->assertFalse($cache_object_bin
      ->stampedeProtected('test_cid'), t('Disable stampede protection for cid contained in a disabled bin.'));
    $this
      ->assertFalse($cache_object_bin
      ->stampedeProtected('cid_no_prefix'), t('Disable stampede protection for cid without prefix in a disabled bin.'));
    $this
      ->assertFalse($cache_object_bin
      ->stampedeProtected('cid_with_prefix:example'), t('Disable stampede protection for cid with prefix in a disabled bin.'));

    // Test ignoring of specific CIDs.
    $this
      ->assertTrue($cache_object_bin2
      ->stampedeProtected('test_cid'), t('Don\'t disable stampede protection for a specific non-matching cid.'));
    $this
      ->assertFalse($cache_object_bin2
      ->stampedeProtected('cid_no_prefix'), t('Disable stampede protection for a specific cid.'));
    $this
      ->assertFalse($cache_object_bin2
      ->stampedeProtected('cid_with_prefix:example'), t('Disable stampede protection for a specific cid with disabled prefix.'));
    $this
      ->assertTrue($cache_object_bin2
      ->stampedeProtected('cid_with_other_prefix:example'), t('Don\'t disable stampede protection for a specific cid with a different prefix.'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MemCacheStampedeProtection::getInfo public static function
MemCacheStampedeProtection::testStampedeProtectionIgnoringUnit public function Tests the opt out functionality of stampede protection using a unit test.