Rename Quorum into Strategy
This commit is contained in:
parent
59dd7521a7
commit
1e9671b993
@ -18,7 +18,7 @@ use Symfony\Component\Lock\Exception\InvalidArgumentException;
|
||||
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 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 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
}
|
||||
|
||||
$this->stores = $stores;
|
||||
$this->quorum = $quorum;
|
||||
$this->strategy = $strategy;
|
||||
$this->logger = new NullLogger();
|
||||
}
|
||||
|
||||
@ -72,12 +72,12 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
++$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 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
++$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 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface
|
||||
++$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;
|
||||
}
|
||||
}
|
||||
|
@ -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é <jeremy@derusse.com>
|
||||
*/
|
||||
class ConsensusStrategy implements QuorumInterface
|
||||
class ConsensusStrategy implements StrategyInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
@ -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é <jeremy@derusse.com>
|
||||
*/
|
||||
interface QuorumInterface
|
||||
interface StrategyInterface
|
||||
{
|
||||
/**
|
||||
* Returns whether or not the quorum is met.
|
@ -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é <jeremy@derusse.com>
|
||||
*/
|
||||
class UnanimousStrategy implements QuorumInterface
|
||||
class UnanimousStrategy implements StrategyInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
@ -13,8 +13,8 @@ namespace Symfony\Component\Lock\Tests\Store;
|
||||
|
||||
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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
}
|
||||
|
||||
/** @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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
|
||||
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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testSaveAbortWhenQuorumCantBeMet()
|
||||
public function testSaveAbortWhenStrategyCantBeMet()
|
||||
{
|
||||
$key = new Key(uniqid(__METHOD__, true));
|
||||
|
||||
@ -148,11 +148,11 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testputOffExpirationAbortWhenQuorumCantBeMet()
|
||||
public function testputOffExpirationAbortWhenStrategyCantBeMet()
|
||||
{
|
||||
$key = new Key(uniqid(__METHOD__, true));
|
||||
$ttl = random_int(1, 10);
|
||||
@ -248,11 +248,11 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
$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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
$this->assertTrue($this->store->exists($key));
|
||||
}
|
||||
|
||||
public function testExistsAbortWhenQuorumCantBeMet()
|
||||
public function testExistsAbortWhenStrategyCantBeMet()
|
||||
{
|
||||
$key = new Key(uniqid(__METHOD__, true));
|
||||
|
||||
@ -325,11 +325,11 @@ class CombinedStoreTest extends AbstractStoreTest
|
||||
->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);
|
||||
|
@ -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é <jeremy@derusse.com>
|
||||
@ -20,11 +20,11 @@ use Symfony\Component\Lock\Quorum\ConsensusStrategy;
|
||||
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 @@ class ConsensusStrategyTest extends TestCase
|
||||
*/
|
||||
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 @@ class ConsensusStrategyTest extends TestCase
|
||||
*/
|
||||
public function canBeMet($success, $failure, $total, $isMet)
|
||||
{
|
||||
$this->assertSame($isMet, $this->quorum->canBeMet($failure, $total));
|
||||
$this->assertSame($isMet, $this->strategy->canBeMet($failure, $total));
|
||||
}
|
||||
}
|
@ -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é <jeremy@derusse.com>
|
||||
@ -20,11 +20,11 @@ use Symfony\Component\Lock\Quorum\UnanimousStrategy;
|
||||
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 @@ class UnanimousStrategyTest extends TestCase
|
||||
*/
|
||||
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 @@ class UnanimousStrategyTest extends TestCase
|
||||
*/
|
||||
public function canBeMet($success, $failure, $total, $isMet)
|
||||
{
|
||||
$this->assertSame($isMet, $this->quorum->canBeMet($failure, $total));
|
||||
$this->assertSame($isMet, $this->strategy->canBeMet($failure, $total));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user