Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renaming ExponentialBackoffPlugin to BackoffPlugin

  • Loading branch information...
commit 2de3507c534846a503d71093a5ae9c1fcd66dd25 1 parent 4c12cc0
@mtdowling mtdowling authored
View
10 composer.json
@@ -49,8 +49,6 @@
"symfony/event-dispatcher": "2.1.*"
},
- "minimum-stability": "beta",
-
"autoload": {
"psr-0": {
"Guzzle\\Tests": "tests/",
@@ -62,12 +60,8 @@
"doctrine/common": "*",
"symfony/class-loader": "*",
"monolog/monolog": "1.*",
- "zendframework/zend-cache": "2.0.0beta4",
- "zendframework/zend-log": "2.0.0beta4",
- "zendframework/zend-loader": "2.0.0beta4",
- "zendframework/zend-stdlib": "2.0.0beta4",
- "zendframework/zend-eventmanager": "2.0.0beta4",
- "zendframework/zend-servicemanager": "2.0.0beta4",
+ "zendframework/zend-cache": "2.0.*",
+ "zendframework/zend-log": "2.0.*",
"zend/zend-log1": "1.12",
"zend/zend-cache1": "1.12"
},
View
6 src/Guzzle/Plugin/Backoff/BackoffLogger.php
@@ -8,7 +8,7 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
- * Logs exponential backoff retries triggered from the ExponentialBackoffPlugin
+ * Logs backoff retries triggered from the BackoffPlugin
*
* Format your log messages using a template that can contain the the following variables:
*
@@ -43,7 +43,7 @@ class BackoffLogger implements EventSubscriberInterface
protected $template;
/**
- * Exponential backoff retry logger
+ * Backoff retry logger
*
* @param LogAdapterInterface $logger Logger used to log the retries
* @param string $template Log message template
@@ -59,7 +59,7 @@ public function __construct(LogAdapterInterface $logger, $template = self::DEFAU
*/
public static function getSubscribedEvents()
{
- return array(ExponentialBackoffPlugin::RETRY_EVENT => 'onRequestRetry');
+ return array(BackoffPlugin::RETRY_EVENT => 'onRequestRetry');
}
/**
View
25 ...ugin/Backoff/ExponentialBackoffPlugin.php → src/Guzzle/Plugin/Backoff/BackoffPlugin.php
@@ -13,14 +13,13 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
- * Plugin to automatically retry failed HTTP requests using truncated
- * exponential backoff.
+ * Plugin to automatically retry failed HTTP requests using a backoff strategy
*/
-class ExponentialBackoffPlugin extends AbstractHasDispatcher implements EventSubscriberInterface
+class BackoffPlugin extends AbstractHasDispatcher implements EventSubscriberInterface
{
- const DELAY_PARAM = 'plugins.exponential_backoff.retry_time';
- const RETRY_PARAM = 'plugins.exponential_backoff.retry_count';
- const RETRY_EVENT = 'plugins.exponential_backoff.retry';
+ const DELAY_PARAM = 'plugins.backoff.retry_time';
+ const RETRY_PARAM = 'plugins.backoff.retry_count';
+ const RETRY_EVENT = 'plugins.backoff.retry';
/**
* @var array|callable Hash table of failure codes or PHP callable
@@ -57,8 +56,6 @@ class ExponentialBackoffPlugin extends AbstractHasDispatcher implements EventSub
protected static $defaultFailureCodesHash;
/**
- * Construct a new exponential backoff plugin
- *
* $failureCodes can be a list of numeric codes that match the response
* code, a list of reason phrases that can match the reason phrase of a
* request, or a list of cURL error code integers. By default, this
@@ -128,7 +125,7 @@ public static function getSubscribedEvents()
*
* @param integer $maxRetries The maximum number of retries.
*
- * @return ExponentialBackoffPlugin
+ * @return self
*/
public function setMaxRetries($maxRetries)
{
@@ -148,8 +145,7 @@ public function getMaxRetries()
}
/**
- * Get the HTTP response codes that should be retried using truncated
- * exponential backoff
+ * Get the HTTP response codes that should be retried
*
* @return array
*/
@@ -159,12 +155,11 @@ public function getFailureCodes()
}
/**
- * Set the HTTP response codes that should be retried using truncated
- * exponential backoff
+ * Set the HTTP response codes that should be retried
*
* @param mixed $codes Array of HTTP response codes or PHP callable
*
- * @return ExponentialBackoffPlugin
+ * @return self
*/
public function setFailureCodes($codes = null)
{
@@ -182,7 +177,7 @@ public function setFailureCodes($codes = null)
}
/**
- * Determine how long to wait using truncated exponential backoff
+ * Determine how long to wait
*
* @param int $retries Number of retries so far
*
View
58 ...Plugin/Backoff/ExponentialBackoffTest.php → ...zzle/Tests/Plugin/Backoff/BackoffTest.php
@@ -5,7 +5,7 @@
use Guzzle\Common\Event;
use Guzzle\Http\Exception\CurlException;
use Guzzle\Http\Client;
-use Guzzle\Plugin\Backoff\ExponentialBackoffPlugin;
+use Guzzle\Plugin\Backoff\BackoffPlugin;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Request;
use Guzzle\Http\Message\EntityEnclosingRequest;
@@ -16,7 +16,7 @@
/**
* @group server
*/
-class ExponentialBackoffPluginTest extends \Guzzle\Tests\GuzzleTestCase
+class BackoffPluginTest extends \Guzzle\Tests\GuzzleTestCase
{
public function delayClosure($retries)
{
@@ -28,7 +28,7 @@ public function delayClosure($retries)
*/
public function testHasEventList()
{
- $this->assertEquals(1, count(ExponentialBackoffPlugin::getAllEvents()));
+ $this->assertEquals(1, count(BackoffPlugin::getAllEvents()));
}
/**
@@ -41,7 +41,7 @@ public function testHasEventList()
*/
public function testConstructsCorrectly()
{
- $plugin = new ExponentialBackoffPlugin(2, array(500, 503, 502), array($this, 'delayClosure'));
+ $plugin = new BackoffPlugin(2, array(500, 503, 502), array($this, 'delayClosure'));
$this->assertEquals(2, $plugin->getMaxRetries());
$this->assertEquals(array(500, 503, 502), $plugin->getFailureCodes());
@@ -55,7 +55,7 @@ public function testConstructsCorrectly()
*/
public function testCalculateWait()
{
- $plugin = new ExponentialBackoffPlugin(2);
+ $plugin = new BackoffPlugin(2);
$this->assertEquals(1, $plugin->calculateWait(0));
$this->assertEquals(2, $plugin->calculateWait(1));
$this->assertEquals(4, $plugin->calculateWait(2));
@@ -76,7 +76,7 @@ public function testRetriesRequests()
"HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata"
));
- $plugin = new ExponentialBackoffPlugin(2, null, array($this, 'delayClosure'));
+ $plugin = new BackoffPlugin(2, null, array($this, 'delayClosure'));
$client = new Client($this->getServer()->getUrl());
$client->getEventDispatcher()->addSubscriber($plugin);
$request = $client->get();
@@ -103,7 +103,7 @@ public function testRetriesRequestsUsingReasonPhraseMatch()
"HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\ndata"
));
- $plugin = new ExponentialBackoffPlugin(2, array('FooError'), array($this, 'delayClosure'));
+ $plugin = new BackoffPlugin(2, array('FooError'), array($this, 'delayClosure'));
$client = new Client($this->getServer()->getUrl());
$client->getEventDispatcher()->addSubscriber($plugin);
$request = $client->get();
@@ -132,7 +132,7 @@ public function testAllowsFailureOnMaxRetries()
"HTTP/1.1 500 Internal Server Error\r\nContent-Length: 0\r\n\r\n"
));
- $plugin = new ExponentialBackoffPlugin(2, null, array($this, 'delayClosure'));
+ $plugin = new BackoffPlugin(2, null, array($this, 'delayClosure'));
$client = new Client($this->getServer()->getUrl());
$client->getEventDispatcher()->addSubscriber($plugin);
$request = $client->get();
@@ -142,8 +142,8 @@ public function testAllowsFailureOnMaxRetries()
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestSent
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestPoll
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestSent
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestPoll
* @covers Guzzle\Http\Curl\CurlMulti
*/
public function testRetriesPooledRequestsUsingDelayAndPollingEvent()
@@ -156,7 +156,7 @@ public function testRetriesPooledRequestsUsingDelayAndPollingEvent()
// Need to sleep for one second to make sure that the polling works
// correctly in the observer
- $plugin = new ExponentialBackoffPlugin(1, null, function($r) {
+ $plugin = new BackoffPlugin(1, null, function($r) {
return 1;
});
@@ -173,30 +173,30 @@ public function testRetriesPooledRequestsUsingDelayAndPollingEvent()
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::getDefaultFailureCodes
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::getDefaultFailureCodes
*/
public function testReturnsDefaultFailureCodes()
{
- $this->assertNotEmpty(ExponentialBackoffPlugin::getDefaultFailureCodes());
+ $this->assertNotEmpty(BackoffPlugin::getDefaultFailureCodes());
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::__construct
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::getDefaultFailureCodes
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::__construct
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::getDefaultFailureCodes
*/
public function testUsesDefaultFailureCodesByDefault()
{
- $p = new ExponentialBackoffPlugin();
- $this->assertEquals($p->getFailureCodes(), ExponentialBackoffPlugin::getDefaultFailureCodes());
+ $p = new BackoffPlugin();
+ $this->assertEquals($p->getFailureCodes(), BackoffPlugin::getDefaultFailureCodes());
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestSent
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestSent
*/
public function testAllowsCallableFailureCodes()
{
$a = 0;
- $plugin = new ExponentialBackoffPlugin(1, function($request, $response) use (&$a) {
+ $plugin = new BackoffPlugin(1, function($request, $response) use (&$a) {
// Look for a Foo header
if ($response->hasHeader('Foo')) {
$a = 1;
@@ -224,11 +224,11 @@ public function testAllowsCallableFailureCodes()
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestSent
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestSent
*/
public function testExponentiallyBacksOffCurlErrors()
{
- $plugin = $this->getMock('Guzzle\Plugin\Backoff\ExponentialBackoffPlugin', array('retryRequest'));
+ $plugin = $this->getMock('Guzzle\Plugin\Backoff\BackoffPlugin', array('retryRequest'));
// Mock the retryRequest method so that it does nothing, but ensure
// that it is called exactly once
@@ -254,13 +254,13 @@ public function testExponentiallyBacksOffCurlErrors()
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestSent
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestSent
*/
public function testAllowsCustomFailureMethodsToPuntToDefaultMethod()
{
$count = 0;
- $plugin = $this->getMockBuilder('Guzzle\Plugin\Backoff\ExponentialBackoffPlugin')
+ $plugin = $this->getMockBuilder('Guzzle\Plugin\Backoff\BackoffPlugin')
->setMethods(array('retryRequest'))
->setConstructorArgs(array(2, function() use (&$count) {
$count++;
@@ -282,7 +282,7 @@ public function testAllowsCustomFailureMethodsToPuntToDefaultMethod()
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestPoll
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestPoll
*/
public function testSeeksToBeginningOfRequestBodyWhenRetrying()
{
@@ -290,27 +290,27 @@ public function testSeeksToBeginningOfRequestBodyWhenRetrying()
$request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
$request->setBody('abc');
// Set the retry time to be something that will be retried always
- $request->getParams()->set('plugins.exponential_backoff.retry_time', 2);
+ $request->getParams()->set('plugins.backoff.retry_time', 2);
// Seek to the end of the stream
$request->getBody()->seek(3);
$this->assertEquals('', $request->getBody()->read(1));
// Create a plugin that does not delay when retrying
- $plugin = new ExponentialBackoffPlugin(2, null, array($this, 'delayClosure'));
+ $plugin = new BackoffPlugin(2, null, array($this, 'delayClosure'));
$plugin->onRequestPoll($this->getMockEvent($request));
// Ensure that the stream was seeked to 0
$this->assertEquals('a', $request->getBody()->read(1));
}
/**
- * @covers Guzzle\Plugin\Backoff\ExponentialBackoffPlugin::onRequestPoll
+ * @covers Guzzle\Plugin\Backoff\BackoffPlugin::onRequestPoll
*/
public function testDoesNotSeekOnRequestsWithNoBodyWhenRetrying()
{
// Create a request with a body
$request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
- $request->getParams()->set('plugins.exponential_backoff.retry_time', 2);
- $plugin = new ExponentialBackoffPlugin(2, null, array($this, 'delayClosure'));
+ $request->getParams()->set('plugins.backoff.retry_time', 2);
+ $plugin = new BackoffPlugin(2, null, array($this, 'delayClosure'));
$plugin->onRequestPoll($this->getMockEvent($request));
}
Please sign in to comment.
Something went wrong with that request. Please try again.