Skip to content

Commit bcd94f1

Browse files
committed
Upgrade tarantool/client to v0.5.0
1 parent 90d5a02 commit bcd94f1

File tree

11 files changed

+99
-134
lines changed

11 files changed

+99
-134
lines changed

.php_cs.dist

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,18 @@ return Config::create()
8484
'FilterableFixer/native_function_invocation' => true,
8585
'no_useless_else' => true,
8686
'no_useless_return' => true,
87-
'ordered_imports' => true,
87+
'ordered_imports' => [
88+
'sort_algorithm' => 'alpha',
89+
'imports_order' => ['class', 'function', 'const'],
90+
],
8891
'phpdoc_order' => true,
8992
'phpdoc_align' => false,
9093
'return_type_declaration' => ['space_before' => 'one'],
9194
'strict_comparison' => true,
9295
'header_comment' => [
96+
'comment_type' => 'PHPDoc',
9397
'header' => $header,
94-
'location' => 'after_declare_strict',
98+
'location' => 'after_open',
9599
'separate' => 'both',
96100
],
97101
])

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ services:
66
- docker
77

88
env:
9-
- IMAGE='php:7.1-cli' TNT_CLIENT=pecl
10-
- IMAGE='php:7.1-cli' CHECK_CS=1
11-
- IMAGE='php:7.2-cli' PHPUNIT_OPTS='--coverage-clover=coverage.clover'
12-
- IMAGE='php:7.3-cli'
9+
- PHP_IMAGE='php:7.1-cli' TNT_CLIENT=pecl
10+
- PHP_IMAGE='php:7.1-cli' CHECK_CS=1
11+
- PHP_IMAGE='php:7.2-cli' PHPUNIT_OPTS='--coverage-clover=coverage.clover'
12+
- PHP_IMAGE='php:7.3-cli'
1313

1414
install:
1515
- ./dockerfile.sh | tee /dev/tty | docker build -t queue -
1616

1717
script:
1818
- docker network create tarantool-php
19-
- docker run -d --net=tarantool-php --name=tarantool -v `pwd`:/queue tarantool/tarantool:1 tarantool /queue/tests/Integration/queues.lua
19+
- docker run -d --net=tarantool-php --name=tarantool -v `pwd`:/queue tarantool/tarantool:2 tarantool /queue/tests/Integration/queues.lua
2020
- docker run --rm --net=tarantool-php -v `pwd`:/queue -w /queue -e PHPUNIT_OPTS="$PHPUNIT_OPTS" queue
2121

2222
after_script:

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,21 +294,22 @@ Then run Tarantool instance (needed for integration tests):
294294

295295
```bash
296296
docker network create tarantool-php
297-
docker run -d --net=tarantool-php --name=tarantool -v `pwd`:/queue \
298-
tarantool/tarantool:1 tarantool /queue/tests/Integration/queues.lua
297+
docker run -d --net=tarantool-php -p 3301:3301 --name=tarantool \
298+
-v $(pwd)/tests/Integration/queues.lua:/queues.lua \
299+
tarantool/tarantool:2 tarantool /queues.lua
299300
```
300301

301302
And then run both unit and integration tests:
302303

303304
```bash
304-
docker run --rm --net=tarantool-php --name=queue -v `pwd`:/queue -w /queue queue
305+
docker run --rm --net=tarantool-php -v `pwd`:/queue -w /queue queue
305306
```
306307

307308
To run only integration or unit tests, set the `PHPUNIT_OPTS` environment variable
308309
to either `--testsuite integration` or `--testsuite unit` respectively, e.g.:
309310

