public function testUngenerate()
 {
     $generator = new DefaultKeyGenerator();
     $lock = new Lock();
     $generator->ungenerate('resourceA:EX:nasidb20d98g', $lock);
     $this->assertEquals('resourceA', $lock->getResourceName());
     $this->assertEquals('EX', $lock->getType());
     $this->assertEquals('nasidb20d98g', $lock->getToken());
 }
Пример #2
0
 public function testGetKeysHits()
 {
     $keyGenerator = new \Everlution\Redlock\KeyGenerator\DefaultKeyGenerator();
     $locks = array(new Lock('printer', LockType::NULL, 'dn87020w80df8gsad'), new Lock('printer', LockType::PROTECTED_READ, 'dn87020w80df8gsad'), new Lock('printer', LockType::CONCURRENT_READ, 'dn87020w80df8gsad'));
     $keys = array();
     foreach ($locks as $lock) {
         $keys[$keyGenerator->generate($lock)] = $lock;
     }
     $manager = $this->newManager(count($this->validAdapters), count($this->invalidAdapters));
     $hits = $manager->getKeysHits('printer:*:*');
     $this->assertInternalType('array', $hits);
     $this->assertCount(0, $hits);
     $i = 1;
     foreach ($keys as $key => $lock) {
         $manager->acquireLock($lock);
         $hits = $manager->getKeysHits('printer:*:*');
         $this->assertInternalType('array', $hits);
         $this->assertCount($i, $hits);
         $this->assertContains($key, array_keys($keys));
         $i++;
     }
 }