You are here

memcache_test.module in Memcache API and Integration 6

Same filename and directory in other branches
  1. 7 tests/memcache_test.module

File

tests/memcache_test.module
View source
<?php

/**
 * Implements hook_menu().
 */
function memcache_test_menu() {
  $items['memcache-test/lock-acquire'] = array(
    'title' => 'Lock acquire',
    'page callback' => 'memcache_test_lock_acquire',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  $items['memcache-test/lock-exit'] = array(
    'title' => 'Lock acquire then exit',
    'page callback' => 'memcache_test_lock_exit',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Try to acquire a named lock and report the outcome.
 */
function memcache_test_lock_acquire() {
  dmemcache_key(FALSE, FALSE, TRUE);
  $GLOBALS['drupal_test_info']['test_run_id'] = arg(2);
  if (lock_acquire('memcache_test_lock_acquire')) {
    lock_release('memcache_test_lock_acquire');
    return 'TRUE: Lock successfully acquired in memcache_test_lock_acquire()';
  }
  else {
    return 'FALSE: Lock not acquired in memcache_test_lock_acquire()';
  }
}

/**
 * Try to acquire a specific lock, and then exit.
 */
function memcache_test_lock_exit() {
  dmemcache_key(FALSE, FALSE, TRUE);
  $GLOBALS['drupal_test_info']['test_run_id'] = arg(2);
  if (lock_acquire('memcache_test_lock_exit', 900)) {
    echo 'TRUE: Lock successfully acquired in memcache_test_lock_exit()';

    // The shut-down function should release the lock.
    exit;
  }
  else {
    return 'FALSE: Lock not acquired in memcache_test_lock_exit()';
  }
}

Functions

Namesort descending Description
memcache_test_lock_acquire Try to acquire a named lock and report the outcome.
memcache_test_lock_exit Try to acquire a specific lock, and then exit.
memcache_test_menu Implements hook_menu().