public function testBasicConcurrentCollectionReadLock()
 {
     $this->loadFixturesCountries();
     $this->loadFixturesStates();
     $this->loadFixturesCities();
     $this->_em->clear();
     $this->evictRegions();
     $stateId = $this->states[0]->getId();
     $state = $this->_em->find(State::CLASSNAME, $stateId);
     $this->assertInstanceOf(State::CLASSNAME, $state);
     $this->assertInstanceOf(Country::CLASSNAME, $state->getCountry());
     $this->assertNotNull($state->getCountry()->getName());
     $this->assertCount(2, $state->getCities());
     $this->_em->clear();
     $this->secondLevelCacheLogger->clearStats();
     $stateId = $this->states[0]->getId();
     $cacheId = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id' => $stateId));
     $region = $this->_em->getCache()->getCollectionCacheRegion(State::CLASSNAME, 'cities');
     $this->assertTrue($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId));
     /* @var $region \Doctrine\Tests\Mocks\ConcurrentRegionMock */
     $region->setLock($cacheId, Lock::createLockRead());
     // another proc lock the entity cache
     $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId));
     $queryCount = $this->getCurrentQueryCount();
     $state = $this->_em->find(State::CLASSNAME, $stateId);
     $this->assertEquals(0, $this->secondLevelCacheLogger->getMissCount());
     $this->assertEquals(1, $this->secondLevelCacheLogger->getHitCount());
     $this->assertEquals(0, $this->secondLevelCacheLogger->getRegionMissCount($this->getEntityRegion(State::CLASSNAME)));
     $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionHitCount($this->getEntityRegion(State::CLASSNAME)));
     $this->assertInstanceOf(State::CLASSNAME, $state);
     $this->assertCount(2, $state->getCities());
     $this->assertEquals(1, $this->secondLevelCacheLogger->getMissCount());
     $this->assertEquals(1, $this->secondLevelCacheLogger->getHitCount());
     $this->assertEquals(1, $this->secondLevelCacheLogger->getRegionMissCount($this->getCollectionRegion(State::CLASSNAME, 'cities')));
     $this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
     $this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $stateId));
 }
Exemple #2
0
 /**
  * {inheritdoc}
  */
 public function lock(CacheKey $key)
 {
     if ($this->isLocked($key)) {
         return null;
     }
     $lock = Lock::createLockRead();
     $filename = $this->getLockFileName($key);
     if (!@file_put_contents($filename, $lock->value, LOCK_EX)) {
         return null;
     }
     chmod($filename, 0664);
     return $lock;
 }
 public function testTransactionRollCommitUpdateShouldClearQueue()
 {
     $entity = new State("Foo");
     $lock = Lock::createLockRead();
     $persister = $this->createPersisterDefault();
     $collection = $this->createCollection($entity);
     $key = new CollectionCacheKey(State::CLASSNAME, 'cities', array('id' => 1));
     $property = new \ReflectionProperty('Doctrine\\ORM\\Cache\\Persister\\Collection\\ReadWriteCachedCollectionPersister', 'queuedCache');
     $property->setAccessible(true);
     $this->region->expects($this->once())->method('lock')->with($this->equalTo($key))->will($this->returnValue($lock));
     $this->region->expects($this->once())->method('evict')->with($this->equalTo($key));
     $this->em->getUnitOfWork()->registerManaged($entity, array('id' => 1), array('id' => 1, 'name' => 'Foo'));
     $persister->update($collection);
     $this->assertCount(1, $property->getValue($persister));
     $persister->afterTransactionComplete();
     $this->assertCount(0, $property->getValue($persister));
 }
 /**
  * {@inheritdoc}
  */
 public function lock(CacheKey $key)
 {
     $this->calls[__FUNCTION__][] = array('key' => $key);
     $this->throwException(__FUNCTION__);
     if (isset($this->locks[$key->hash])) {
         return null;
     }
     return $this->locks[$key->hash] = Lock::createLockRead();
 }