Files
predis/tests/Predis/Command/Redis/CLIENT_Test.php
T
Vladyslav Vildanov 9318232e8d Merge main into 3.x (#1342)
* Changed command arguments (#1330)

* Re-implement CLIENT command as container command (#1337)

* Resolve merge conflicts

* Merge 2.x into main (#1341)

* Codestyle changes related to php-cs-fixer update (#1311)

* Codestyle changes

* Added missing type-hints

* Added GETDEL command to KeyPrefixProcessor (#1306)

* Added GETDEL command to KeyPrefixProcessor

* Added test coverage

* Codestyle fixes

* Added timeout after FT.CREATE call

* Added support for JSON.MERGE command (#1304)

* Added support for JSON.MSET command (#1307)

* Fixed subcommand test bug (#1313)

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fixed bug with incorrect multiple words processing (#1325)

* Fixed bug with incorrect multiple words processing

* Convert subcommand string to lower case

* Update SubcommandStrategyResolver.php

* Added test coverage

* Codestyle fixes

---------

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>

* Added support for FUNCTION DUMP, FUNCTION FLUSH, FUNCTION RESTORE commands (#1332)

* Added support for CLIENT NO-EVICT command (#1335)

* Added support for FUNCTION KILL, FUNCTION LIST, FUNCTION STATS commands (#1334)

* Added support for FUNCTION KILL, FUNCTION LIST, FUNCTION STATS commands

* Marked tests as relay-incompatible

* Added support for tests running against redis cluster (#1236)

* Added support for tests running against redis cluster

* Test coverage

* Added comment about master nodes

* Codestyle fix

* Revert changes

* Revert DBNUM

* Added cluster endpoints to relay tests env configuration

* Exclude cluster tests from relay tests environment

* Removed TODO comment

* Changed cluster image version to unstable

* Updated configuration to match unstable cluster

* Fixed path

* Updated cluster CI configuration

* Removed redundant flag

* Removed backslash

* Updated file path

* Updated file path variable

* Added docker cluster initialization as additional step

* Run cluster tests as separate workflow

* Codestyle fixes

* Updated exported files

* Added additional timeout so cluster image could be settled

* Added support for different cluster image, use docker compose for cluster tests CI

* Remove unused flag

* Removed variable from volume path

* Added sleep timeout to allow docker setup after running

* Added timeout before tests run

* Updated linter settings

* Include indent changes for.sh files

* Added missing coverage

* Revert expected files and mark docker folder as exclusion

* Specify folder itself as excluded

* Moved cluster tests as separate job in tests.yml

* Updated name to contain cluster word

---------

Co-authored-by: Chayim <chayim@users.noreply.github.com>

---------

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>

---------

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
2023-07-25 10:34:02 +03:00

356 lines
9.9 KiB
PHP

<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Redis;
/**
* @group commands
* @group realm-server
*/
class CLIENT_Test extends PredisCommandTestCase
{
/**
* {@inheritdoc}
*/
protected function getExpectedCommand(): string
{
return 'Predis\Command\Redis\CLIENT';
}
/**
* {@inheritdoc}
*/
protected function getExpectedId(): string
{
return 'CLIENT';
}
/**
* @group disconnected
*/
public function testFilterArgumentsOfClientKill(): void
{
$arguments = ['KILL', '127.0.0.1:45393'];
$expected = ['KILL', '127.0.0.1:45393'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @dataProvider listArgumentsProvider
* @group disconnected
*/
public function testFilterArgumentsOfClientList(array $actualArguments, array $expectedArguments): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedArguments, $command->getArguments());
}
/**
* @group disconnected
*/
public function testFilterArgumentsOfClientGetname(): void
{
$arguments = $expected = ['GETNAME'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @group disconnected
*/
public function testFilterArgumentsOfClientSetname(): void
{
$arguments = $expected = ['SETNAME', 'connection-a'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSame($expected, $command->getArguments());
}
/**
* @dataProvider noTouchArgumentsProvider
* @group disconnected
*/
public function testFilterArgumentsNoTouch(array $actualArguments, array $expectedArguments): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedArguments, $command->getArguments());
}
/**
* @dataProvider setInfoArgumentsProvider
* @group disconnected
*/
public function testFilterArgumentsSetInfo(array $actualArguments, array $expectedArguments): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedArguments, $command->getArguments());
}
/**
* @group disconnected
*/
public function testParseResponseOfClientKill(): void
{
$command = $this->getCommand();
$command->setArguments(['kill']);
$this->assertSame(true, $command->parseResponse(true));
}
/**
* @group disconnected
*/
public function testParseResponseOfClientList(): void
{
$command = $this->getCommand();
$command->setArguments(['list']);
$raw = <<<BUFFER
addr=127.0.0.1:45393 fd=6 idle=0 flags=N db=0 sub=0 psub=0
addr=127.0.0.1:45394 fd=7 idle=0 flags=N db=0 sub=0 psub=0
addr=127.0.0.1:45395 fd=8 idle=0 flags=N db=0 sub=0 psub=0
BUFFER;
$parsed = [
['addr' => '127.0.0.1:45393', 'fd' => '6', 'idle' => '0', 'flags' => 'N', 'db' => '0', 'sub' => '0', 'psub' => '0'],
['addr' => '127.0.0.1:45394', 'fd' => '7', 'idle' => '0', 'flags' => 'N', 'db' => '0', 'sub' => '0', 'psub' => '0'],
['addr' => '127.0.0.1:45395', 'fd' => '8', 'idle' => '0', 'flags' => 'N', 'db' => '0', 'sub' => '0', 'psub' => '0'],
];
$this->assertSame($parsed, $command->parseResponse($raw));
}
/**
* @group connected
* @requiresRedisVersion >= 2.4.0
*/
public function testReturnsListOfConnectedClients(): void
{
$redis = $this->getClient();
$this->assertIsArray($clients = $redis->client->list());
$this->assertGreaterThanOrEqual(1, count($clients));
$this->assertIsArray($clients[0]);
$this->assertArrayHasKey('addr', $clients[0]);
$this->assertArrayHasKey('fd', $clients[0]);
$this->assertArrayHasKey('idle', $clients[0]);
$this->assertArrayHasKey('flags', $clients[0]);
$this->assertArrayHasKey('db', $clients[0]);
$this->assertArrayHasKey('sub', $clients[0]);
$this->assertArrayHasKey('psub', $clients[0]);
}
/**
* @group connected
* @requiresRedisVersion >= 6.0.0
*/
public function testReturnsListOfConnectedClientsResp3(): void
{
$redis = $this->getResp3Client();
$this->assertIsArray($clients = $redis->client('LIST'));
$this->assertGreaterThanOrEqual(1, count($clients));
$this->assertIsArray($clients[0]);
$this->assertArrayHasKey('addr', $clients[0]);
$this->assertArrayHasKey('fd', $clients[0]);
$this->assertArrayHasKey('idle', $clients[0]);
$this->assertArrayHasKey('flags', $clients[0]);
$this->assertArrayHasKey('db', $clients[0]);
$this->assertArrayHasKey('sub', $clients[0]);
$this->assertArrayHasKey('psub', $clients[0]);
}
/**
* @group connected
* @group relay-incompatible
* @requiresRedisVersion >= 2.6.9
*/
public function testGetsNameOfConnection(): void
{
$redis = $this->getClient();
$clientName = $redis->client->getName();
$this->assertNull($clientName);
$expectedConnectionName = 'foo-bar';
$this->assertEquals('OK', $redis->client->setName($expectedConnectionName));
$this->assertEquals($expectedConnectionName, $redis->client->getName());
}
/**
* @group connected
* @requiresRedisVersion >= 6.0.0
*/
public function testGetsNameOfConnectionResp3(): void
{
$redis = $this->getResp3Client();
$clientName = $redis->client('GETNAME');
$this->assertSame('predis', $clientName);
$expectedConnectionName = 'foo-bar';
$this->assertEquals('OK', $redis->client('SETNAME', $expectedConnectionName));
$this->assertEquals($expectedConnectionName, $redis->client('GETNAME'));
}
/**
* @group connected
* @requiresRedisVersion >= 2.6.9
*/
public function testSetsNameOfConnection(): void
{
$redis = $this->getClient();
$expectedConnectionName = 'foo-baz';
$this->assertEquals('OK', $redis->client->setName($expectedConnectionName));
$this->assertEquals($expectedConnectionName, $redis->client->getName());
}
/**
* @group connected
* @requiresRedisVersion >= 7.2.0
*/
public function testNoTouchTurnOnControlOnKeys(): void
{
$redis = $this->getClient();
$this->assertEquals('OK', $redis->client->noTouch(true));
}
/**
* @group connected
* @requiresRedisVersion >= 7.2.0
*/
public function testSetInfoToCurrentClientConnection(): void
{
$redis = $this->getClient();
$this->assertEquals('OK', $redis->client->setInfo('LIB-NAME', 'lib'));
$this->assertEquals('OK', $redis->client->setInfo('LIB-VER', '1.0.0'));
$this->assertSame('lib', $redis->client->list()[0]['lib-name']);
$this->assertSame('1.0.0', $redis->client->list()[0]['lib-ver']);
}
/**
* @return array
*/
public function invalidConnectionNameProvider()
{
return [
['foo space'],
['foo \n'],
['foo $'],
];
}
/**
* @group connected
* @requiresRedisVersion >= 2.6.9
* @dataProvider invalidConnectionNameProvider
*
* @param string $invalidConnectionName
*/
public function testInvalidSetNameOfConnection($invalidConnectionName)
{
$this->expectException('Predis\Response\ServerException');
$redis = $this->getClient();
$redis->client->setName($invalidConnectionName);
}
/**
* @group connected
* @requiresRedisVersion >= 2.4.0
*/
public function testThrowsExceptionWhenKillingUnknownClient(): void
{
$this->expectException('Predis\Response\ServerException');
$this->expectExceptionMessage('ERR No such client');
$redis = $this->getClient();
$redis->client->kill('127.0.0.1:65535');
}
public function listArgumentsProvider(): array
{
return [
'with default arguments' => [
['LIST'],
['LIST'],
],
'with TYPE modifier' => [
['LIST', 'MASTER'],
['LIST', 'TYPE', 'MASTER'],
],
'with ID modifier' => [
['LIST', null, 1, 2, 3],
['LIST', 'ID', 1, 2, 3],
],
];
}
public function noTouchArgumentsProvider(): array
{
return [
'with default arguments' => [
['NOTOUCH'],
['NO-TOUCH'],
],
'with enabled modifier' => [
['NOTOUCH', true],
['NO-TOUCH', 'ON'],
],
'with disabled modifier' => [
['NOTOUCH', false],
['NO-TOUCH', 'OFF'],
],
];
}
public function setInfoArgumentsProvider(): array
{
return [
'with default arguments' => [
['SETINFO'],
['SETINFO'],
],
'with LIB-NAME modifier' => [
['SETINFO', 'LIB-NAME', 'lib'],
['SETINFO', 'LIB-NAME', 'lib'],
],
'with LIB-VER modifier' => [
['SETINFO', 'LIB-VER', '1.0.0'],
['SETINFO', 'LIB-VER', '1.0.0'],
],
'with only modifier given' => [
['SETINFO', 'LIB-VER'],
['SETINFO'],
],
];
}
}