Skip to content

Commit 09ad561

Browse files
committed
Update tests
1 parent 54e920b commit 09ad561

13 files changed

+347
-258
lines changed

examples/app/Commands/BasicExampleCommand.php

Lines changed: 156 additions & 124 deletions
Large diffs are not rendered by default.

examples/app/Commands/CreateTableCommand.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use YdbPlatform\Ydb\Session;
1011

1112
class CreateTableCommand extends Command
1213
{
@@ -48,17 +49,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
4849

4950
$ydb = $this->appService->initYdb();
5051

51-
$session = $ydb->table()->session();
52+
$ydb->table()->retrySession(function (Session $session){
5253

53-
$result = $session->createTable($table_name, $columns, 'id');
54+
$result = $session->createTable($table_name, $columns, 'id');
5455

55-
$output->writeln('Table ' . $table_name . ' has been created.');
56+
$output->writeln('Table ' . $table_name . ' has been created.');
5657

57-
$session->transaction(function($session) use ($table_name, $columns) {
58-
$session->query('upsert into `' . $table_name . '` (`' . implode('`, `', array_keys($columns)) . '`) values (' . implode('), (', $this->getData()) . ');');
59-
});
58+
$session->transaction(function($session) use ($table_name, $columns) {
59+
$session->query('upsert into `' . $table_name . '` (`' . implode('`, `', array_keys($columns)) . '`) values (' . implode('), (', $this->getData()) . ');');
60+
});
6061

61-
$output->writeln('Table ' . $table_name . ' has been populated with some data.');
62+
$output->writeln('Table ' . $table_name . ' has been populated with some data.');
63+
});
6264

6365
return Command::SUCCESS;
6466
}

examples/app/Commands/ListDirectoryCommand.php

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use YdbPlatform\Ydb\Ydb;
1112

1213
class ListDirectoryCommand extends Command
1314
{
@@ -46,29 +47,35 @@ protected function execute(InputInterface $input, OutputInterface $output)
4647

4748
$ydb = $this->appService->initYdb();
4849

49-
$scheme = $ydb->scheme();
50-
51-
$result = $scheme->listDirectory($dirname);
52-
53-
if (!empty($result))
54-
{
55-
$t = new Table($output);
56-
$t
57-
->setHeaders(['name', 'type', 'owner'])
58-
->setRows(array_map(function($row) {
59-
return [
60-
$row['name'] ?? null,
61-
$row['type'] ?? null,
62-
$row['owner'] ?? null,
63-
];
64-
}, $result))
65-
;
66-
$t->render();
67-
}
68-
else
69-
{
70-
$output->writeln('Empty directory');
71-
}
50+
$ydb->retry(function (Ydb $ydb) use ($output, $dirname) {
51+
52+
$scheme = $ydb->scheme();
53+
54+
$result = $scheme->listDirectory($dirname);
55+
56+
if (!empty($result))
57+
{
58+
$t = new Table($output);
59+
$t
60+
->setHeaders(['name', 'type', 'owner'])
61+
->setRows(array_map(function($row) {
62+
return [
63+
$row['name'] ?? null,
64+
$row['type'] ?? null,
65+
$row['owner'] ?? null,
66+
];
67+
}, $result))
68+
;
69+
$t->render();
70+
}
71+
else
72+
{
73+
$output->writeln('Empty directory');
74+
}
75+
76+
});
77+
78+
7279

7380
return Command::SUCCESS;
7481
}

examples/app/Commands/ListEndpointsCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
4040
{
4141
$ydb = $this->appService->initYdb();
4242

43-
$discovery = $ydb->discovery();
43+
$ydb->retry(function (Ydb $ydb) use ($output) {
4444

45-
$result = $discovery->listEndpoints();
45+
$discovery = $ydb->discovery();
4646

47-
$output->writeln(json_encode($result, 480));
47+
$result = $discovery->listEndpoints();
48+
49+
$output->writeln(json_encode($result, 480));
50+
51+
});
4852

4953
return Command::SUCCESS;
5054
}

