From a363f79d6a32e9ddc22c9023e1a497377ccbf3a0 Mon Sep 17 00:00:00 2001 From: Jake Wright Date: Tue, 14 Mar 2017 15:21:25 +0000 Subject: [PATCH] Rename getBackoffPeriod to calculateBackoffPeriod --- src/RetryStrategy/ExponentialBackoffStrategy.php | 2 +- src/RetryStrategy/RetryStrategyInterface.php | 2 +- src/TransientFaultHandler.php | 2 +- .../ExponentialBackoffStrategyTest.php | 2 +- tests/unit/TransientFaultHandlerTest.php | 14 +++++++------- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/RetryStrategy/ExponentialBackoffStrategy.php b/src/RetryStrategy/ExponentialBackoffStrategy.php index 01a78ac..d77096f 100644 --- a/src/RetryStrategy/ExponentialBackoffStrategy.php +++ b/src/RetryStrategy/ExponentialBackoffStrategy.php @@ -58,7 +58,7 @@ public function __construct($maxRetries = 2, $firstFastRetry = false, $multiplie * @param int $retryCount * @return int */ - public function getBackoffPeriod($retryCount) + public function calculateBackoffPeriod($retryCount) { $offset = $this->firstFastRetry ? $this->multiplier : 0; $backoff = $this->minBackoff + rand(0, $this->multiplier * pow(2, $retryCount) - $offset); diff --git a/src/RetryStrategy/RetryStrategyInterface.php b/src/RetryStrategy/RetryStrategyInterface.php index 6cb488d..141c85c 100644 --- a/src/RetryStrategy/RetryStrategyInterface.php +++ b/src/RetryStrategy/RetryStrategyInterface.php @@ -30,5 +30,5 @@ public function shouldRetry($retryCount); * @param int $retryCount * @return int */ - public function getBackoffPeriod($retryCount); + public function calculateBackoffPeriod($retryCount); } diff --git a/src/TransientFaultHandler.php b/src/TransientFaultHandler.php index 0333220..46e44cd 100644 --- a/src/TransientFaultHandler.php +++ b/src/TransientFaultHandler.php @@ -104,7 +104,7 @@ public function execute(callable $task) break; } - $backoffPeriod = $this->retryStrategy->getBackoffPeriod($retryCount); + $backoffPeriod = $this->retryStrategy->calculateBackoffPeriod($retryCount); $retryCount++; if ($this->logger) { diff --git a/tests/unit/RetryStrategy/ExponentialBackoffStrategyTest.php b/tests/unit/RetryStrategy/ExponentialBackoffStrategyTest.php index 55ef220..61ab4de 100644 --- a/tests/unit/RetryStrategy/ExponentialBackoffStrategyTest.php +++ b/tests/unit/RetryStrategy/ExponentialBackoffStrategyTest.php @@ -32,7 +32,7 @@ class ExponentialBackoffStrategyTest extends TestCase public function testBackoffPeriodIsAboveMinimum($maxRetries, $firstFastRetry, $multiplier, $minBackoff, $maxBackoff, $retryCount) { $strategy = new ExponentialBackoffStrategy($maxRetries, $firstFastRetry, $multiplier, $minBackoff, $maxBackoff); - $this->assertGreaterThanOrEqual($minBackoff, $strategy->getBackoffPeriod($retryCount)); + $this->assertGreaterThanOrEqual($minBackoff, $strategy->calculateBackoffPeriod($retryCount)); } /** diff --git a/tests/unit/TransientFaultHandlerTest.php b/tests/unit/TransientFaultHandlerTest.php index 8378ec1..1b17ecd 100644 --- a/tests/unit/TransientFaultHandlerTest.php +++ b/tests/unit/TransientFaultHandlerTest.php @@ -60,7 +60,7 @@ public function testDoesNotRetryAfterSuccess(array $isTransientReturnValues, $ex // Mock the retry strategy $this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true); - $this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0); + $this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0); // Mock the Sleep class $this->sleep->shouldReceive('milliSleep'); @@ -113,7 +113,7 @@ public function testDoesNotRetryAfterNonTransientException() // Mock the retry strategy $this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true); - $this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0); + $this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0); // Mock the Sleep class $this->sleep->shouldReceive('milliSleep'); @@ -150,7 +150,7 @@ public function testTransientExceptionsIgnored() // Mock the retry strategy $this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true); - $this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0); + $this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0); // Mock the Sleep class $this->sleep->shouldReceive('milliSleep'); @@ -189,7 +189,7 @@ public function testRetriesAccordingToRetryStrategy() // Mock the retry strategy $this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true, true, true, false); - $this->retryStrategy->shouldReceive('getBackoffPeriod')->andReturn(0); + $this->retryStrategy->shouldReceive('calculateBackoffPeriod')->andReturn(0); // Mock the Sleep class $this->sleep->shouldReceive('milliSleep'); @@ -229,7 +229,7 @@ public function testSleepsAccordingToRetryStrategy(array $backoffPeriods, array // Mock the retry strategy $expectation = $this->retryStrategy->shouldReceive('shouldRetry'); call_user_func_array([$expectation, 'andReturn'], $shouldRetryReturnValues); - $expectation = $this->retryStrategy->shouldReceive('getBackoffPeriod'); + $expectation = $this->retryStrategy->shouldReceive('calculateBackoffPeriod'); call_user_func_array([$expectation, 'andReturn'], $backoffPeriods); // Mock the Sleep class @@ -272,8 +272,8 @@ public function testRetryCountIsIncremented() // Mock the retry strategy $this->retryStrategy->shouldReceive('shouldRetry')->andReturn(true, true, false); - $this->retryStrategy->shouldReceive('getBackoffPeriod')->with(0)->andReturn(0); - $this->retryStrategy->shouldReceive('getBackoffPeriod')->with(1)->andReturn(0); + $this->retryStrategy->shouldReceive('calculateBackoffPeriod')->with(0)->andReturn(0); + $this->retryStrategy->shouldReceive('calculateBackoffPeriod')->with(1)->andReturn(0); // Mock the Sleep class $this->sleep->shouldReceive('milliSleep');