diff --git a/src/Symfony/Component/Lock/Store/CombinedStore.php b/src/Symfony/Component/Lock/Store/CombinedStore.php index 7122b9019e166..0f5a78cef6455 100644 --- a/src/Symfony/Component/Lock/Store/CombinedStore.php +++ b/src/Symfony/Component/Lock/Store/CombinedStore.php @@ -18,7 +18,7 @@ use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\QuorumInterface; +use Symfony\Component\Lock\Strategy\StrategyInterface; use Symfony\Component\Lock\StoreInterface; /** @@ -32,16 +32,16 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface /** @var StoreInterface[] */ private $stores; - /** @var QuorumInterface */ - private $quorum; + /** @var StrategyInterface */ + private $strategy; /** - * @param StoreInterface[] $stores The list of synchronized stores - * @param QuorumInterface $quorum + * @param StoreInterface[] $stores The list of synchronized stores + * @param StrategyInterface $strategy * * @throws InvalidArgumentException */ - public function __construct(array $stores, QuorumInterface $quorum) + public function __construct(array $stores, StrategyInterface $strategy) { foreach ($stores as $store) { if (!$store instanceof StoreInterface) { @@ -50,7 +50,7 @@ public function __construct(array $stores, QuorumInterface $quorum) } $this->stores = $stores; - $this->quorum = $quorum; + $this->strategy = $strategy; $this->logger = new NullLogger(); } @@ -72,12 +72,12 @@ public function save(Key $key) ++$failureCount; } - if (!$this->quorum->canBeMet($failureCount, $storesCount)) { + if (!$this->strategy->canBeMet($failureCount, $storesCount)) { break; } } - if ($this->quorum->isMet($successCount, $storesCount)) { + if ($this->strategy->isMet($successCount, $storesCount)) { return; } @@ -112,12 +112,12 @@ public function putOffExpiration(Key $key, $ttl) ++$failureCount; } - if (!$this->quorum->canBeMet($failureCount, $storesCount)) { + if (!$this->strategy->canBeMet($failureCount, $storesCount)) { break; } } - if ($this->quorum->isMet($successCount, $storesCount)) { + if ($this->strategy->isMet($successCount, $storesCount)) { return; } @@ -161,10 +161,10 @@ public function exists(Key $key) ++$failureCount; } - if ($this->quorum->isMet($successCount, $storesCount)) { + if ($this->strategy->isMet($successCount, $storesCount)) { return true; } - if (!$this->quorum->canBeMet($failureCount, $storesCount)) { + if (!$this->strategy->canBeMet($failureCount, $storesCount)) { return false; } } diff --git a/src/Symfony/Component/Lock/Quorum/ConsensusStrategy.php b/src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php similarity index 71% rename from src/Symfony/Component/Lock/Quorum/ConsensusStrategy.php rename to src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php index a4b193d05d860..047820a409f1d 100644 --- a/src/Symfony/Component/Lock/Quorum/ConsensusStrategy.php +++ b/src/Symfony/Component/Lock/Strategy/ConsensusStrategy.php @@ -9,16 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Lock\Quorum; - -use Symfony\Component\Lock\QuorumInterface; +namespace Symfony\Component\Lock\Strategy; /** - * ConsensusStrategy is a QuorumInterface implementation where strictly more than 50% items should be successful. + * ConsensusStrategy is a StrategyInterface implementation where strictly more than 50% items should be successful. * * @author Jérémy Derussé */ -class ConsensusStrategy implements QuorumInterface +class ConsensusStrategy implements StrategyInterface { /** * {@inheritdoc} diff --git a/src/Symfony/Component/Lock/QuorumInterface.php b/src/Symfony/Component/Lock/Strategy/StrategyInterface.php similarity index 85% rename from src/Symfony/Component/Lock/QuorumInterface.php rename to src/Symfony/Component/Lock/Strategy/StrategyInterface.php index 5dddfaa9739ea..beaa7280a2d49 100644 --- a/src/Symfony/Component/Lock/QuorumInterface.php +++ b/src/Symfony/Component/Lock/Strategy/StrategyInterface.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Lock; +namespace Symfony\Component\Lock\Strategy; /** - * QuorumInterface defines an interface to indicate when a quorum is met and can be met. + * StrategyInterface defines an interface to indicate when a quorum is met and can be met. * * @author Jérémy Derussé */ -interface QuorumInterface +interface StrategyInterface { /** * Returns whether or not the quorum is met. diff --git a/src/Symfony/Component/Lock/Quorum/UnanimousStrategy.php b/src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php similarity index 72% rename from src/Symfony/Component/Lock/Quorum/UnanimousStrategy.php rename to src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php index 487a2dd1df20f..12d57e526ecf4 100644 --- a/src/Symfony/Component/Lock/Quorum/UnanimousStrategy.php +++ b/src/Symfony/Component/Lock/Strategy/UnanimousStrategy.php @@ -9,16 +9,14 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Lock\Quorum; - -use Symfony\Component\Lock\QuorumInterface; +namespace Symfony\Component\Lock\Strategy; /** - * UnanimousStrategy is a QuorumInterface implementation where 100% of elements should be successful. + * UnanimousStrategy is a StrategyInterface implementation where 100% of elements should be successful. * * @author Jérémy Derussé */ -class UnanimousStrategy implements QuorumInterface +class UnanimousStrategy implements StrategyInterface { /** * {@inheritdoc} diff --git a/src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php b/src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php index 4670fdfde2dcc..debe06183dc35 100644 --- a/src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php @@ -13,8 +13,8 @@ use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; -use Symfony\Component\Lock\Quorum\UnanimousStrategy; -use Symfony\Component\Lock\QuorumInterface; +use Symfony\Component\Lock\Strategy\UnanimousStrategy; +use Symfony\Component\Lock\Strategy\StrategyInterface; use Symfony\Component\Lock\Store\CombinedStore; use Symfony\Component\Lock\Store\RedisStore; use Symfony\Component\Lock\StoreInterface; @@ -50,7 +50,7 @@ public function getStore() } /** @var \PHPUnit_Framework_MockObject_MockObject */ - private $quorum; + private $strategy; /** @var \PHPUnit_Framework_MockObject_MockObject */ private $store1; /** @var \PHPUnit_Framework_MockObject_MockObject */ @@ -60,11 +60,11 @@ public function getStore() public function setup() { - $this->quorum = $this->getMockBuilder(QuorumInterface::class)->getMock(); + $this->strategy = $this->getMockBuilder(StrategyInterface::class)->getMock(); $this->store1 = $this->getMockBuilder(StoreInterface::class)->getMock(); $this->store2 = $this->getMockBuilder(StoreInterface::class)->getMock(); - $this->store = new CombinedStore(array($this->store1, $this->store2), $this->quorum); + $this->store = new CombinedStore(array($this->store1, $this->store2), $this->strategy); } /** @@ -85,11 +85,11 @@ public function testSaveThrowsExceptionOnFailure() ->with($key) ->willThrowException(new LockConflictedException()); - $this->quorum + $this->strategy ->expects($this->any()) ->method('canBeMet') ->willReturn(true); - $this->quorum + $this->strategy ->expects($this->any()) ->method('isMet') ->willReturn(false); @@ -119,11 +119,11 @@ public function testSaveCleanupOnFailure() ->expects($this->once()) ->method('delete'); - $this->quorum + $this->strategy ->expects($this->any()) ->method('canBeMet') ->willReturn(true); - $this->quorum + $this->strategy ->expects($this->any()) ->method('isMet') ->willReturn(false); @@ -135,7 +135,7 @@ public function testSaveCleanupOnFailure() } } - public function testSaveAbortWhenQuorumCantBeMet() + public function testSaveAbortWhenStrategyCantBeMet() { $key = new Key(uniqid(__METHOD__, true)); @@ -148,11 +148,11 @@ public function testSaveAbortWhenQuorumCantBeMet() ->expects($this->never()) ->method('save'); - $this->quorum + $this->strategy ->expects($this->once()) ->method('canBeMet') ->willReturn(false); - $this->quorum + $this->strategy ->expects($this->any()) ->method('isMet') ->willReturn(false); @@ -183,11 +183,11 @@ public function testputOffExpirationThrowsExceptionOnFailure() ->with($key, $ttl) ->willThrowException(new LockConflictedException()); - $this->quorum + $this->strategy ->expects($this->any()) ->method('canBeMet') ->willReturn(true); - $this->quorum + $this->strategy ->expects($this->any()) ->method('isMet') ->willReturn(false); @@ -218,11 +218,11 @@ public function testputOffExpirationCleanupOnFailure() ->expects($this->once()) ->method('delete'); - $this->quorum + $this->strategy ->expects($this->any()) ->method('canBeMet') ->willReturn(true); - $this->quorum + $this->strategy ->expects($this->any()) ->method('isMet') ->willReturn(false); @@ -234,7 +234,7 @@ public function testputOffExpirationCleanupOnFailure() } } - public function testputOffExpirationAbortWhenQuorumCantBeMet() + public function testputOffExpirationAbortWhenStrategyCantBeMet() { $key = new Key(uniqid(__METHOD__, true)); $ttl = random_int(1, 10); @@ -248,11 +248,11 @@ public function testputOffExpirationAbortWhenQuorumCantBeMet() ->expects($this->never()) ->method('putOffExpiration'); - $this->quorum + $this->strategy ->expects($this->once()) ->method('canBeMet') ->willReturn(false); - $this->quorum + $this->strategy ->expects($this->any()) ->method('isMet') ->willReturn(false); @@ -269,16 +269,16 @@ public function testPutOffExpirationIgnoreNonExpiringStorage() $store1 = $this->getMockBuilder(StoreInterface::class)->getMock(); $store2 = $this->getMockBuilder(StoreInterface::class)->getMock(); - $store = new CombinedStore(array($store1, $store2), $this->quorum); + $store = new CombinedStore(array($store1, $store2), $this->strategy); $key = new Key(uniqid(__METHOD__, true)); $ttl = random_int(1, 10); - $this->quorum + $this->strategy ->expects($this->any()) ->method('canBeMet') ->willReturn(true); - $this->quorum + $this->strategy ->expects($this->once()) ->method('isMet') ->with(2, 2) @@ -300,11 +300,11 @@ public function testExistsDontAskToEveryBody() ->expects($this->never()) ->method('exists'); - $this->quorum + $this->strategy ->expects($this->any()) ->method('canBeMet') ->willReturn(true); - $this->quorum + $this->strategy ->expects($this->once()) ->method('isMet') ->willReturn(true); @@ -312,7 +312,7 @@ public function testExistsDontAskToEveryBody() $this->assertTrue($this->store->exists($key)); } - public function testExistsAbortWhenQuorumCantBeMet() + public function testExistsAbortWhenStrategyCantBeMet() { $key = new Key(uniqid(__METHOD__, true)); @@ -325,11 +325,11 @@ public function testExistsAbortWhenQuorumCantBeMet() ->expects($this->never()) ->method('exists'); - $this->quorum + $this->strategy ->expects($this->once()) ->method('canBeMet') ->willReturn(false); - $this->quorum + $this->strategy ->expects($this->once()) ->method('isMet') ->willReturn(false); diff --git a/src/Symfony/Component/Lock/Tests/Quorum/ConsensusStrategyTest.php b/src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php similarity index 86% rename from src/Symfony/Component/Lock/Tests/Quorum/ConsensusStrategyTest.php rename to src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php index 1bebb184c7230..09215f9a94d63 100644 --- a/src/Symfony/Component/Lock/Tests/Quorum/ConsensusStrategyTest.php +++ b/src/Symfony/Component/Lock/Tests/Strategy/ConsensusStrategyTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Lock\Tests\Quorum; +namespace Symfony\Component\Lock\Tests\Strategy; use PHPUnit\Framework\TestCase; -use Symfony\Component\Lock\Quorum\ConsensusStrategy; +use Symfony\Component\Lock\Strategy\ConsensusStrategy; /** * @author Jérémy Derussé @@ -20,11 +20,11 @@ class ConsensusStrategyTest extends TestCase { /** @var ConsensusStrategy */ - private $quorum; + private $strategy; public function setup() { - $this->quorum = new ConsensusStrategy(); + $this->strategy = new ConsensusStrategy(); } public function provideMetResults() @@ -76,7 +76,7 @@ public function provideIndeterminate() */ public function testMet($success, $failure, $total, $isMet) { - $this->assertSame($isMet, $this->quorum->isMet($success, $total)); + $this->assertSame($isMet, $this->strategy->isMet($success, $total)); } /** @@ -84,6 +84,6 @@ public function testMet($success, $failure, $total, $isMet) */ public function canBeMet($success, $failure, $total, $isMet) { - $this->assertSame($isMet, $this->quorum->canBeMet($failure, $total)); + $this->assertSame($isMet, $this->strategy->canBeMet($failure, $total)); } } diff --git a/src/Symfony/Component/Lock/Tests/Quorum/UnanimousStrategyTest.php b/src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php similarity index 86% rename from src/Symfony/Component/Lock/Tests/Quorum/UnanimousStrategyTest.php rename to src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php index ea5934aab2498..76ea68a41e3b3 100644 --- a/src/Symfony/Component/Lock/Tests/Quorum/UnanimousStrategyTest.php +++ b/src/Symfony/Component/Lock/Tests/Strategy/UnanimousStrategyTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Lock\Tests\Quorum; +namespace Symfony\Component\Lock\Tests\Strategy; use PHPUnit\Framework\TestCase; -use Symfony\Component\Lock\Quorum\UnanimousStrategy; +use Symfony\Component\Lock\Strategy\UnanimousStrategy; /** * @author Jérémy Derussé @@ -20,11 +20,11 @@ class UnanimousStrategyTest extends TestCase { /** @var UnanimousStrategy */ - private $quorum; + private $strategy; public function setup() { - $this->quorum = new UnanimousStrategy(); + $this->strategy = new UnanimousStrategy(); } public function provideMetResults() @@ -76,7 +76,7 @@ public function provideIndeterminate() */ public function testMet($success, $failure, $total, $isMet) { - $this->assertSame($isMet, $this->quorum->isMet($success, $total)); + $this->assertSame($isMet, $this->strategy->isMet($success, $total)); } /** @@ -84,6 +84,6 @@ public function testMet($success, $failure, $total, $isMet) */ public function canBeMet($success, $failure, $total, $isMet) { - $this->assertSame($isMet, $this->quorum->canBeMet($failure, $total)); + $this->assertSame($isMet, $this->strategy->canBeMet($failure, $total)); } }