310311
```bash
311-
docker run --rm --net=tarantool-php --name=queue -v `pwd`:/queue -w /queue \
312+
docker run --rm --net=tarantool-php -v `pwd`:/queue -w /queue \
312313
-e PHPUNIT_OPTS='--testsuite unit' queue
313314
```
314315

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"php": "^7.1"
1515
},
1616
"require-dev": {
17-
"friendsofphp/php-cs-fixer": "^2.13",
17+
"friendsofphp/php-cs-fixer": "^2.14",
1818
"phpunit/phpunit": "^7.4",
19-
"rybakit/msgpack": "@dev",
20-
"tarantool/client": "@dev"
19+
"rybakit/msgpack": "^0.5.4",
20+
"tarantool/client": "^0.5.0"
2121
},
2222
"suggest": {
2323
"ext-tarantool": "For using pecl extension",

dockerfile.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

3-
if [[ -z "$IMAGE" ]] ; then
4-
IMAGE='php:7.2-cli'
3+
if [[ -z "$PHP_IMAGE" ]] ; then
4+
PHP_IMAGE='php:7.3-cli'
55
fi
66

77
if [[ -z "$TNT_CLIENT" ]] ; then
@@ -24,10 +24,10 @@ if [[ "1" != "$CHECK_CS" ]]; then
2424
fi
2525

2626
echo -e "
27-
FROM $IMAGE
27+
FROM $PHP_IMAGE
2828
2929
RUN apt-get update && \\
30-
apt-get install -y git curl libzip-dev && \\
30+
apt-get install -y curl git libzip-dev && \\
3131
docker-php-ext-configure zip --with-libzip && \\
3232
docker-php-ext-install zip${RUN_CMDS}
3333

src/ClientAdapter.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Queue.php

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ final class Queue
2828
*/
2929
public function __construct($client, string $name)
3030
{
31-
if ($client instanceof Client) {
32-
$client = new ClientAdapter($client);
33-
} elseif (!$client instanceof \Tarantool) {
31+
if ($client instanceof \Tarantool) {
32+
$client = new TarantoolAdapter($client);
33+
} elseif (!$client instanceof Client) {
3434
throw new \InvalidArgumentException(\sprintf(
35-
'%s() expects parameter 1 to be Tarantool or %s, %s given.',
35+
'%s() expects parameter 1 to be %s or Tarantool, %s given.',
3636
__METHOD__, Client::class, \is_object($client) ? \get_class($client) : \gettype($client)
3737
));
3838
}
@@ -48,68 +48,63 @@ public function getName() : string
4848

4949
public function put($data, array $options = []) : Task
5050
{
51-
$args = $options ? [$data, $options] : [$data];
52-
$result = $this->client->call("queue.tube.$this->name:put", $args);
53-
54-
return Task::createFromTuple($result[0]);
51+
return Task::createFromTuple(
52+
$this->client->call("queue.tube.$this->name:put", $data, $options)[0]
53+
);
5554
}
5655

5756
public function take(float $timeout = null) : ?Task
5857
{
59-
$args = null === $timeout ? [] : [$timeout];
60-
$result = $this->client->call("queue.tube.$this->name:take", $args);
58+
$result = $this->client->call("queue.tube.$this->name:take", $timeout);
6159

6260
return empty($result[0]) ? null : Task::createFromTuple($result[0]);
6361
}
6462

6563
public function touch(int $taskId, float $increment) : ?Task
6664
{
67-
$result = $this->client->call("queue.tube.$this->name:touch", [$taskId, $increment]);
65+
$result = $this->client->call("queue.tube.$this->name:touch", $taskId, $increment);
6866

6967
return empty($result[0]) ? null : Task::createFromTuple($result[0]);
7068
}
7169

7270
public function ack(int $taskId) : Task
7371
{
74-
$result = $this->client->call("queue.tube.$this->name:ack", [$taskId]);
75-
76-
return Task::createFromTuple($result[0]);
72+
return Task::createFromTuple(
73+
$this->client->call("queue.tube.$this->name:ack", $taskId)[0]
74+
);
7775
}
7876

7977
public function release(int $taskId, array $options = []) : Task
8078
{
81-
$args = $options ? [$taskId, $options] : [$taskId];
82-
$result = $this->client->call("queue.tube.$this->name:release", $args);
83-
84-
return Task::createFromTuple($result[0]);
79+
return Task::createFromTuple(
80+
$this->client->call("queue.tube.$this->name:release", $taskId, $options)[0]
81+
);
8582
}
8683

8784
public function peek(int $taskId) : Task
8885
{
89-
$result = $this->client->call("queue.tube.$this->name:peek", [$taskId]);
90-
91-
return Task::createFromTuple($result[0]);
86+
return Task::createFromTuple(
87+
$this->client->call("queue.tube.$this->name:peek", $taskId)[0]
88+
);
9289
}
9390

9491
public function bury(int $taskId) : Task
9592
{
96-
$result = $this->client->call("queue.tube.$this->name:bury", [$taskId]);
97-
98-
return Task::createFromTuple($result[0]);
93+
return Task::createFromTuple(
94+
$this->client->call("queue.tube.$this->name:bury", $taskId)[0]
95+
);
9996
}
10097

10198
public function kick(int $count) : int
10299
{
103-
$result = $this->client->call("queue.tube.$this->name:kick", [$count]);
104-
105-
return $result[0][0];
100+
return $this->client->call("queue.tube.$this->name:kick", $count)[0];
106101
}
107102

108103
public function delete(int $taskId) : Task
109104
{
110-
$result = $this->client->call("queue.tube.$this->name:delete", [$taskId]);
111-
112-
return Task::createFromTuple($result[0]);
105+
return Task::createFromTuple(
106+
$this->client->call("queue.tube.$this->name:delete", $taskId)[0]
107+
);
113108
}
114109

115110
public function truncate() : void
@@ -126,25 +121,24 @@ public function truncate() : void
126121
*/
127122
public function stats(string $path = null)
128123
{
129-
$result = $this->client->call('queue.stats', [$this->name]);
124+
[$stats] = $this->client->call('queue.stats', $this->name);
130125

131126
if (null === $path) {
132-
return $result[0][0];
127+
return $stats;
133128
}
134129

135-
$result = $result[0][0];
136130
foreach (\explode('.', $path) as $key) {
137-
if (!isset($result[$key])) {
131+
if (!isset($stats[$key])) {
138132
throw new \InvalidArgumentException(\sprintf('Invalid path "%s".', $path));
139133
}
140-
$result = $result[$key];
134+
$stats = $stats[$key];
141135
}
142136

143-
return $result;
137+
return $stats;
144138
}
145139

146140
public function call(string $methodName, ...$args) : array
147141
{
148-
return $this->client->call("queue.tube.$this->name:$methodName", $args);
142+
return $this->client->call("queue.tube.$this->name:$methodName", ...$args);
149143
}
150144
}

src/TarantoolAdapter.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Tarantool Queue package.
7+
*
8+
* (c) Eugene Leonovich <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Tarantool\Queue;
15+
16+
final class TarantoolAdapter
17+
{
18+
private $tarantool;
19+
20+
public function __construct(\Tarantool $tarantool)
21+
{
22+
$this->tarantool = $tarantool;
23+
}
24+
25+
public function call(string $funcName, ...$args) : array
26+
{
27+
return $this->tarantool->call($funcName, $args);
28+
}
29+
}

tests/Integration/QueueTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
use PHPUnit\Framework\TestCase;
1717
use Tarantool\Client\Client;
18-
use Tarantool\Client\Connection\StreamConnection;
19-
use Tarantool\Client\Packer\PurePacker;
2018
use Tarantool\Queue\Queue;
2119
use Tarantool\Queue\States;
2220
use Tarantool\Queue\Task;
@@ -35,19 +33,12 @@ abstract class QueueTest extends TestCase
3533

3634
public static function setUpBeforeClass() : void
3735
{
38-
if (class_exists(\Tarantool::class, false)) {
39-
self::$client = new \Tarantool(
40-
getenv('TARANTOOL_HOST'),
41-
(int) getenv('TARANTOOL_PORT')
42-
);
36+
$host = getenv('TARANTOOL_HOST');
37+
$port = (int) getenv('TARANTOOL_PORT');
4338

44-
return;
45-
}
46-
47-
$uri = sprintf('tcp://%s:%d', getenv('TARANTOOL_HOST'), getenv('TARANTOOL_PORT'));
48-
$conn = new StreamConnection($uri);
49-
50-
self::$client = new Client($conn, new PurePacker());
39+
self::$client = extension_loaded('tarantool')
40+
? new \Tarantool($host, $port)
41+
: Client::fromDsn(sprintf('tcp://%s:%d', $host, $port));
5142
}
5243

5344
public static function tearDownAfterClass() : void
@@ -63,12 +54,12 @@ protected function setUp() : void
6354
$tubeType = $this->getTubeType();
6455
$queueName = sprintf('t_%s_%s', $tubeType, $testName);
6556

66-
self::$client->evaluate('create_tube(...)', [$queueName, $tubeType]);
57+
$this->evaluate('create_tube(...)', $queueName, $tubeType);
6758

6859
$ann = $this->getAnnotations();
6960
if (!empty($ann['method']['eval'])) {
7061
foreach ($ann['method']['eval'] as $eval) {
71-
self::$client->evaluate(str_replace('%tube_name%', $queueName, $eval));
62+
$this->evaluate(str_replace('%tube_name%', $queueName, $eval));
7263
}
7364
}
7465

@@ -396,7 +387,7 @@ public function testCall() : void
396387
{
397388
$result = $this->queue->call('pow', 2, 8);
398389

399-
self::assertSame(256, $result[0][0]);
390+
self::assertSame(256, $result[0]);
400391
}
401392

402393
/**
@@ -453,4 +444,11 @@ protected function getTubeType() : string
453444

454445
return strtolower($type);
455446
}
447+
448+
final protected function evaluate(string $expr, ...$args) : array
449+
{
450+
return self::$client instanceof Client
451+
? self::$client->evaluate($expr, ...$args)
452+
: self::$client->evaluate($expr, $args);
453+
}
456454
}

tests/Integration/queues.lua

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ box.cfg {
88
slab_alloc_arena = .1,
99
}
1010

11-
-- local function bootstrap()
12-
-- box.schema.user.grant('guest', 'read,write,execute', 'universe')
13-
-- end
14-
15-
-- box.once('queues', bootstrap)
16-
17-
console = require('console')
18-
console.listen('127.0.0.1:33333')
11+
box.schema.user.grant('guest', 'read,write,execute,create,drop,alter', 'universe', nil, {if_not_exists = true})
1912

2013
queue = require('queue')
2114

0 commit comments

Comments
 (0)