123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request;
- use Exception;
- use AlibabaCloud\Client\Support\Stringy;
- use PHPUnit\Framework\TestCase;
- use AlibabaCloud\Client\AlibabaCloud;
- use AlibabaCloud\Client\Exception\ClientException;
- /**
- * Class RetryByServerTest
- *
- * @package AlibabaCloud\Client\Tests\LowerthanVersion7_2\Feature\Request
- * @coversDefaultClass \AlibabaCloud\Client\Request\RpcRequest
- */
- class RetryByServerTest extends TestCase
- {
- protected function setUp()
- {
- AlibabaCloud::forgetHistory();
- AlibabaCloud::rememberHistory();
- }
- /**
- * @throws ClientException
- * @throws Exception
- */
- public function testNoRetry()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->asDefaultClient()->regionId('cn-hangzhou');
- try {
- AlibabaCloud::rpc()
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnServiceNotFound')
- ->connectTimeout(25)
- ->timeout(30)
- ->request();
- } catch (Exception $exception) {
- self::assertFalse(Stringy::contains($exception->getMessage(), 'Action or Version'));
- self::assertEquals(1, AlibabaCloud::countHistory());
- }
- }
- /**
- * @throws ClientException
- * @throws Exception
- */
- public function testRetryWithStrings()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->asDefaultClient()->regionId('cn-hangzhou');
- try {
- AlibabaCloud::rpc()
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnServiceNotFound')
- ->connectTimeout(25)
- ->timeout(30)
- ->retryByServer(3, ['Action or Version'])
- ->request();
- } catch (Exception $exception) {
- self::assertFalse(Stringy::contains($exception->getMessage(), 'Action or Version'));
- self::assertEquals(1, AlibabaCloud::countHistory());
- }
- }
- /**
- * @throws ClientException
- * @throws Exception
- */
- public function testRetryWithStatusCode()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->asDefaultClient()->regionId('cn-hangzhou');
- try {
- AlibabaCloud::rpc()
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnServiceNotFound')
- ->connectTimeout(25)
- ->timeout(30)
- ->retryByServer(3, [], [404])
- ->request();
- } catch (Exception $exception) {
- self::assertFalse(Stringy::contains($exception->getMessage(), 'Action or Version'));
- self::assertEquals(4, AlibabaCloud::countHistory());
- }
- }
- /**
- * @throws ClientException
- * @throws Exception
- */
- public function testRetryWithFalse()
- {
- AlibabaCloud::accessKeyClient(
- \getenv('ACCESS_KEY_ID'),
- \getenv('ACCESS_KEY_SECRET')
- )->asDefaultClient()->regionId('cn-hangzhou');
- try {
- AlibabaCloud::rpc()
- ->method('POST')
- ->product('Cdn')
- ->version('2014-11-11')
- ->action('DescribeCdnServiceNotFound')
- ->connectTimeout(25)
- ->timeout(30)
- ->retryByServer(3, [], [])
- ->request();
- } catch (Exception $exception) {
- self::assertFalse(Stringy::contains($exception->getMessage(), 'Action or Version'));
- self::assertEquals(1, AlibabaCloud::countHistory());
- }
- }
- }
|