/**
  * tests lock()/unlock()/isLocked() functions
  */
 public function testLock()
 {
     $memoryManager = new Memory\MemoryManager($this->_cache);
     $memObject = $memoryManager->create('012345678');
     $this->assertFalse((bool) $memObject->isLocked());
     $memObject->lock();
     $this->assertTrue((bool) $memObject->isLocked());
     $memObject->unlock();
     $this->assertFalse((bool) $memObject->isLocked());
 }
 /**
  * Destroy memory container and remove it from memory manager list
  *
  * @internal
  */
 public function destroy()
 {
     /**
      * We don't clean up swap because of performance considerations
      * Cleaning is performed by Memory Manager destructor
      */
     $this->memManager->unlink($this, $this->id);
 }
Exemple #3
0
 public function testNotEnoughSpaceThrowException()
 {
     $memoryManager = new Memory\MemoryManager($this->_cache);
     $memoryManager->setMinSize(128);
     $memoryManager->setMemoryLimit(1024);
     $memObjects = array();
     for ($count = 0; $count < 8; $count++) {
         $memObject = $memoryManager->create(str_repeat((string) ($count % 10), 128));
         $memObjects[] = $memObject;
     }
     $this->setExpectedException('Zend\\Memory\\Exception\\RuntimeException');
     $memoryManager->create('a');
 }
 /**
  * tests the processing of data
  */
 public function testProcessing()
 {
     $memoryManager = new Memory\MemoryManager($this->_cache);
     $memoryManager->setMinSize(256);
     $memoryManager->setMemoryLimit(1024 * 32);
     $memObjects = array();
     for ($count = 0; $count < 64; $count++) {
         $memObject = $memoryManager->create(str_repeat((string) ($count % 10), 1024));
         $memObjects[] = $memObject;
     }
     for ($count = 0; $count < 64; $count += 2) {
         if (version_compare(PHP_VERSION, '5.2') < 0) {
             $value = $memObjects[$count]->getRef();
             $this->assertEquals($value[16], (string) ($count % 10));
         } else {
             $this->assertEquals($memObjects[$count]->value[16], (string) ($count % 10));
         }
     }
     for ($count = 63; $count > 0; $count -= 2) {
         if (version_compare(PHP_VERSION, '5.2') < 0) {
             $value =& $memObjects[$count]->getRef();
             $value[16] = '_';
         } else {
             $memObjects[$count]->value[16] = '_';
         }
     }
     for ($count = 1; $count < 64; $count += 2) {
         if (version_compare(PHP_VERSION, '5.2') < 0) {
             $value = $memObjects[$count]->getRef();
             $this->assertEquals($value[16], '_');
         } else {
             $this->assertEquals($memObjects[$count]->value[16], '_');
         }
     }
 }