Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[lock] Rename Quorum into Strategy #22114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions 26 src/Symfony/Component/Lock/Store/CombinedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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) {
Expand All @@ -50,7 +50,7 @@ public function __construct(array $stores, QuorumInterface $quorum)
}

$this->stores = $stores;
$this->quorum = $quorum;
$this->strategy = $strategy;
$this->logger = new NullLogger();
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
54 changes: 27 additions & 27 deletions 54 src/Symfony/Component/Lock/Tests/Store/CombinedStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
}

/**
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -135,7 +135,7 @@ public function testSaveCleanupOnFailure()
}
}

public function testSaveAbortWhenQuorumCantBeMet()
public function testSaveAbortWhenStrategyCantBeMet()
{
$key = new Key(uniqid(__METHOD__, true));

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -234,7 +234,7 @@ public function testputOffExpirationCleanupOnFailure()
}
}

public function testputOffExpirationAbortWhenQuorumCantBeMet()
public function testputOffExpirationAbortWhenStrategyCantBeMet()
{
$key = new Key(uniqid(__METHOD__, true));
$ttl = random_int(1, 10);
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -300,19 +300,19 @@ 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);

$this->assertTrue($this->store->exists($key));
}

public function testExistsAbortWhenQuorumCantBeMet()
public function testExistsAbortWhenStrategyCantBeMet()
{
$key = new Key(uniqid(__METHOD__, true));

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
* 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>
*/
class ConsensusStrategyTest extends TestCase
{
/** @var ConsensusStrategy */
private $quorum;
private $strategy;

public function setup()
{
$this->quorum = new ConsensusStrategy();
$this->strategy = new ConsensusStrategy();
}

public function provideMetResults()
Expand Down Expand Up @@ -76,14 +76,14 @@ 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));
}

/**
* @dataProvider provideIndeterminate
*/
public function canBeMet($success, $failure, $total, $isMet)
{
$this->assertSame($isMet, $this->quorum->canBeMet($failure, $total));
$this->assertSame($isMet, $this->strategy->canBeMet($failure, $total));
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.