Skip to content

Commit 4c84d15

Browse files
author
Илья
committed
Added lambda on exception in retryTransaction
1 parent 1740b77 commit 4c84d15

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

src/Table.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,16 @@ public function retryTransaction(Closure $userFunc, bool $idempotent = null, Ret
487487
}
488488

489489
if (isset($options['idempotent']) && !is_null($idempotent)){
490-
throw new Exception('...');
490+
throw new \YdbPlatform\Ydb\Exception('Idempotent flag set in 2 params');
491491
}
492-
else if (!isset($options['idempotent'])) {
492+
else if (!is_null($idempotent)) {
493493
$options['idempotent'] = $idempotent;
494+
} else {
495+
$options['idempotent'] = false;
494496
}
495497

496498
if (isset($options['retryParams']) && !is_null($params)){
497-
throw new Exception('...');
499+
throw new \YdbPlatform\Ydb\Exception('RetryParams set in 2 params');
498500
}
499501
else if (!isset($options['retryParams'])) {
500502
$options['retryParams'] = $params;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace YdbPlatform\Ydb\Test;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use YdbPlatform\Ydb\Exception;
7+
use YdbPlatform\Ydb\Retry\RetryParams;
8+
use YdbPlatform\Ydb\Session;
9+
use YdbPlatform\Ydb\Ydb;
10+
use YdbPlatform\Ydb\YdbTable;
11+
12+
class CheckParamsInRetryTransactionTest extends TestCase
13+
{
14+
public function testRun()
15+
{
16+
$config = [
17+
18+
// Database path
19+
'database' => '/local',
20+
21+
// Database endpoint
22+
'endpoint' => 'localhost:2136',
23+
24+
// Auto discovery (dedicated server only)
25+
'discovery' => false,
26+
27+
// IAM config
28+
'iam_config' => [
29+
'anonymous' => true,
30+
'insecure' => true
31+
],
32+
];
33+
34+
$ydb = new Ydb($config);
35+
36+
$table = $ydb->table();
37+
38+
try {
39+
$table->retryTransaction(function (Session $session){}, true, null, ['idempotent'=>true]);
40+
throw new \Exception('retryTransaction does not throw exception');
41+
} catch (\YdbPlatform\Ydb\Exception $e){
42+
self::assertEquals(1,1);
43+
}
44+
45+
try {
46+
$table->retryTransaction(function (Session $session){}, null, new RetryParams(), ['retryParams'=>new RetryParams()]);
47+
throw new \Exception('retryTransaction does not throw exception');
48+
} catch (\YdbPlatform\Ydb\Exception $e){
49+
self::assertEquals(1,1);
50+
}
51+
52+
}
53+
}

0 commit comments

Comments
 (0)