|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace YdbPlatform\Ydb\Test; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication; |
| 7 | +use YdbPlatform\Ydb\Logger\SimpleStdLogger; |
| 8 | +use YdbPlatform\Ydb\Ydb; |
| 9 | + |
| 10 | +class CheckTxSettingsTest extends TestCase |
| 11 | +{ |
| 12 | + |
| 13 | + /** |
| 14 | + * @var Ydb |
| 15 | + */ |
| 16 | + protected $ydb; |
| 17 | + /** |
| 18 | + * @var \YdbPlatform\Ydb\Table |
| 19 | + */ |
| 20 | + protected $table; |
| 21 | + /** |
| 22 | + * @var \YdbPlatform\Ydb\Session|null |
| 23 | + */ |
| 24 | + protected $session; |
| 25 | + |
| 26 | + public function __construct(?string $name = null, array $data = [], $dataName = '') |
| 27 | + { |
| 28 | + parent::__construct($name, $data, $dataName); |
| 29 | + $config = [ |
| 30 | + |
| 31 | + // Database path |
| 32 | + 'database' => '/local', |
| 33 | + |
| 34 | + // Database endpoint |
| 35 | + 'endpoint' => 'localhost:2136', |
| 36 | + |
| 37 | + // Auto discovery (dedicated server only) |
| 38 | + 'discovery' => false, |
| 39 | + |
| 40 | + // IAM config |
| 41 | + 'iam_config' => [ |
| 42 | + 'insecure' => true, |
| 43 | + ], |
| 44 | + 'credentials' => new AnonymousAuthentication() |
| 45 | + ]; |
| 46 | + $this->ydb = new Ydb($config, new SimpleStdLogger(SimpleStdLogger::DEBUG)); |
| 47 | + $this->table = $this->ydb->table(); |
| 48 | + $this->session = $this->table->session(); |
| 49 | + } |
| 50 | + |
| 51 | + public function testSerializableTxConfig(){ |
| 52 | + $this->checkTx('serializable', 'serializable_read_write'); |
| 53 | + } |
| 54 | + |
| 55 | + public function testSnapshotTxConfig(){ |
| 56 | + $this->checkTx('snapshot', 'snapshot_read_only'); |
| 57 | + } |
| 58 | + public function testStaleTxConfig(){ |
| 59 | + $this->checkTx('stale', 'stale_read_only'); |
| 60 | + } |
| 61 | + public function testOnlineTxConfig(){ |
| 62 | + $this->checkTx('online', 'online_read_only'); |
| 63 | + } |
| 64 | + |
| 65 | + protected function checkTx(string $mode, string $value) |
| 66 | + { |
| 67 | + $query= $this->session->newQuery("SELECT 1;") |
| 68 | + ->beginTx($mode); |
| 69 | + self::assertEquals($value, $query->getRequestData()['tx_control']->getBeginTx()->getTxMode()); |
| 70 | + $query->execute(); |
| 71 | + } |
| 72 | +} |
0 commit comments