CheckTimeoutAndDurationParamsTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication;
  5. use YdbPlatform\Ydb\Logger\SimpleStdLogger;
  6. use YdbPlatform\Ydb\Session;
  7. use YdbPlatform\Ydb\Ydb;
  8. class CheckTimeoutAndDurationParamsTest extends TestCase
  9. {
  10. public function testTimeoutAndDurationParams(){
  11. $config = [
  12. // Database path
  13. 'database' => '/local',
  14. // Database endpoint
  15. 'endpoint' => 'localhost:2136',
  16. // Auto discovery (dedicated server only)
  17. 'discovery' => false,
  18. // IAM config
  19. 'iam_config' => [
  20. 'insecure' => true,
  21. ],
  22. 'credentials' => new AnonymousAuthentication()
  23. ];
  24. $ydb = new Ydb($config, new SimpleStdLogger(7));
  25. $table = $ydb->table();
  26. $this->expectException('YdbPlatform\Ydb\Exceptions\Ydb\TimeoutException');
  27. $table->retrySession(function (Session $session){
  28. $session->query('SELECT 1;', null, [
  29. 'operation_timeout_ms' => 1e-5
  30. ]);
  31. });
  32. $this->expectException('YdbPlatform\Ydb\Exceptions\Ydb\CancelledException');
  33. $table->retrySession(function (Session $session){
  34. $session->query('SELECT 1;', null, [
  35. 'cancel_after_ms' => 1e-5
  36. ]);
  37. });
  38. }
  39. }