examples/app/Commands/MakeDirectoryCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use YdbPlatform\Ydb\Ydb;
1011

1112
class MakeDirectoryCommand extends Command
1213
{
@@ -45,11 +46,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
4546

4647
$ydb = $this->appService->initYdb();
4748

48-
$scheme = $ydb->scheme();
49+
$ydb->retry(function (Ydb $ydb) use ($output, $dirname) {
50+
$scheme = $ydb->scheme();
4951

50-
$result = $scheme->makeDirectory($dirname);
52+
$result = $scheme->makeDirectory($dirname);
5153

52-
$output->writeln(json_encode($result, 480));
54+
$output->writeln(json_encode($result, 480));
55+
});
5356

5457
return Command::SUCCESS;
5558
}

examples/app/Commands/ReadTableCommand.php

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use YdbPlatform\Ydb\Ydb;
1112

1213
class ReadTableCommand extends Command
1314
{
@@ -47,68 +48,70 @@ protected function execute(InputInterface $input, OutputInterface $output)
4748

4849
$ydb = $this->appService->initYdb();
4950

50-
$table = $ydb->table();
51-
52-
$description = $table->describeTable($table_name);
53-
54-
$columns = [];
55-
56-
foreach ($description['columns'] ?? [] as $column)
57-
{
58-
$columns[] = $column['name'];
59-
}
60-
61-
if ( ! $columns)
62-
{
63-
throw new \Exception('Failed to get columns for table ' . $table_name);
64-
}
65-
66-
$options = [
67-
'row_limit' => 10,
68-
'ordered' => true,
69-
'key_range' => [
70-
'gte' => $table->tuple('uint64', 10),
71-
'lte' => $table->tuple('uint64', 30),
72-
73-
// other options:
74-
75-
// multi-column primary key:
76-
// 'lte' => $table->tuple('uint64,uin64', [30, 10]), // two-column primary key
77-
78-
// operators variant:
79-
// 'less' => $table->tuple('uint64', 30), // less than
80-
// 'lt' => $table->tuple('uint64', 30), // less than
81-
// '<' => $table->tuple('uint64', 30), // less than
82-
83-
// 'less_or_equal' => $table->tuple('uint64', 30), // less than or equal
84-
// 'lte' => $table->tuple('uint64', 30), // less than or equal
85-
// '<=' => $table->tuple('uint64', 30), // less than or equal
86-
87-
// 'greater' => $table->tuple('uint64', 30), // greater than
88-
// 'gt' => $table->tuple('uint64', 30), // greater than
89-
// '>' => $table->tuple('uint64', 30), // greater than
90-
91-
// 'greater_or_equal' => $table->tuple('uint64', 30), // greater than or equal
92-
// 'gte' => $table->tuple('uint64', 30), // greater than or equal
93-
// '>=' => $table->tuple('uint64', 30), // greater than or equal
94-
],
95-
];
96-
97-
foreach ($table->readTable($table_name, $columns, $options) as $i => $result)
98-
{
99-
$output->writeln('Portion #' . ($i + 1));
100-
$output->writeln('Column count: ' . $result->columnCount());
101-
$output->writeln('Row count: ' . $result->rowCount());
102-
103-
$t = new Table($output);
104-
$t
105-
->setHeaders(array_map(function($column) {
106-
return $column['name'];
107-
}, $result->columns()))
108-
->setRows($result->rows())
109-
;
110-
$t->render();
111-
}
51+
$ydb->retry(function (Ydb $ydb) use ($table_name, $output) {
52+
$table = $ydb->table();
53+
54+
$description = $table->describeTable($table_name);
55+
56+
$columns = [];
57+
58+
foreach ($description['columns'] ?? [] as $column)
59+
{
60+
$columns[] = $column['name'];
61+
}
62+
63+
if ( ! $columns)
64+
{
65+
throw new \Exception('Failed to get columns for table ' . $table_name);
66+
}
67+
68+
$options = [
69+
'row_limit' => 10,
70+
'ordered' => true,
71+
'key_range' => [
72+
'gte' => $table->tuple('uint64', 10),
73+
'lte' => $table->tuple('uint64', 30),
74+
75+
// other options:
76+
77+
// multi-column primary key:
78+
// 'lte' => $table->tuple('uint64,uin64', [30, 10]), // two-column primary key
79+
80+
// operators variant:
81+
// 'less' => $table->tuple('uint64', 30), // less than
82+
// 'lt' => $table->tuple('uint64', 30), // less than
83+
// '<' => $table->tuple('uint64', 30), // less than
84+
85+
// 'less_or_equal' => $table->tuple('uint64', 30), // less than or equal
86+
// 'lte' => $table->tuple('uint64', 30), // less than or equal
87+
// '<=' => $table->tuple('uint64', 30), // less than or equal
88+
89+
// 'greater' => $table->tuple('uint64', 30), // greater than
90+
// 'gt' => $table->tuple('uint64', 30), // greater than
91+
// '>' => $table->tuple('uint64', 30), // greater than
92+
93+
// 'greater_or_equal' => $table->tuple('uint64', 30), // greater than or equal
94+
// 'gte' => $table->tuple('uint64', 30), // greater than or equal
95+
// '>=' => $table->tuple('uint64', 30), // greater than or equal
96+
],
97+
];
98+
99+
foreach ($table->readTable($table_name, $columns, $options) as $i => $result)
100+
{
101+
$output->writeln('Portion #' . ($i + 1));
102+
$output->writeln('Column count: ' . $result->columnCount());
103+
$output->writeln('Row count: ' . $result->rowCount());
104+
105+
$t = new Table($output);
106+
$t
107+
->setHeaders(array_map(function($column) {
108+
return $column['name'];
109+
}, $result->columns()))
110+
->setRows($result->rows())
111+
;
112+
$t->render();
113+
}
114+
});
112115

113116
return Command::SUCCESS;
114117
}

