CheckTxSettingsTest.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace YdbPlatform\Ydb\Test;
  3. use PHPUnit\Framework\TestCase;
  4. use Ydb\Table\OnlineModeSettings;
  5. use Ydb\Table\SerializableModeSettings;
  6. use Ydb\Table\SnapshotModeSettings;
  7. use Ydb\Table\StaleModeSettings;
  8. use YdbPlatform\Ydb\Auth\Implement\AnonymousAuthentication;
  9. use YdbPlatform\Ydb\Logger\SimpleStdLogger;
  10. use YdbPlatform\Ydb\Ydb;
  11. use function YdbPlatform\Ydb\parseTxMode;
  12. require_once __DIR__.'/../src/Session.php';
  13. class CheckTxSettingsTest extends TestCase
  14. {
  15. public function testParseTxMode(?string $name = null, array $data = [], $dataName = '')
  16. {
  17. parent::__construct($name, $data, $dataName);
  18. $config = [
  19. // Database path
  20. 'database' => '/local',
  21. // Database endpoint
  22. 'endpoint' => 'localhost:2136',
  23. // Auto discovery (dedicated server only)
  24. 'discovery' => false,
  25. // IAM config
  26. 'iam_config' => [
  27. 'insecure' => true,
  28. ],
  29. 'credentials' => new AnonymousAuthentication()
  30. ];
  31. $ydb = new Ydb($config, new SimpleStdLogger(SimpleStdLogger::DEBUG));
  32. $table = $ydb->table();
  33. $session = $table->createSession();
  34. $testsQuery = [
  35. ['mode' => 'stale_read_only', 'result' => ['stale_read_only' => new StaleModeSettings], 'interactive' => false],
  36. ['mode' => 'stale', 'result' => ['stale_read_only' => new StaleModeSettings], 'interactive' => false],
  37. ['mode' => 'online_read_only', 'result' => ['online_read_only' => new OnlineModeSettings([
  38. 'allow_inconsistent_reads' => false,
  39. ])], 'interactive' => false],
  40. ['mode' => 'online', 'result' => ['online_read_only' => new OnlineModeSettings([
  41. 'allow_inconsistent_reads' => false,
  42. ])], 'interactive' => false],
  43. ['mode' => 'inconsistent_reads', 'result' => ['online_read_only' => new OnlineModeSettings([
  44. 'allow_inconsistent_reads' => true,
  45. ])], 'interactive' => false],
  46. ['mode' => 'online_inconsistent', 'result' => ['online_read_only' => new OnlineModeSettings([
  47. 'allow_inconsistent_reads' => true,
  48. ])], 'interactive' => false],
  49. ['mode' => 'online_inconsistent_reads', 'result' => ['online_read_only' => new OnlineModeSettings([
  50. 'allow_inconsistent_reads' => true,
  51. ])], 'interactive' => false],
  52. ['mode' => 'snapshot', 'result' => ['snapshot_read_only' => new SnapshotModeSettings], 'interactive' => true],
  53. ['mode' => 'snapshot_read_only', 'result' => ['snapshot_read_only' => new SnapshotModeSettings], 'interactive' => true],
  54. ['mode' => 'serializable', 'result' => ['serializable_read_write' => new SerializableModeSettings], 'interactive' => true],
  55. ['mode' => 'serializable_read_write', 'result' => ['serializable_read_write' => new SerializableModeSettings], 'interactive' => true],
  56. ];
  57. foreach ($testsQuery as $i => $test){
  58. self::assertEquals($test["result"], parseTxMode($test["mode"]));
  59. $query= $session->newQuery("SELECT 1;")
  60. ->beginTx($test['mode']);
  61. $query->execute();
  62. if ($test['interactive']){
  63. $table->transaction(function (){}, $test['mode']);
  64. }
  65. }
  66. }
  67. }