| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Service_WindowsAzure
- * @subpackage UnitTests
- * @version $Id$
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- if (!defined('PHPUnit_MAIN_METHOD')) {
- define('PHPUnit_MAIN_METHOD', 'Zend_Service_WindowsAzure_RetryPolicyTest::main');
- }
- /**
- * Test helpers
- */
- require_once dirname(__FILE__) . '/../../../TestHelper.php';
- require_once dirname(__FILE__) . '/../../../TestConfiguration.php.dist';
- /** Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract */
- require_once 'Zend/Service/WindowsAzure/RetryPolicy/RetryPolicyAbstract.php';
- /**
- * @category Zend
- * @package Zend_Service_WindowsAzure
- * @subpackage UnitTests
- * @version $Id$
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Service_WindowsAzure_RetryPolicyTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Helper variable for counting retries
- *
- * @var int
- */
- protected $_executedRetries = 0;
-
- /**
- * Helper variable for setting Exception count
- *
- * @var int
- */
- protected $_exceptionCount = 0;
-
- public static function main()
- {
- $suite = new PHPUnit_Framework_TestSuite("Zend_Service_WindowsAzure_RetryPolicyTest");
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- /**
- * Test retry policy - noRetry
- */
- public function testNoRetry()
- {
- $this->_executedRetries = 0;
- $policy = Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::noRetry();
- $retries = $policy->execute(
- array($this, '_countRetries')
- );
- $this->assertEquals(1, $retries);
- }
-
- /**
- * Test retry policy - retryN
- */
- public function testRetryN()
- {
- $this->_executedRetries = 0;
- $this->_exceptionCount = 9;
-
- $policy = Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract::retryN(10, 100);
- $retries = $policy->execute(
- array($this, '_countRetriesAndThrowExceptions')
- );
- $this->assertEquals(10, $retries);
- }
-
- /**
- * Helper function, counting retries
- */
- public function _countRetries()
- {
- return ++$this->_executedRetries;
- }
-
- /**
- * Helper function, counting retries and generating number of exceptions
- */
- public function _countRetriesAndThrowExceptions()
- {
- ++$this->_executedRetries;
- if ($this->_exceptionCount-- > 0) {
- throw new Exception("Exception thrown.");
- }
- return $this->_executedRetries;
- }
- }
- // Call Zend_Service_WindowsAzure_RetryPolicyTest::main() if this source file is executed directly.
- if (PHPUnit_MAIN_METHOD == "Zend_Service_WindowsAzure_RetryPolicyTest::main") {
- Zend_Service_WindowsAzure_RetryPolicyTest::main();
- }
|