You are here

public function MemCacheStampedeProtection::testStampedeProtectionIgnoringUnit in Memcache API and Integration 7

Tests the opt out functionality of stampede protection using a unit test.

File

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

Class

MemCacheStampedeProtection
Tests memcache stampede protection.

Code

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.'));
}