examples/app/Commands/RemoveDirectoryCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputArgument;
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use YdbPlatform\Ydb\Ydb;
1011

1112
class RemoveDirectoryCommand extends Command
1213
{
@@ -45,11 +46,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
4546

4647
$ydb = $this->appService->initYdb();
4748

48-
$scheme = $ydb->scheme();
49+
$ydb->retry(function (Ydb $ydb) use ($output, $dirname) {
4950

50-
$result = $scheme->removeDirectory($dirname);
51+
$scheme = $ydb->scheme();
5152

52-
$output->writeln(json_encode($result, 480));
53+
$result = $scheme->removeDirectory($dirname);
54+
55+
$output->writeln(json_encode($result, 480));
56+
57+
});
5358

5459
return Command::SUCCESS;
5560
}

examples/app/Commands/Select1Command.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputInterface;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use YdbPlatform\Ydb\Ydb;
1112

1213
class Select1Command extends Command
1314
{
@@ -43,21 +44,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
4344
{
4445
$ydb = $this->appService->initYdb();
4546

46-
$table = $ydb->table();
47+
$ydb->retry(function (Ydb $ydb) use ($output) {
4748

48-
$result = $table->session()->query('select 1;');
49+
$table = $ydb->table();
4950

50-
$output->writeln('Column count: ' . $result->columnCount());
51-
$output->writeln('Row count: ' . $result->rowCount());
51+
$result = $table->session()->query('select 1;');
5252

53-
$t = new Table($output);
54-
$t
55-
->setHeaders(array_map(function($column) {
56-
return $column['name'];
57-
}, $result->columns()))
58-
->setRows($result->rows())
59-
;
60-
$t->render();
53+
$output->writeln('Column count: ' . $result->columnCount());
54+
$output->writeln('Row count: ' . $result->rowCount());
55+
56+
$t = new Table($output);
57+
$t
58+
->setHeaders(array_map(function($column) {
59+
return $column['name'];
60+
}, $result->columns()))
61+
->setRows($result->rows())
62+
;
63+
$t->render();
64+
65+
});
6166

6267
return Command::SUCCESS;
6368
}

0 commit comments

Comments
 (0)