public function testMetaDataSuccess() { $temp = $this->createTempDir(__CLASS__); $meta = new ezcCacheStackLruMetaData(); $meta->setState(array('replacementData' => array('id_1' => 23, 'id_2' => 42), 'storageData' => array('storage_id_1' => array('id_1' => true, 'id_2' => true), 'storage_id_2' => array('id_2' => true)))); $storage = new ezcCacheStorageFilePlain($temp); $this->assertFalse(file_exists($storage->getLocation() . $storage->options->metaDataFile), 'Meta data file existed before the storage was created.'); $storage->storeMetaData($meta); $this->assertTrue(file_exists($storage->getLocation() . $storage->options->metaDataFile), 'Meta data file existed before the storage was created.'); $restoredMeta = $storage->restoreMetaData(); $this->assertEquals($meta, $restoredMeta, 'Meta data not restored correctly.'); $this->assertTrue(file_exists($storage->getLocation() . $storage->options->metaDataFile), 'Meta data does not exist anymore after restoring.'); }
public function testMetaDataSuccess() { $storage = new ezcCacheStorageFileApcArray($this->getTempDir(__CLASS__), array('ttl' => 1)); $storage->reset(); $metaDataKey = urlencode($storage->getLocation()) . '_' . $storage->options->metaDataKey; $meta = new ezcCacheStackLruMetaData(); $meta->setState(array('replacementData' => array('id_1' => 23, 'id_2' => 42), 'storageData' => array('storage_id_1' => array('id_1' => true, 'id_2' => true), 'storage_id_2' => array('id_2' => true)))); $this->assertFalse(apc_fetch($metaDataKey), 'Meta data key existed before the storage was created.'); $storage->storeMetaData($meta); $this->assertEquals($meta, apc_fetch($metaDataKey)->var, 'Meta data file existed before the storage was created.'); $restoredMeta = $storage->restoreMetaData(); $this->assertEquals($meta, $restoredMeta, 'Meta data not restored correctly.'); $this->assertEquals($meta, apc_fetch($metaDataKey)->var, 'Meta data file existed before the storage was created.'); $this->removeTempDir(); }
public function testDeleteSuccessSearch() { // Prepare faked test data $tmpDir = $this->createTempDir(__FUNCTION__); $conf = new ezcCacheStackStorageConfiguration('storage_id_1', new ezcCacheStorageFileArray($tmpDir, array('ttl' => 30)), 5, 0.5); $now = time(); // Store max number of items $conf->storage->store('id_1', 'id_1_content', array('lang' => 'en')); $conf->storage->store('id_2', 'id_2_content'); $conf->storage->store('id_3', 'id_3_content', array('lang' => 'en')); // Cache location not empty $this->assertEquals(3, count(glob("{$tmpDir}/*")), 'Cache location contains unknown items.'); $meta = new ezcCacheStackLruMetaData(); $meta->setState(array('replacementData' => array('id_1' => $now, 'id_2' => $now, 'id_3' => $now), 'storageData' => array('storage_id_1' => array('id_1' => true, 'id_2' => true, 'id_3' => true), 'storage_id_42' => array('id_1' => true)))); // Perform actual action $deletedItems = ezcCacheStackLruReplacementStrategy::delete($conf, $meta, null, array('lang' => 'en'), true); $metaData = $meta->getState(); // Assert correct behavior // Item data correctly restored $this->assertEquals(array('id_1', 'id_3'), $deletedItems, 'Item not indicated to be delted.'); // Meta data actualized correctly $this->assertEquals(array('id_1' => $now, 'id_2' => $now), $metaData['replacementData'], "Meta data not actualized correctly."); // Storage data kept correctly $this->assertEquals(array('storage_id_1' => array('id_2' => true), 'storage_id_42' => array('id_1' => true)), $metaData['storageData'], 'Storage data not correctly updated.'); // Cache location empty $this->assertEquals(1, count(glob("{$tmpDir}/*")), 'Cache location contains incorrect number of items.'); }
public function testMetaDataSuccess() { $opts = array('host' => 'localhost', 'port' => 11211, 'ttl' => 1); $storage = new ezcCacheStorageMemcacheWrapper('.', $opts); $storage->reset(); $backend = $this->readAttribute($storage, 'backend'); $memcache = $this->readAttribute($backend, 'memcache'); $metaDataKey = urlencode($storage->getLocation()) . '_' . $storage->options->metaDataKey; $meta = new ezcCacheStackLruMetaData(); $meta->setState(array('replacementData' => array('id_1' => 23, 'id_2' => 42), 'storageData' => array('storage_id_1' => array('id_1' => true, 'id_2' => true), 'storage_id_2' => array('id_2' => true)))); $this->assertFalse($memcache->get($metaDataKey), 'Meta data key existed before the storage was created.'); $storage->storeMetaData($meta); $this->assertEquals($meta, $memcache->get($metaDataKey)->var, 'Meta data file existed before the storage was created.'); $restoredMeta = $storage->restoreMetaData(); $this->assertEquals($meta, $restoredMeta, 'Meta data not restored correctly.'); $this->assertEquals($meta, $memcache->get($metaDataKey)->var, 'Meta data file existed before the storage was created.'); }